summaryrefslogtreecommitdiffstats
path: root/arch/powerpc
diff options
context:
space:
mode:
authorQiheng Lin <linqiheng@huawei.com>2022-12-08 21:34:49 +0800
committerSasha Levin <sashal@kernel.org>2024-03-26 18:18:41 -0400
commit7f7d39fe3d80d6143404940b2413010cf6527029 (patch)
treef0358474fe11538d6cffa502a0f426bd5705203a /arch/powerpc
parent819caca474e501809d0952ec88793fb366a17fe0 (diff)
downloadlinux-stable-7f7d39fe3d80d6143404940b2413010cf6527029.tar.gz
linux-stable-7f7d39fe3d80d6143404940b2413010cf6527029.tar.bz2
linux-stable-7f7d39fe3d80d6143404940b2413010cf6527029.zip
powerpc/pseries: Fix potential memleak in papr_get_attr()
[ Upstream commit cda9c0d556283e2d4adaa9960b2dc19b16156bae ] `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 Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'arch/powerpc')
-rw-r--r--arch/powerpc/platforms/pseries/papr_platform_attributes.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/arch/powerpc/platforms/pseries/papr_platform_attributes.c b/arch/powerpc/platforms/pseries/papr_platform_attributes.c
index 526c621b098b..eea2041b270b 100644
--- a/arch/powerpc/platforms/pseries/papr_platform_attributes.c
+++ b/arch/powerpc/platforms/pseries/papr_platform_attributes.c
@@ -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;
}