Skip to contentSkip to conversation

ti: fix possible memory leak in _ti_omap4_clkctrl_setup

PATCH Superseded Hangyu Hua 2 participants 3 messages Oct 25, 2023 – Oct 27, 2023

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Hangyu Hua

author
#0 lore raw

PATCH 1/1 ti: fix possible memory leak in _ti_omap4_clkctrl_setup

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()")
---
 drivers/clk/ti/clkctrl.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clk/ti/clkctrl.c +1 -0
index 607e34d8e289..cb4aa8a45bb2 100644
@@ -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;
 		}
Signature · 1 line
2.34.1
#1 lore raw
Quoted 1 line · Hangyu Hua

kstrndup and kstrdup_and_replace in clkctrl_get_name can perform

kstrndup()
kstrdup_and_replace()
clkctrl_get_name()

Quoted 2 lines

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

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#2 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 1 line · Hangyu Hua

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

Quoted 3 lines
Quoted 2 lines

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