Message ID | 20220906010313.1296714-1-mpe@ellerman.id.au (mailing list archive) |
---|---|
State | Accepted |
Headers | show |
Series | powerpc/pasemi: Use of_root in pas_pci_init() | expand |
Context | Check | Description |
---|---|---|
snowpatch_ozlabs/github-powerpc_selftests | success | Successfully ran 10 jobs. |
snowpatch_ozlabs/github-powerpc_ppctests | success | Successfully ran 10 jobs. |
snowpatch_ozlabs/github-powerpc_clang | success | Successfully ran 6 jobs. |
snowpatch_ozlabs/github-powerpc_kernel_qemu | success | Successfully ran 23 jobs. |
snowpatch_ozlabs/github-powerpc_sparse | success | Successfully ran 4 jobs. |
Le 06/09/2022 à 03:03, Michael Ellerman a écrit : > Currently in pas_pci_init() a reference to the root node is leaked due > to a missing of_node_put(). Instead just use of_root directly. > > Note that converting to of_find_compatible_node(NULL, ...) would > not be entirely equivalent, because that would check the compatible > property of the root node, whereas using of_root skips checking the root > node and start the search at the first child of the root. > That seems to simplify code. Should we do the same in all places below ? $ git grep -n "of_find_node_by_path(\"/\");" arch/powerpc/ arch/powerpc/kernel/pci_32.c:139: dn = of_find_node_by_path("/"); arch/powerpc/kernel/pci_32.c:214: dn = of_find_node_by_path("/"); arch/powerpc/kernel/setup-common.c:212: root = of_find_node_by_path("/"); arch/powerpc/kernel/setup-common.c:793: np = of_find_node_by_path("/"); arch/powerpc/mm/numa.c:388: root = of_find_node_by_path("/"); arch/powerpc/mm/numa.c:456: root = of_find_node_by_path("/"); arch/powerpc/platforms/52xx/efika.c:77: root = of_find_node_by_path("/"); arch/powerpc/platforms/52xx/efika.c:148: root = of_find_node_by_path("/"); arch/powerpc/platforms/85xx/xes_mpc85xx.c:119: root = of_find_node_by_path("/"); arch/powerpc/platforms/cell/setup.c:67: root = of_find_node_by_path("/"); arch/powerpc/platforms/cell/setup.c:154: struct device_node *root = of_find_node_by_path("/"); arch/powerpc/platforms/chrp/pci.c:191: struct device_node *root = of_find_node_by_path("/"); arch/powerpc/platforms/chrp/pci.c:216: struct device_node *root = of_find_node_by_path("/"); arch/powerpc/platforms/chrp/setup.c:105: root = of_find_node_by_path("/"); arch/powerpc/platforms/chrp/setup.c:201: root = of_find_node_by_path("/"); arch/powerpc/platforms/chrp/setup.c:268: node = of_find_node_by_path("/"); arch/powerpc/platforms/chrp/setup.c:299: struct device_node *root = of_find_node_by_path("/"); arch/powerpc/platforms/chrp/setup.c:378: root = of_find_node_by_path("/"); arch/powerpc/platforms/maple/pci.c:601: root = of_find_node_by_path("/"); arch/powerpc/platforms/maple/setup.c:225: root = of_find_node_by_path("/"); arch/powerpc/platforms/pasemi/pci.c:276: root = of_find_node_by_path("/"); arch/powerpc/platforms/pasemi/setup.c:268: root = of_find_node_by_path("/"); arch/powerpc/platforms/powermac/pci.c:910: root = of_find_node_by_path("/"); arch/powerpc/platforms/powermac/setup.c:105: np = of_find_node_by_path("/"); arch/powerpc/platforms/powernv/setup.c:255: root = of_find_node_by_path("/"); arch/powerpc/platforms/ps3/os-area.c:676: node = of_find_node_by_path("/"); arch/powerpc/platforms/ps3/os-area.c:774: node = of_find_node_by_path("/"); arch/powerpc/platforms/pseries/hotplug-memory.c:166: parent = of_find_node_by_path("/"); arch/powerpc/platforms/pseries/ibmebus.c:187: root = of_find_node_by_path("/"); arch/powerpc/platforms/pseries/lparcfg.c:232: root = of_find_node_by_path("/"); arch/powerpc/platforms/pseries/lparcfg.c:799: rootdn = of_find_node_by_path("/"); arch/powerpc/platforms/pseries/setup.c:97: root = of_find_node_by_path("/"); arch/powerpc/platforms/pseries/setup.c:486: struct device_node *root = of_find_node_by_path("/"); arch/powerpc/sysdev/xive/spapr.c:714: rootdn = of_find_node_by_path("/"); Christophe > Reported-by: Liang He <windhl@126.com> > Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> > --- > arch/powerpc/platforms/pasemi/pci.c | 10 ++-------- > 1 file changed, 2 insertions(+), 8 deletions(-) > > diff --git a/arch/powerpc/platforms/pasemi/pci.c b/arch/powerpc/platforms/pasemi/pci.c > index 55f0160910bf..f27d31414737 100644 > --- a/arch/powerpc/platforms/pasemi/pci.c > +++ b/arch/powerpc/platforms/pasemi/pci.c > @@ -270,18 +270,12 @@ static int __init pas_add_bridge(struct device_node *dev) > > void __init pas_pci_init(void) > { > - struct device_node *np, *root; > + struct device_node *np; > int res; > > - root = of_find_node_by_path("/"); > - if (!root) { > - pr_crit("pas_pci_init: can't find root of device tree\n"); > - return; > - } > - > pci_set_flags(PCI_SCAN_ALL_PCIE_DEVS); > > - np = of_find_compatible_node(root, NULL, "pasemi,rootbus"); > + np = of_find_compatible_node(of_root, NULL, "pasemi,rootbus"); > if (np) { > res = pas_add_bridge(np); > of_node_put(np);
Christophe Leroy <christophe.leroy@csgroup.eu> writes: > Le 06/09/2022 à 03:03, Michael Ellerman a écrit : >> Currently in pas_pci_init() a reference to the root node is leaked due >> to a missing of_node_put(). Instead just use of_root directly. >> >> Note that converting to of_find_compatible_node(NULL, ...) would >> not be entirely equivalent, because that would check the compatible >> property of the root node, whereas using of_root skips checking the root >> node and start the search at the first child of the root. >> > > That seems to simplify code. Should we do the same in all places below ? I guess so. There are some places where using of_root complicates things, because it *doesn't* need refcount handling, eg. the cases in numa.c. But in most cases it is preferable to use of_root IMHO. cheers > $ git grep -n "of_find_node_by_path(\"/\");" arch/powerpc/ > arch/powerpc/kernel/pci_32.c:139: dn = of_find_node_by_path("/"); > arch/powerpc/kernel/pci_32.c:214: dn = of_find_node_by_path("/"); > arch/powerpc/kernel/setup-common.c:212: root = of_find_node_by_path("/"); > arch/powerpc/kernel/setup-common.c:793: np = of_find_node_by_path("/"); > arch/powerpc/mm/numa.c:388: root = of_find_node_by_path("/"); > arch/powerpc/mm/numa.c:456: root = of_find_node_by_path("/"); > arch/powerpc/platforms/52xx/efika.c:77: root = of_find_node_by_path("/"); > arch/powerpc/platforms/52xx/efika.c:148: root = of_find_node_by_path("/"); > arch/powerpc/platforms/85xx/xes_mpc85xx.c:119: root = of_find_node_by_path("/"); > arch/powerpc/platforms/cell/setup.c:67: root = of_find_node_by_path("/"); > arch/powerpc/platforms/cell/setup.c:154: struct device_node *root > = of_find_node_by_path("/"); > arch/powerpc/platforms/chrp/pci.c:191: struct device_node *root = of_find_node_by_path("/"); > arch/powerpc/platforms/chrp/pci.c:216: struct device_node *root = of_find_node_by_path("/"); > arch/powerpc/platforms/chrp/setup.c:105: root = of_find_node_by_path("/"); > arch/powerpc/platforms/chrp/setup.c:201: root = of_find_node_by_path("/"); > arch/powerpc/platforms/chrp/setup.c:268: node = of_find_node_by_path("/"); > arch/powerpc/platforms/chrp/setup.c:299: struct device_node *root > = of_find_node_by_path("/"); > arch/powerpc/platforms/chrp/setup.c:378: root = of_find_node_by_path("/"); > arch/powerpc/platforms/maple/pci.c:601: root = of_find_node_by_path("/"); > arch/powerpc/platforms/maple/setup.c:225: root = of_find_node_by_path("/"); > arch/powerpc/platforms/pasemi/pci.c:276: root = of_find_node_by_path("/"); > arch/powerpc/platforms/pasemi/setup.c:268: root = of_find_node_by_path("/"); > arch/powerpc/platforms/powermac/pci.c:910: root = of_find_node_by_path("/"); > arch/powerpc/platforms/powermac/setup.c:105: np = of_find_node_by_path("/"); > arch/powerpc/platforms/powernv/setup.c:255: root = of_find_node_by_path("/"); > arch/powerpc/platforms/ps3/os-area.c:676: node = of_find_node_by_path("/"); > arch/powerpc/platforms/ps3/os-area.c:774: node = of_find_node_by_path("/"); > arch/powerpc/platforms/pseries/hotplug-memory.c:166: parent = of_find_node_by_path("/"); > arch/powerpc/platforms/pseries/ibmebus.c:187: root = of_find_node_by_path("/"); > arch/powerpc/platforms/pseries/lparcfg.c:232: root = of_find_node_by_path("/"); > arch/powerpc/platforms/pseries/lparcfg.c:799: rootdn = of_find_node_by_path("/"); > arch/powerpc/platforms/pseries/setup.c:97: root = of_find_node_by_path("/"); > arch/powerpc/platforms/pseries/setup.c:486: struct device_node *root > = of_find_node_by_path("/"); > arch/powerpc/sysdev/xive/spapr.c:714: rootdn = of_find_node_by_path("/"); > > Christophe > > >> Reported-by: Liang He <windhl@126.com> >> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> >> --- >> arch/powerpc/platforms/pasemi/pci.c | 10 ++-------- >> 1 file changed, 2 insertions(+), 8 deletions(-) >> >> diff --git a/arch/powerpc/platforms/pasemi/pci.c b/arch/powerpc/platforms/pasemi/pci.c >> index 55f0160910bf..f27d31414737 100644 >> --- a/arch/powerpc/platforms/pasemi/pci.c >> +++ b/arch/powerpc/platforms/pasemi/pci.c >> @@ -270,18 +270,12 @@ static int __init pas_add_bridge(struct device_node *dev) >> >> void __init pas_pci_init(void) >> { >> - struct device_node *np, *root; >> + struct device_node *np; >> int res; >> >> - root = of_find_node_by_path("/"); >> - if (!root) { >> - pr_crit("pas_pci_init: can't find root of device tree\n"); >> - return; >> - } >> - >> pci_set_flags(PCI_SCAN_ALL_PCIE_DEVS); >> >> - np = of_find_compatible_node(root, NULL, "pasemi,rootbus"); >> + np = of_find_compatible_node(of_root, NULL, "pasemi,rootbus"); >> if (np) { >> res = pas_add_bridge(np); >> of_node_put(np);
On Tue, 6 Sep 2022 11:03:13 +1000, Michael Ellerman wrote: > Currently in pas_pci_init() a reference to the root node is leaked due > to a missing of_node_put(). Instead just use of_root directly. > > Note that converting to of_find_compatible_node(NULL, ...) would > not be entirely equivalent, because that would check the compatible > property of the root node, whereas using of_root skips checking the root > node and start the search at the first child of the root. > > [...] Applied to powerpc/next. [1/1] powerpc/pasemi: Use of_root in pas_pci_init() https://git.kernel.org/powerpc/c/c28c2d4abdf95655001992c4f52dc243ba00cac3 cheers
diff --git a/arch/powerpc/platforms/pasemi/pci.c b/arch/powerpc/platforms/pasemi/pci.c index 55f0160910bf..f27d31414737 100644 --- a/arch/powerpc/platforms/pasemi/pci.c +++ b/arch/powerpc/platforms/pasemi/pci.c @@ -270,18 +270,12 @@ static int __init pas_add_bridge(struct device_node *dev) void __init pas_pci_init(void) { - struct device_node *np, *root; + struct device_node *np; int res; - root = of_find_node_by_path("/"); - if (!root) { - pr_crit("pas_pci_init: can't find root of device tree\n"); - return; - } - pci_set_flags(PCI_SCAN_ALL_PCIE_DEVS); - np = of_find_compatible_node(root, NULL, "pasemi,rootbus"); + np = of_find_compatible_node(of_root, NULL, "pasemi,rootbus"); if (np) { res = pas_add_bridge(np); of_node_put(np);
Currently in pas_pci_init() a reference to the root node is leaked due to a missing of_node_put(). Instead just use of_root directly. Note that converting to of_find_compatible_node(NULL, ...) would not be entirely equivalent, because that would check the compatible property of the root node, whereas using of_root skips checking the root node and start the search at the first child of the root. Reported-by: Liang He <windhl@126.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> --- arch/powerpc/platforms/pasemi/pci.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)