Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

cxl: Use of_property_ accessor functions

The CXL driver has its own custom implementations of typed DT property
accessors. Replace the custom property accessor functions with the
common DT property functions.

This clean-up is part of a larger effort to remove of_get_property() and
other DT functions which leak pointers to DT node and property data.

Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
Link: https://lore.kernel.org/r/20240729-dt-cxl-cleanup-v1-2-a75eea80d231@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Rob Herring (Arm) and committed by
Greg Kroah-Hartman
5c4efc60 35fc2654

+33 -105
+20 -86
drivers/misc/cxl/of.c
··· 7 7 #include <linux/module.h> 8 8 #include <linux/platform_device.h> 9 9 #include <linux/slab.h> 10 + #include <linux/of.h> 10 11 #include <linux/of_address.h> 11 12 #include <linux/of_platform.h> 12 13 13 14 #include "cxl.h" 14 - 15 - 16 - static const __be32 *read_prop_string(const struct device_node *np, 17 - const char *prop_name) 18 - { 19 - const __be32 *prop; 20 - 21 - prop = of_get_property(np, prop_name, NULL); 22 - return prop; 23 - } 24 - 25 - static const __be32 *read_prop_dword(const struct device_node *np, 26 - const char *prop_name, u32 *val) 27 - { 28 - const __be32 *prop; 29 - 30 - prop = of_get_property(np, prop_name, NULL); 31 - if (prop) 32 - *val = be32_to_cpu(prop[0]); 33 - return prop; 34 - } 35 - 36 - static const __be64 *read_prop64_dword(const struct device_node *np, 37 - const char *prop_name, u64 *val) 38 - { 39 - const __be64 *prop; 40 - 41 - prop = of_get_property(np, prop_name, NULL); 42 - if (prop) 43 - *val = be64_to_cpu(prop[0]); 44 - return prop; 45 - } 46 - 47 - 48 - static int read_handle(struct device_node *np, u64 *handle) 49 - { 50 - const __be32 *prop; 51 - u64 size; 52 - 53 - /* Get address and size of the node */ 54 - prop = of_get_address(np, 0, &size, NULL); 55 - if (size) 56 - return -EINVAL; 57 - 58 - /* Helper to read a big number; size is in cells (not bytes) */ 59 - *handle = of_read_number(prop, of_n_addr_cells(np)); 60 - return 0; 61 - } 62 15 63 16 static int read_phys_addr(struct device_node *np, char *prop_name, 64 17 struct cxl_afu *afu) ··· 74 121 75 122 int cxl_of_read_afu_handle(struct cxl_afu *afu, struct device_node *afu_np) 76 123 { 77 - if (read_handle(afu_np, &afu->guest->handle)) 78 - return -EINVAL; 79 - pr_devel("AFU handle: 0x%.16llx\n", afu->guest->handle); 80 - 81 - return 0; 124 + return of_property_read_reg(afu_np, 0, &afu->guest->handle, NULL); 82 125 } 83 126 84 127 int cxl_of_read_afu_properties(struct cxl_afu *afu, struct device_node *np) 85 128 { 86 129 int i, rc; 87 - const __be32 *prop; 88 130 u16 device_id, vendor_id; 89 131 u32 val = 0, class_code; 90 132 ··· 98 150 else 99 151 afu->psa = true; 100 152 101 - read_prop_dword(np, "ibm,#processes", &afu->max_procs_virtualised); 153 + of_property_read_u32(np, "ibm,#processes", &afu->max_procs_virtualised); 102 154 103 155 if (cxl_verbose) 104 156 read_vpd(NULL, afu); 105 157 106 - read_prop_dword(np, "ibm,max-ints-per-process", &afu->guest->max_ints); 158 + of_property_read_u32(np, "ibm,max-ints-per-process", &afu->guest->max_ints); 107 159 afu->irqs_max = afu->guest->max_ints; 108 160 109 - prop = read_prop_dword(np, "ibm,min-ints-per-process", &afu->pp_irqs); 110 - if (prop) { 161 + if (!of_property_read_u32(np, "ibm,min-ints-per-process", &afu->pp_irqs)) { 111 162 /* One extra interrupt for the PSL interrupt is already 112 163 * included. Remove it now to keep only AFU interrupts and 113 164 * match the native case. ··· 114 167 afu->pp_irqs--; 115 168 } 116 169 117 - read_prop64_dword(np, "ibm,error-buffer-size", &afu->eb_len); 170 + of_property_read_u64(np, "ibm,error-buffer-size", &afu->eb_len); 118 171 afu->eb_offset = 0; 119 172 120 - read_prop64_dword(np, "ibm,config-record-size", &afu->crs_len); 173 + of_property_read_u64(np, "ibm,config-record-size", &afu->crs_len); 121 174 afu->crs_offset = 0; 122 175 123 - read_prop_dword(np, "ibm,#config-records", &afu->crs_num); 176 + of_property_read_u32(np, "ibm,#config-records", &afu->crs_num); 124 177 125 178 if (cxl_verbose) { 126 179 for (i = 0; i < afu->crs_num; i++) { ··· 148 201 * not supported 149 202 */ 150 203 val = 0; 151 - prop = read_prop_dword(np, "ibm,process-mmio", &val); 152 - if (prop && val == 1) 204 + if (!of_property_read_u32(np, "ibm,process-mmio", &val) && val == 1) 153 205 afu->pp_psa = true; 154 206 else 155 207 afu->pp_psa = false; 156 208 157 - prop = read_prop_dword(np, "ibm,function-error-interrupt", &val); 158 - if (prop) 209 + if (!of_property_read_u32(np, "ibm,function-error-interrupt", &val)) 159 210 afu->serr_hwirq = val; 160 211 161 212 pr_devel("AFU handle: %#llx\n", afu->guest->handle); ··· 224 279 225 280 int cxl_of_read_adapter_handle(struct cxl *adapter, struct device_node *np) 226 281 { 227 - if (read_handle(np, &adapter->guest->handle)) 228 - return -EINVAL; 229 - pr_devel("Adapter handle: 0x%.16llx\n", adapter->guest->handle); 230 - 231 - return 0; 282 + return of_property_read_reg(np, 0, &adapter->guest->handle, NULL); 232 283 } 233 284 234 285 int cxl_of_read_adapter_properties(struct cxl *adapter, struct device_node *np) 235 286 { 236 287 int rc; 237 - const __be32 *prop; 288 + const char *p; 238 289 u32 val = 0; 239 290 240 291 /* Properties are read in the same order as listed in PAPR */ ··· 238 297 if ((rc = read_adapter_irq_config(adapter, np))) 239 298 return rc; 240 299 241 - prop = read_prop_dword(np, "ibm,caia-version", &val); 242 - if (prop) { 300 + if (!of_property_read_u32(np, "ibm,caia-version", &val)) { 243 301 adapter->caia_major = (val & 0xFF00) >> 8; 244 302 adapter->caia_minor = val & 0xFF; 245 303 } 246 304 247 - prop = read_prop_dword(np, "ibm,psl-revision", &val); 248 - if (prop) 305 + if (!of_property_read_u32(np, "ibm,psl-revision", &val)) 249 306 adapter->psl_rev = val; 250 307 251 - prop = read_prop_string(np, "status"); 252 - if (prop) { 253 - adapter->guest->status = kasprintf(GFP_KERNEL, "%s", (char *) prop); 308 + if (!of_property_read_string(np, "status", &p)) { 309 + adapter->guest->status = kasprintf(GFP_KERNEL, "%s", p); 254 310 if (adapter->guest->status == NULL) 255 311 return -ENOMEM; 256 312 } 257 313 258 - prop = read_prop_dword(np, "vendor-id", &val); 259 - if (prop) 314 + if (!of_property_read_u32(np, "vendor-id", &val)) 260 315 adapter->guest->vendor = val; 261 316 262 - prop = read_prop_dword(np, "device-id", &val); 263 - if (prop) 317 + if (!of_property_read_u32(np, "device-id", &val)) 264 318 adapter->guest->device = val; 265 319 266 - prop = read_prop_dword(np, "subsystem-vendor-id", &val); 267 - if (prop) 320 + if (!of_property_read_u32(np, "subsystem-vendor-id", &val)) 268 321 adapter->guest->subsystem_vendor = val; 269 322 270 - prop = read_prop_dword(np, "subsystem-id", &val); 271 - if (prop) 323 + if (!of_property_read_u32(np, "subsystem-id", &val)) 272 324 adapter->guest->subsystem = val; 273 325 274 326 if (cxl_verbose)
+13 -19
drivers/misc/cxl/pci.c
··· 363 363 { 364 364 int rc; 365 365 struct device_node *np; 366 - const __be32 *prop; 366 + u32 id; 367 367 368 368 if (!(np = pnv_pci_get_phb_node(dev))) 369 369 return -ENODEV; 370 370 371 - while (np && !(prop = of_get_property(np, "ibm,chip-id", NULL))) 371 + while (np && of_property_read_u32(np, "ibm,chip-id", &id)) 372 372 np = of_get_next_parent(np); 373 373 if (!np) 374 374 return -ENODEV; 375 375 376 - *chipid = be32_to_cpup(prop); 376 + *chipid = id; 377 377 378 378 rc = get_phb_index(np, phb_index); 379 379 if (rc) { ··· 398 398 static int get_phb_indications(struct pci_dev *dev, u64 *capiind, u64 *asnind, 399 399 u64 *nbwind) 400 400 { 401 - static u64 nbw, asn, capi = 0; 401 + static u32 val[3]; 402 402 struct device_node *np; 403 - const __be32 *prop; 404 403 405 404 mutex_lock(&indications_mutex); 406 - if (!capi) { 405 + if (!val[0]) { 407 406 if (!(np = pnv_pci_get_phb_node(dev))) { 408 407 mutex_unlock(&indications_mutex); 409 408 return -ENODEV; 410 409 } 411 410 412 - prop = of_get_property(np, "ibm,phb-indications", NULL); 413 - if (!prop) { 414 - nbw = 0x0300UL; /* legacy values */ 415 - asn = 0x0400UL; 416 - capi = 0x0200UL; 417 - } else { 418 - nbw = (u64)be32_to_cpu(prop[2]); 419 - asn = (u64)be32_to_cpu(prop[1]); 420 - capi = (u64)be32_to_cpu(prop[0]); 411 + if (of_property_read_u32_array(np, "ibm,phb-indications", val, 3)) { 412 + val[2] = 0x0300UL; /* legacy values */ 413 + val[1] = 0x0400UL; 414 + val[0] = 0x0200UL; 421 415 } 422 416 of_node_put(np); 423 417 } 424 - *capiind = capi; 425 - *asnind = asn; 426 - *nbwind = nbw; 418 + *capiind = val[0]; 419 + *asnind = val[1]; 420 + *nbwind = val[2]; 427 421 mutex_unlock(&indications_mutex); 428 422 return 0; 429 423 } ··· 599 605 600 606 /* Do not fail when CAPP timebase sync is not supported by OPAL */ 601 607 of_node_get(np); 602 - if (! of_get_property(np, "ibm,capp-timebase-sync", NULL)) { 608 + if (!of_property_present(np, "ibm,capp-timebase-sync")) { 603 609 of_node_put(np); 604 610 dev_info(&dev->dev, "PSL timebase inactive: OPAL support missing\n"); 605 611 return;