summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKunwu Chan <chentao@kylinos.cn>2023-11-26 10:57:39 +0100
committerMichael Ellerman <mpe@ellerman.id.au>2023-12-13 12:19:07 +0100
commite123015c0ba859cf48aa7f89c5016cc6e98e018d (patch)
treea265e574706b93d2c69838b61b6d1163ad86cb66
parentpowerpc/powernv: Add a null pointer check in opal_event_init() (diff)
downloadlinux-e123015c0ba859cf48aa7f89c5016cc6e98e018d.tar.xz
linux-e123015c0ba859cf48aa7f89c5016cc6e98e018d.zip
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: b9ef7b4b867f ("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
-rw-r--r--arch/powerpc/platforms/powernv/opal-powercap.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/arch/powerpc/platforms/powernv/opal-powercap.c b/arch/powerpc/platforms/powernv/opal-powercap.c
index 7bfe4cbeb35a..ea917266aa17 100644
--- a/arch/powerpc/platforms/powernv/opal-powercap.c
+++ b/arch/powerpc/platforms/powernv/opal-powercap.c
@@ -196,6 +196,12 @@ void __init opal_powercap_init(void)
j = 0;
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) {
powercap_add_attr(min, "powercap-min",
&pcaps[i].pattrs[j]);