Skip to content

Commit e123015

Browse files
KunWuChanmpe
authored andcommitted
powerpc/powernv: Add a null pointer check in opal_powercap_init()
kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure. Fixes: b9ef7b4 ("powerpc: Convert to using %pOFn instead of device_node.name") Signed-off-by: Kunwu Chan <chentao@kylinos.cn> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://msgid.link/20231126095739.1501990-1-chentao@kylinos.cn
1 parent 8649829 commit e123015

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ void __init opal_powercap_init(void)
196196

197197
j = 0;
198198
pcaps[i].pg.name = kasprintf(GFP_KERNEL, "%pOFn", node);
199+
if (!pcaps[i].pg.name) {
200+
kfree(pcaps[i].pattrs);
201+
kfree(pcaps[i].pg.attrs);
202+
goto out_pcaps_pattrs;
203+
}
204+
199205
if (has_min) {
200206
powercap_add_attr(min, "powercap-min",
201207
&pcaps[i].pattrs[j]);

0 commit comments

Comments
 (0)