Skip to content

Commit 5c4efc6

Browse files
robherringgregkh
authored andcommitted
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) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 35fc265 commit 5c4efc6

File tree

2 files changed

+33
-105
lines changed

2 files changed

+33
-105
lines changed

drivers/misc/cxl/of.c

Lines changed: 20 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,12 @@
77
#include <linux/module.h>
88
#include <linux/platform_device.h>
99
#include <linux/slab.h>
10+
#include <linux/of.h>
1011
#include <linux/of_address.h>
1112
#include <linux/of_platform.h>
1213

1314
#include "cxl.h"
1415

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-
6316
static int read_phys_addr(struct device_node *np, char *prop_name,
6417
struct cxl_afu *afu)
6518
{
@@ -121,17 +74,12 @@ static int read_vpd(struct cxl *adapter, struct cxl_afu *afu)
12174

12275
int cxl_of_read_afu_handle(struct cxl_afu *afu, struct device_node *afu_np)
12376
{
124-
if (read_handle(afu_np, &afu->guest->handle))
125-
return -EINVAL;
126-
pr_devel("AFU handle: 0x%.16llx\n", afu->guest->handle);
127-
128-
return 0;
77+
return of_property_read_reg(afu_np, 0, &afu->guest->handle, NULL);
12978
}
13079

13180
int cxl_of_read_afu_properties(struct cxl_afu *afu, struct device_node *np)
13281
{
13382
int i, rc;
134-
const __be32 *prop;
13583
u16 device_id, vendor_id;
13684
u32 val = 0, class_code;
13785

@@ -150,30 +98,29 @@ int cxl_of_read_afu_properties(struct cxl_afu *afu, struct device_node *np)
15098
else
15199
afu->psa = true;
152100

153-
read_prop_dword(np, "ibm,#processes", &afu->max_procs_virtualised);
101+
of_property_read_u32(np, "ibm,#processes", &afu->max_procs_virtualised);
154102

155103
if (cxl_verbose)
156104
read_vpd(NULL, afu);
157105

158-
read_prop_dword(np, "ibm,max-ints-per-process", &afu->guest->max_ints);
106+
of_property_read_u32(np, "ibm,max-ints-per-process", &afu->guest->max_ints);
159107
afu->irqs_max = afu->guest->max_ints;
160108

161-
prop = read_prop_dword(np, "ibm,min-ints-per-process", &afu->pp_irqs);
162-
if (prop) {
109+
if (!of_property_read_u32(np, "ibm,min-ints-per-process", &afu->pp_irqs)) {
163110
/* One extra interrupt for the PSL interrupt is already
164111
* included. Remove it now to keep only AFU interrupts and
165112
* match the native case.
166113
*/
167114
afu->pp_irqs--;
168115
}
169116

170-
read_prop64_dword(np, "ibm,error-buffer-size", &afu->eb_len);
117+
of_property_read_u64(np, "ibm,error-buffer-size", &afu->eb_len);
171118
afu->eb_offset = 0;
172119

173-
read_prop64_dword(np, "ibm,config-record-size", &afu->crs_len);
120+
of_property_read_u64(np, "ibm,config-record-size", &afu->crs_len);
174121
afu->crs_offset = 0;
175122

176-
read_prop_dword(np, "ibm,#config-records", &afu->crs_num);
123+
of_property_read_u32(np, "ibm,#config-records", &afu->crs_num);
177124

178125
if (cxl_verbose) {
179126
for (i = 0; i < afu->crs_num; i++) {
@@ -201,14 +148,12 @@ int cxl_of_read_afu_properties(struct cxl_afu *afu, struct device_node *np)
201148
* not supported
202149
*/
203150
val = 0;
204-
prop = read_prop_dword(np, "ibm,process-mmio", &val);
205-
if (prop && val == 1)
151+
if (!of_property_read_u32(np, "ibm,process-mmio", &val) && val == 1)
206152
afu->pp_psa = true;
207153
else
208154
afu->pp_psa = false;
209155

210-
prop = read_prop_dword(np, "ibm,function-error-interrupt", &val);
211-
if (prop)
156+
if (!of_property_read_u32(np, "ibm,function-error-interrupt", &val))
212157
afu->serr_hwirq = val;
213158

214159
pr_devel("AFU handle: %#llx\n", afu->guest->handle);
@@ -279,55 +224,44 @@ static int read_adapter_irq_config(struct cxl *adapter, struct device_node *np)
279224

280225
int cxl_of_read_adapter_handle(struct cxl *adapter, struct device_node *np)
281226
{
282-
if (read_handle(np, &adapter->guest->handle))
283-
return -EINVAL;
284-
pr_devel("Adapter handle: 0x%.16llx\n", adapter->guest->handle);
285-
286-
return 0;
227+
return of_property_read_reg(np, 0, &adapter->guest->handle, NULL);
287228
}
288229

289230
int cxl_of_read_adapter_properties(struct cxl *adapter, struct device_node *np)
290231
{
291232
int rc;
292-
const __be32 *prop;
233+
const char *p;
293234
u32 val = 0;
294235

295236
/* Properties are read in the same order as listed in PAPR */
296237

297238
if ((rc = read_adapter_irq_config(adapter, np)))
298239
return rc;
299240

300-
prop = read_prop_dword(np, "ibm,caia-version", &val);
301-
if (prop) {
241+
if (!of_property_read_u32(np, "ibm,caia-version", &val)) {
302242
adapter->caia_major = (val & 0xFF00) >> 8;
303243
adapter->caia_minor = val & 0xFF;
304244
}
305245

306-
prop = read_prop_dword(np, "ibm,psl-revision", &val);
307-
if (prop)
246+
if (!of_property_read_u32(np, "ibm,psl-revision", &val))
308247
adapter->psl_rev = val;
309248

310-
prop = read_prop_string(np, "status");
311-
if (prop) {
312-
adapter->guest->status = kasprintf(GFP_KERNEL, "%s", (char *) prop);
249+
if (!of_property_read_string(np, "status", &p)) {
250+
adapter->guest->status = kasprintf(GFP_KERNEL, "%s", p);
313251
if (adapter->guest->status == NULL)
314252
return -ENOMEM;
315253
}
316254

317-
prop = read_prop_dword(np, "vendor-id", &val);
318-
if (prop)
255+
if (!of_property_read_u32(np, "vendor-id", &val))
319256
adapter->guest->vendor = val;
320257

321-
prop = read_prop_dword(np, "device-id", &val);
322-
if (prop)
258+
if (!of_property_read_u32(np, "device-id", &val))
323259
adapter->guest->device = val;
324260

325-
prop = read_prop_dword(np, "subsystem-vendor-id", &val);
326-
if (prop)
261+
if (!of_property_read_u32(np, "subsystem-vendor-id", &val))
327262
adapter->guest->subsystem_vendor = val;
328263

329-
prop = read_prop_dword(np, "subsystem-id", &val);
330-
if (prop)
264+
if (!of_property_read_u32(np, "subsystem-id", &val))
331265
adapter->guest->subsystem = val;
332266

333267
if (cxl_verbose)

drivers/misc/cxl/pci.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -363,17 +363,17 @@ int cxl_calc_capp_routing(struct pci_dev *dev, u64 *chipid,
363363
{
364364
int rc;
365365
struct device_node *np;
366-
const __be32 *prop;
366+
u32 id;
367367

368368
if (!(np = pnv_pci_get_phb_node(dev)))
369369
return -ENODEV;
370370

371-
while (np && !(prop = of_get_property(np, "ibm,chip-id", NULL)))
371+
while (np && of_property_read_u32(np, "ibm,chip-id", &id))
372372
np = of_get_next_parent(np);
373373
if (!np)
374374
return -ENODEV;
375375

376-
*chipid = be32_to_cpup(prop);
376+
*chipid = id;
377377

378378
rc = get_phb_index(np, phb_index);
379379
if (rc) {
@@ -398,32 +398,26 @@ static DEFINE_MUTEX(indications_mutex);
398398
static int get_phb_indications(struct pci_dev *dev, u64 *capiind, u64 *asnind,
399399
u64 *nbwind)
400400
{
401-
static u64 nbw, asn, capi = 0;
401+
static u32 val[3];
402402
struct device_node *np;
403-
const __be32 *prop;
404403

405404
mutex_lock(&indications_mutex);
406-
if (!capi) {
405+
if (!val[0]) {
407406
if (!(np = pnv_pci_get_phb_node(dev))) {
408407
mutex_unlock(&indications_mutex);
409408
return -ENODEV;
410409
}
411410

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;
421415
}
422416
of_node_put(np);
423417
}
424-
*capiind = capi;
425-
*asnind = asn;
426-
*nbwind = nbw;
418+
*capiind = val[0];
419+
*asnind = val[1];
420+
*nbwind = val[2];
427421
mutex_unlock(&indications_mutex);
428422
return 0;
429423
}
@@ -605,7 +599,7 @@ static void cxl_setup_psl_timebase(struct cxl *adapter, struct pci_dev *dev)
605599

606600
/* Do not fail when CAPP timebase sync is not supported by OPAL */
607601
of_node_get(np);
608-
if (! of_get_property(np, "ibm,capp-timebase-sync", NULL)) {
602+
if (!of_property_present(np, "ibm,capp-timebase-sync")) {
609603
of_node_put(np);
610604
dev_info(&dev->dev, "PSL timebase inactive: OPAL support missing\n");
611605
return;

0 commit comments

Comments
 (0)