[PATCH v3] mfd: mc13xxx-core: Fix memory leak in mc13xxx_add_subdevice_pdata()

Abdun Nihaal posted 1 patch 2 weeks, 5 days ago
drivers/mfd/mc13xxx-core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH v3] mfd: mc13xxx-core: Fix memory leak in mc13xxx_add_subdevice_pdata()
Posted by Abdun Nihaal 2 weeks, 5 days ago
The memory allocated for cell.name using kmemdup() is not freed when
mfd_add_devices() fails. Fix that by using devm_kmemdup().

Fixes: 8e00593557c3 ("mfd: Add mc13892 support to mc13xxx")
Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>
---
v2->v3:
- Use devm_kmemdup() to fix the memory leak as suggested by Lee Jones

v1->v2:
- Added the include of slab.h to ensure kfree is declared before use, to
  fix the compiler warning pointed out by kernel test robot.

v2 link: https://lore.kernel.org/all/20251127044500.44820-1-nihaal@cse.iitm.ac.in/

 drivers/mfd/mc13xxx-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c
index 920797b806ce..786eab3b2d03 100644
--- a/drivers/mfd/mc13xxx-core.c
+++ b/drivers/mfd/mc13xxx-core.c
@@ -377,7 +377,7 @@ static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx,
 	if (snprintf(buf, sizeof(buf), format, name) > sizeof(buf))
 		return -E2BIG;
 
-	cell.name = kmemdup(buf, strlen(buf) + 1, GFP_KERNEL);
+	cell.name = devm_kmemdup(mc13xxx->dev, buf, strlen(buf) + 1, GFP_KERNEL);
 	if (!cell.name)
 		return -ENOMEM;
 
-- 
2.43.0
Re: (subset) [PATCH v3] mfd: mc13xxx-core: Fix memory leak in mc13xxx_add_subdevice_pdata()
Posted by Lee Jones 3 days, 10 hours ago
On Tue, 20 Jan 2026 15:56:20 +0530, Abdun Nihaal wrote:
> The memory allocated for cell.name using kmemdup() is not freed when
> mfd_add_devices() fails. Fix that by using devm_kmemdup().
> 
> 

Applied, thanks!

[1/1] mfd: mc13xxx-core: Fix memory leak in mc13xxx_add_subdevice_pdata()
      commit: 34d2638a97f8eab67557cf7dd6281e70eff9f666

--
Lee Jones [李琼斯]