* [PATCH] powerpc/pseries: Fix potential memleak in papr_get_attr()
@ 2022-12-08 13:34 ` Qiheng Lin
0 siblings, 0 replies; 3+ messages in thread
From: Qiheng Lin @ 2022-12-08 13:34 UTC (permalink / raw
To: mpe, npiggin, christophe.leroy; +Cc: linuxppc-dev, linux-kernel, linqiheng
`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(-)
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;
}
--
2.32.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH] powerpc/pseries: Fix potential memleak in papr_get_attr()
@ 2022-12-08 13:34 ` Qiheng Lin
0 siblings, 0 replies; 3+ messages in thread
From: Qiheng Lin @ 2022-12-08 13:34 UTC (permalink / raw
To: mpe, npiggin, christophe.leroy; +Cc: linqiheng, linuxppc-dev, linux-kernel
`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(-)
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;
}
--
2.32.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc/pseries: Fix potential memleak in papr_get_attr()
2022-12-08 13:34 ` Qiheng Lin
(?)
@ 2024-03-13 13:19 ` Michael Ellerman
-1 siblings, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2024-03-13 13:19 UTC (permalink / raw
To: npiggin, christophe.leroy, Qiheng Lin; +Cc: linuxppc-dev, linux-kernel
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-13 13:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-08 13:34 [PATCH] powerpc/pseries: Fix potential memleak in papr_get_attr() Qiheng Lin
2022-12-08 13:34 ` Qiheng Lin
2024-03-13 13:19 ` Michael Ellerman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.