Skip to content
/ linux Public

Commit 47a3e37

Browse files
GoodLuck612Sasha Levin
authored andcommitted
soc: mediatek: svs: Fix memory leak in svs_enable_debug_write()
[ Upstream commit 6259094 ] In svs_enable_debug_write(), the buf allocated by memdup_user_nul() is leaked if kstrtoint() fails. Fix this by using __free(kfree) to automatically free buf, eliminating the need for explicit kfree() calls and preventing leaks. Fixes: 13f1bbc ("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> [Angelo: Added missing cleanup.h inclusion] Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 7ed9a1d commit 47a3e37

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/soc/mediatek/mtk-svs.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/bits.h>
88
#include <linux/clk.h>
99
#include <linux/completion.h>
10+
#include <linux/cleanup.h>
1011
#include <linux/cpu.h>
1112
#include <linux/cpuidle.h>
1213
#include <linux/debugfs.h>
@@ -709,7 +710,7 @@ static ssize_t svs_enable_debug_write(struct file *filp,
709710
struct svs_platform *svsp = dev_get_drvdata(svsb->dev);
710711
unsigned long flags;
711712
int enabled, ret;
712-
char *buf = NULL;
713+
char *buf __free(kfree) = NULL;
713714

714715
if (count >= PAGE_SIZE)
715716
return -EINVAL;
@@ -735,8 +736,6 @@ static ssize_t svs_enable_debug_write(struct file *filp,
735736
svs_adjust_pm_opp_volts(svsb);
736737
}
737738

738-
kfree(buf);
739-
740739
return count;
741740
}
742741

0 commit comments

Comments
 (0)