powerpc/powernv: Add missing of_node_put()s

In these driver init functions, there are two kinds of errors:

(1) missing of_put_node() for of_find_compatible_node()'s returned
    pointer (refcount incremented)  in fail path or when it is not
    used anymore.
(2) missing of_put_node() for 'for_each_xxx' loop's break

Signed-off-by: Liang He <windhl@126.com>
[mpe: Use out_put_xxx goto label naming]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220620132553.4073863-1-windhl@126.com
This commit is contained in:
Liang He 2022-06-20 21:25:53 +08:00 committed by Michael Ellerman
parent afa6a472a3
commit 605c27f380
6 changed files with 20 additions and 3 deletions

View File

@ -1419,6 +1419,7 @@ static int __init pnv_parse_cpuidle_dt(void)
kfree(temp_u32); kfree(temp_u32);
kfree(temp_u64); kfree(temp_u64);
kfree(temp_string); kfree(temp_string);
of_node_put(np);
return rc; return rc;
} }

View File

@ -348,6 +348,8 @@ static int __init create_opalcore(void)
if (!dn || ret) if (!dn || ret)
pr_warn("WARNING: Failed to read OPAL base & entry values\n"); pr_warn("WARNING: Failed to read OPAL base & entry values\n");
of_node_put(dn);
/* Use count to keep track of the program headers */ /* Use count to keep track of the program headers */
count = 0; count = 0;

View File

@ -153,7 +153,7 @@ void __init opal_powercap_init(void)
pcaps = kcalloc(of_get_child_count(powercap), sizeof(*pcaps), pcaps = kcalloc(of_get_child_count(powercap), sizeof(*pcaps),
GFP_KERNEL); GFP_KERNEL);
if (!pcaps) if (!pcaps)
return; goto out_put_powercap;
powercap_kobj = kobject_create_and_add("powercap", opal_kobj); powercap_kobj = kobject_create_and_add("powercap", opal_kobj);
if (!powercap_kobj) { if (!powercap_kobj) {
@ -226,6 +226,7 @@ void __init opal_powercap_init(void)
} }
i++; i++;
} }
of_node_put(powercap);
return; return;
@ -236,6 +237,9 @@ void __init opal_powercap_init(void)
kfree(pcaps[i].pg.name); kfree(pcaps[i].pg.name);
} }
kobject_put(powercap_kobj); kobject_put(powercap_kobj);
of_node_put(node);
out_pcaps: out_pcaps:
kfree(pcaps); kfree(pcaps);
out_put_powercap:
of_node_put(powercap);
} }

View File

@ -135,7 +135,7 @@ void __init opal_psr_init(void)
psr_attrs = kcalloc(of_get_child_count(psr), sizeof(*psr_attrs), psr_attrs = kcalloc(of_get_child_count(psr), sizeof(*psr_attrs),
GFP_KERNEL); GFP_KERNEL);
if (!psr_attrs) if (!psr_attrs)
return; goto out_put_psr;
psr_kobj = kobject_create_and_add("psr", opal_kobj); psr_kobj = kobject_create_and_add("psr", opal_kobj);
if (!psr_kobj) { if (!psr_kobj) {
@ -162,10 +162,14 @@ void __init opal_psr_init(void)
} }
i++; i++;
} }
of_node_put(psr);
return; return;
out_kobj: out_kobj:
of_node_put(node);
kobject_put(psr_kobj); kobject_put(psr_kobj);
out: out:
kfree(psr_attrs); kfree(psr_attrs);
out_put_psr:
of_node_put(psr);
} }

View File

@ -170,7 +170,7 @@ void __init opal_sensor_groups_init(void)
sgs = kcalloc(of_get_child_count(sg), sizeof(*sgs), GFP_KERNEL); sgs = kcalloc(of_get_child_count(sg), sizeof(*sgs), GFP_KERNEL);
if (!sgs) if (!sgs)
return; goto out_sg_put;
sg_kobj = kobject_create_and_add("sensor_groups", opal_kobj); sg_kobj = kobject_create_and_add("sensor_groups", opal_kobj);
if (!sg_kobj) { if (!sg_kobj) {
@ -222,6 +222,7 @@ void __init opal_sensor_groups_init(void)
} }
i++; i++;
} }
of_node_put(sg);
return; return;
@ -231,6 +232,9 @@ void __init opal_sensor_groups_init(void)
kfree(sgs[i].sg.attrs); kfree(sgs[i].sg.attrs);
} }
kobject_put(sg_kobj); kobject_put(sg_kobj);
of_node_put(node);
out_sgs: out_sgs:
kfree(sgs); kfree(sgs);
out_sg_put:
of_node_put(sg);
} }

View File

@ -952,6 +952,8 @@ static void __init opal_imc_init_dev(void)
np = of_find_compatible_node(NULL, NULL, IMC_DTB_COMPAT); np = of_find_compatible_node(NULL, NULL, IMC_DTB_COMPAT);
if (np) if (np)
of_platform_device_create(np, NULL, NULL); of_platform_device_create(np, NULL, NULL);
of_node_put(np);
} }
static int kopald(void *unused) static int kopald(void *unused)