powerpc/pseries: Fix potential memleak in papr_get_attr()
authorQiheng Lin <linqiheng@huawei.com>
Thu, 8 Dec 2022 13:34:49 +0000 (21:34 +0800)
committerMichael Ellerman <mpe@ellerman.id.au>
Sun, 3 Mar 2024 11:20:28 +0000 (22:20 +1100)
`buf` is allocated in papr_get_attr(), and krealloc() of `buf`
could fail. We need to free the original `buf` in the case of failure.

Fixes: 3c14b73454cf ("powerpc/pseries: Interface to represent PAPR firmware attributes")
Signed-off-by: Qiheng Lin <linqiheng@huawei.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20221208133449.16284-1-linqiheng@huawei.com
arch/powerpc/platforms/pseries/papr_platform_attributes.c

index 526c621b098bece600fdfe72de1c4f53697d33f5..eea2041b270b546477a34e3836662969d6dd25eb 100644 (file)
@@ -101,10 +101,12 @@ retry:
                esi_buf_size = ESI_HDR_SIZE + (CURR_MAX_ESI_ATTRS * max_esi_attrs);
 
                temp_buf = krealloc(buf, esi_buf_size, GFP_KERNEL);
-               if (temp_buf)
+               if (temp_buf) {
                        buf = temp_buf;
-               else
-                       return -ENOMEM;
+               } else {
+                       ret = -ENOMEM;
+                       goto out_buf;
+               }
 
                goto retry;
        }