Skip to content

Commit 6259094

Browse files
GoodLuck612AngeloGioacchino Del Regno
authored andcommitted
soc: mediatek: svs: Fix memory leak in svs_enable_debug_write()
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>
1 parent 8f0b4cc commit 6259094

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

drivers/soc/mediatek/mtk-svs.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/bits.h>
1010
#include <linux/clk.h>
1111
#include <linux/completion.h>
12+
#include <linux/cleanup.h>
1213
#include <linux/cpu.h>
1314
#include <linux/cpuidle.h>
1415
#include <linux/debugfs.h>
@@ -789,7 +790,7 @@ static ssize_t svs_enable_debug_write(struct file *filp,
789790
struct svs_bank *svsb = file_inode(filp)->i_private;
790791
struct svs_platform *svsp = dev_get_drvdata(svsb->dev);
791792
int enabled, ret;
792-
char *buf = NULL;
793+
char *buf __free(kfree) = NULL;
793794

794795
if (count >= PAGE_SIZE)
795796
return -EINVAL;
@@ -807,8 +808,6 @@ static ssize_t svs_enable_debug_write(struct file *filp,
807808
svsb->mode_support = SVSB_MODE_ALL_DISABLE;
808809
}
809810

810-
kfree(buf);
811-
812811
return count;
813812
}
814813

0 commit comments

Comments
 (0)