public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mfd: mc13xxx-core: Fix memory leak in mc13xxx_add_subdevice_pdata()
@ 2025-11-25 17:19 Abdun Nihaal
  2025-11-26 14:45 ` kernel test robot
  2025-11-26 18:17 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Abdun Nihaal @ 2025-11-25 17:19 UTC (permalink / raw)
  To: lee; +Cc: Abdun Nihaal, linux-kernel

The memory allocated for cell.name using kmemdup() is not freed when
mfd_add_devices() fails. Fix that by checking return code and freeing.

Fixes: 8e00593557c3 ("mfd: Add mc13892 support to mc13xxx")
Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>
---
Compile tested only. Issue found using static analysis.

 drivers/mfd/mc13xxx-core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c
index 920797b806ce..1ebf849d80fe 100644
--- a/drivers/mfd/mc13xxx-core.c
+++ b/drivers/mfd/mc13xxx-core.c
@@ -365,6 +365,7 @@ EXPORT_SYMBOL_GPL(mc13xxx_adc_do_conversion);
 static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx,
 		const char *format, void *pdata, size_t pdata_size)
 {
+	int ret;
 	char buf[30];
 	const char *name = mc13xxx_get_chipname(mc13xxx);
 
@@ -381,8 +382,11 @@ static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx,
 	if (!cell.name)
 		return -ENOMEM;
 
-	return mfd_add_devices(mc13xxx->dev, -1, &cell, 1, NULL, 0,
+	ret = mfd_add_devices(mc13xxx->dev, -1, &cell, 1, NULL, 0,
 			       regmap_irq_get_domain(mc13xxx->irq_data));
+	if (ret)
+		kfree(cell.name);
+	return ret;
 }
 
 static int mc13xxx_add_subdevice(struct mc13xxx *mc13xxx, const char *format)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-26 18:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-25 17:19 [PATCH] mfd: mc13xxx-core: Fix memory leak in mc13xxx_add_subdevice_pdata() Abdun Nihaal
2025-11-26 14:45 ` kernel test robot
2025-11-26 18:17 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox