diff mbox series

powerpc/pseries: Fix potential memleak in papr_get_attr()

Message ID 20221208133449.16284-1-linqiheng@huawei.com (mailing list archive)
State Accepted
Commit cda9c0d556283e2d4adaa9960b2dc19b16156bae
Headers show
Series powerpc/pseries: Fix potential memleak in papr_get_attr() | expand

Checks

Context Check Description
snowpatch_ozlabs/github-powerpc_ppctests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_selftests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_kernel_qemu success Successfully ran 24 jobs.
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.

Commit Message

Qiheng Lin Dec. 8, 2022, 1:34 p.m. UTC
`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>
---
 arch/powerpc/platforms/pseries/papr_platform_attributes.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Michael Ellerman March 13, 2024, 1:19 p.m. UTC | #1
On Thu, 08 Dec 2022 21:34:49 +0800, Qiheng Lin wrote:
> `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.
> 
> 

Applied to powerpc/next.

[1/1] powerpc/pseries: Fix potential memleak in papr_get_attr()
      https://git.kernel.org/powerpc/c/cda9c0d556283e2d4adaa9960b2dc19b16156bae

cheers
diff mbox series

Patch

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 @@  static int papr_get_attr(u64 id, struct energy_scale_attribute *esi)
 		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;
 	}