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: 13f1bbcfb582 ("soc: mediatek: SVS: add debug commands") Cc: stable@vger.kernel.org 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 --- Changes in v3: - Reduce the scope of the involved local variable. - Add Cc to stable.
Changes in v2: - Use __free(kfree) to simplify memory management.
drivers/soc/mediatek/mtk-svs.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/soc/mediatek/mtk-svs.c b/drivers/soc/mediatek/mtk-svs.c index f45537546553..475926a606fd 100644 --- a/drivers/soc/mediatek/mtk-svs.c +++ b/drivers/soc/mediatek/mtk-svs.c @@ -789,12 +789,11 @@ static ssize_t svs_enable_debug_write(struct file *filp, struct svs_bank *svsb = file_inode(filp)->i_private; struct svs_platform *svsp = dev_get_drvdata(svsb->dev); int enabled, ret; - char *buf = NULL;
if (count >= PAGE_SIZE) return -EINVAL;
- buf = (char *)memdup_user_nul(buffer, count); + char *buf __free(kfree) = (char *)memdup_user_nul(buffer, count); if (IS_ERR(buf)) return PTR_ERR(buf);
@@ -807,8 +806,6 @@ static ssize_t svs_enable_debug_write(struct file *filp, svsb->mode_support = SVSB_MODE_ALL_DISABLE; }
- kfree(buf); - return count; }
linux-stable-mirror@lists.linaro.org