[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20251125171936.98101-1-nihaal@cse.iitm.ac.in>
Date: Tue, 25 Nov 2025 22:49:33 +0530
From: Abdun Nihaal <nihaal@....iitm.ac.in>
To: lee@...nel.org
Cc: Abdun Nihaal <nihaal@....iitm.ac.in>,
linux-kernel@...r.kernel.org
Subject: [PATCH] mfd: mc13xxx-core: Fix memory leak in mc13xxx_add_subdevice_pdata()
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@....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
Powered by blists - more mailing lists