Skip to content

Commit 605c27f

Browse files
windhlmpe
authored andcommitted
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 <[email protected]> [mpe: Use out_put_xxx goto label naming] Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent afa6a47 commit 605c27f

File tree

6 files changed

+20
-3
lines changed

6 files changed

+20
-3
lines changed

arch/powerpc/platforms/powernv/idle.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,7 @@ static int __init pnv_parse_cpuidle_dt(void)
14191419
kfree(temp_u32);
14201420
kfree(temp_u64);
14211421
kfree(temp_string);
1422+
of_node_put(np);
14221423
return rc;
14231424
}
14241425

arch/powerpc/platforms/powernv/opal-core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ static int __init create_opalcore(void)
348348
if (!dn || ret)
349349
pr_warn("WARNING: Failed to read OPAL base & entry values\n");
350350

351+
of_node_put(dn);
352+
351353
/* Use count to keep track of the program headers */
352354
count = 0;
353355

arch/powerpc/platforms/powernv/opal-powercap.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void __init opal_powercap_init(void)
153153
pcaps = kcalloc(of_get_child_count(powercap), sizeof(*pcaps),
154154
GFP_KERNEL);
155155
if (!pcaps)
156-
return;
156+
goto out_put_powercap;
157157

158158
powercap_kobj = kobject_create_and_add("powercap", opal_kobj);
159159
if (!powercap_kobj) {
@@ -226,6 +226,7 @@ void __init opal_powercap_init(void)
226226
}
227227
i++;
228228
}
229+
of_node_put(powercap);
229230

230231
return;
231232

@@ -236,6 +237,9 @@ void __init opal_powercap_init(void)
236237
kfree(pcaps[i].pg.name);
237238
}
238239
kobject_put(powercap_kobj);
240+
of_node_put(node);
239241
out_pcaps:
240242
kfree(pcaps);
243+
out_put_powercap:
244+
of_node_put(powercap);
241245
}

arch/powerpc/platforms/powernv/opal-psr.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void __init opal_psr_init(void)
135135
psr_attrs = kcalloc(of_get_child_count(psr), sizeof(*psr_attrs),
136136
GFP_KERNEL);
137137
if (!psr_attrs)
138-
return;
138+
goto out_put_psr;
139139

140140
psr_kobj = kobject_create_and_add("psr", opal_kobj);
141141
if (!psr_kobj) {
@@ -162,10 +162,14 @@ void __init opal_psr_init(void)
162162
}
163163
i++;
164164
}
165+
of_node_put(psr);
165166

166167
return;
167168
out_kobj:
169+
of_node_put(node);
168170
kobject_put(psr_kobj);
169171
out:
170172
kfree(psr_attrs);
173+
out_put_psr:
174+
of_node_put(psr);
171175
}

arch/powerpc/platforms/powernv/opal-sensor-groups.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void __init opal_sensor_groups_init(void)
170170

171171
sgs = kcalloc(of_get_child_count(sg), sizeof(*sgs), GFP_KERNEL);
172172
if (!sgs)
173-
return;
173+
goto out_sg_put;
174174

175175
sg_kobj = kobject_create_and_add("sensor_groups", opal_kobj);
176176
if (!sg_kobj) {
@@ -222,6 +222,7 @@ void __init opal_sensor_groups_init(void)
222222
}
223223
i++;
224224
}
225+
of_node_put(sg);
225226

226227
return;
227228

@@ -231,6 +232,9 @@ void __init opal_sensor_groups_init(void)
231232
kfree(sgs[i].sg.attrs);
232233
}
233234
kobject_put(sg_kobj);
235+
of_node_put(node);
234236
out_sgs:
235237
kfree(sgs);
238+
out_sg_put:
239+
of_node_put(sg);
236240
}

arch/powerpc/platforms/powernv/opal.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,8 @@ static void __init opal_imc_init_dev(void)
952952
np = of_find_compatible_node(NULL, NULL, IMC_DTB_COMPAT);
953953
if (np)
954954
of_platform_device_create(np, NULL, NULL);
955+
956+
of_node_put(np);
955957
}
956958

957959
static int kopald(void *unused)

0 commit comments

Comments
 (0)