diff mbox series

ti: fix possible memory leak in _ti_omap4_clkctrl_setup

Message ID 20231025090741.32997-1-hbh25y@gmail.com (mailing list archive)
State New, archived
Headers show
Series ti: fix possible memory leak in _ti_omap4_clkctrl_setup | expand

Commit Message

Hangyu Hua Oct. 25, 2023, 9:07 a.m. UTC
kstrndup and kstrdup_and_replace in clkctrl_get_name can perform
dynamic memory allocation. So clkctrl_name needs to be freed when
provider->clkdm_name is NULL.

Fixes: bd46cd0b802d ("clk: ti: clkctrl: check return value of kasprintf()")
Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
---
 drivers/clk/ti/clkctrl.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Andy Shevchenko Oct. 26, 2023, 12:18 p.m. UTC | #1
On Wed, Oct 25, 2023 at 05:07:41PM +0800, Hangyu Hua wrote:
> kstrndup and kstrdup_and_replace in clkctrl_get_name can perform

kstrndup()
kstrdup_and_replace()
clkctrl_get_name()

> dynamic memory allocation. So clkctrl_name needs to be freed when
> provider->clkdm_name is NULL.
Hangyu Hua Oct. 27, 2023, 2:13 a.m. UTC | #2
On 26/10/2023 20:18, Andy Shevchenko wrote:
> On Wed, Oct 25, 2023 at 05:07:41PM +0800, Hangyu Hua wrote:
>> kstrndup and kstrdup_and_replace in clkctrl_get_name can perform
> 
> kstrndup()
> kstrdup_and_replace()
> clkctrl_get_name()
> 

I see. I will send a v2 later.

Thanks,
Hangyu

>> dynamic memory allocation. So clkctrl_name needs to be freed when
>> provider->clkdm_name is NULL.
>
diff mbox series

Patch

diff --git a/drivers/clk/ti/clkctrl.c b/drivers/clk/ti/clkctrl.c
index 607e34d8e289..cb4aa8a45bb2 100644
--- a/drivers/clk/ti/clkctrl.c
+++ b/drivers/clk/ti/clkctrl.c
@@ -591,6 +591,7 @@  static void __init _ti_omap4_clkctrl_setup(struct device_node *node)
 		provider->clkdm_name = kasprintf(GFP_KERNEL,
 						 "%s_clkdm", clkctrl_name);
 		if (!provider->clkdm_name) {
+			kfree(clkctrl_name);
 			kfree(provider);
 			return;
 		}