Skip to contentSkip to conversation

powerpc/pseries: Fix potential memleak in papr_get_attr()

PATCH Applied Qiheng Lin 2 participants 2 messages Dec 8, 2022 – Mar 13, 2024 PowerPC

lore
Share & tools
lore

Qiheng Lin

author
#0 lore raw

PATCH 1/1 powerpc/pseries: Fix potential memleak in papr_get_attr()

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")
---
 arch/powerpc/platforms/pseries/papr_platform_attributes.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/powerpc/platforms/pseries/papr_platform_attributes.c +5 -3
index 526c621b098b..eea2041b270b 100644
@@ -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;
 	}
Signature · 1 line
2.32.0