Commit e123015c authored by Kunwu Chan's avatar Kunwu Chan Committed by Michael Ellerman

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: b9ef7b4b ("powerpc: Convert to using %pOFn instead of device_node.name")
Signed-off-by: default avatarKunwu Chan <chentao@kylinos.cn>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20231126095739.1501990-1-chentao@kylinos.cn
parent 8649829a
...@@ -196,6 +196,12 @@ void __init opal_powercap_init(void) ...@@ -196,6 +196,12 @@ void __init opal_powercap_init(void)
j = 0; j = 0;
pcaps[i].pg.name = kasprintf(GFP_KERNEL, "%pOFn", node); pcaps[i].pg.name = kasprintf(GFP_KERNEL, "%pOFn", node);
if (!pcaps[i].pg.name) {
kfree(pcaps[i].pattrs);
kfree(pcaps[i].pg.attrs);
goto out_pcaps_pattrs;
}
if (has_min) { if (has_min) {
powercap_add_attr(min, "powercap-min", powercap_add_attr(min, "powercap-min",
&pcaps[i].pattrs[j]); &pcaps[i].pattrs[j]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment