* [PATCH] soc: mediatek: SVS: Fix memory leak in svs_enable_debug_write()
@ 2025-12-28 12:52 Zilin Guan
2025-12-28 14:19 ` Markus Elfring
0 siblings, 1 reply; 3+ messages in thread
From: Zilin Guan @ 2025-12-28 12:52 UTC (permalink / raw)
To: matthias.bgg
Cc: angelogioacchino.delregno, linux-kernel, linux-arm-kernel,
linux-mediatek, Zilin Guan, Jianhao Xu
In svs_enable_debug_write(), the buf is allocated via memdup_user_nul().
If kstrtoint() fails, the function returns directly without freeing the
allocated memory, leading to a memory leak.
Fix this by freeing buf before returning the error code.
Fixes: 13f1bbcfb582 ("soc: mediatek: SVS: add debug commands")
Co-developed-by: Jianhao Xu <jianhao.xu@seu.edu.cn>
Signed-off-by: Jianhao Xu <jianhao.xu@seu.edu.cn>
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
drivers/soc/mediatek/mtk-svs.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/soc/mediatek/mtk-svs.c b/drivers/soc/mediatek/mtk-svs.c
index f45537546553..691e7e6be654 100644
--- a/drivers/soc/mediatek/mtk-svs.c
+++ b/drivers/soc/mediatek/mtk-svs.c
@@ -799,8 +799,10 @@ static ssize_t svs_enable_debug_write(struct file *filp,
return PTR_ERR(buf);
ret = kstrtoint(buf, 10, &enabled);
- if (ret)
+ if (ret) {
+ kfree(buf);
return ret;
+ }
if (!enabled) {
svs_bank_disable_and_restore_default_volts(svsp, svsb);
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] soc: mediatek: SVS: Fix memory leak in svs_enable_debug_write()
2025-12-28 12:52 [PATCH] soc: mediatek: SVS: Fix memory leak in svs_enable_debug_write() Zilin Guan
@ 2025-12-28 14:19 ` Markus Elfring
2025-12-28 16:21 ` Zilin Guan
0 siblings, 1 reply; 3+ messages in thread
From: Markus Elfring @ 2025-12-28 14:19 UTC (permalink / raw)
To: Jianhao Xu, Zilin Guan, linux-mediatek, linux-arm-kernel,
Matthias Brugger
Cc: LKML, Angelo Gioacchino Del Regno
…
> Fix this by freeing buf before returning the error code.
How do you think about to use the attribute “__free(kfree)”?
https://elixir.bootlin.com/linux/v6.19-rc2/source/include/linux/slab.h#L512
https://elixir.bootlin.com/linux/v6.19-rc2/source/drivers/soc/mediatek/mtk-svs.c#L785-L813
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] soc: mediatek: SVS: Fix memory leak in svs_enable_debug_write()
2025-12-28 14:19 ` Markus Elfring
@ 2025-12-28 16:21 ` Zilin Guan
0 siblings, 0 replies; 3+ messages in thread
From: Zilin Guan @ 2025-12-28 16:21 UTC (permalink / raw)
To: markus.elfring
Cc: angelogioacchino.delregno, jianhao.xu, linux-arm-kernel,
linux-kernel, linux-mediatek, matthias.bgg, zilin
On Sun, Dec 28, 2025 at 03:19:00PM+0100, Markus Elfring wrote:
> …
> > Fix this by freeing buf before returning the error code.
>
> How do you think about to use the attribute “__free(kfree)”?
> https://elixir.bootlin.com/linux/v6.19-rc2/source/include/linux/slab.h#L512
> https://elixir.bootlin.com/linux/v6.19-rc2/source/drivers/soc/mediatek/mtk-svs.c#L785-L813
>
> Regards,
> Markus
Hi Markus,
Thanks for the suggestion.
I agree that using the "__free(kfree)" attribute is a good way to
simplify memory management here. I will apply this change in the
v2 patch.
Regards,
Zilin Guan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-28 17:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-28 12:52 [PATCH] soc: mediatek: SVS: Fix memory leak in svs_enable_debug_write() Zilin Guan
2025-12-28 14:19 ` Markus Elfring
2025-12-28 16:21 ` Zilin Guan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®