Skip to contentSkip to conversation

clk: bcm2835: Fix memory leak in bcm2835_register_pll

PATCH In review Navid Emamdoost 2 participants 2 messages Oct 10, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: bcm2835: Fix memory leak in bcm2835_register_pll

In the implementation of bcm2835_register_pll(), the allocated memory for pll should be released if devm_clk_hw_register() fails.

Fixes b19f009d4510 ("clk: bcm2835: Migrate to clk_hw based registration and OF APIs")
---
 drivers/clk/bcm/clk-bcm2835.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/bcm/clk-bcm2835.c +3 -1
index 802e488fd3c3..99549642110a 100644
@@ -1320,8 +1320,10 @@ static struct clk_hw *bcm2835_register_pll(struct bcm2835_cprman *cprman,
 	pll->hw.init = &init;
 
 	ret = devm_clk_hw_register(cprman->dev, &pll->hw);
-	if (ret)
+	if (ret) {
+		kfree(pll);
 		return NULL;
+	}
 	return &pll->hw;
 }
 
Signature · 1 line
2.17.1
#1 lore raw

Hello,

Quoted 14 lines · CEST Navid Emamdoost

In the implementation of bcm2835_register_pll(), the allocated memory for pll should be released if devm_clk_hw_register() fails.

Fixes b19f009d4510 ("clk: bcm2835: Migrate to clk_hw based registration and OF APIs")
---
 drivers/clk/bcm/clk-bcm2835.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/bcm/clk-bcm2835.c +0 -0
index 802e488fd3c3..99549642110a 100644

drivers/clk/bcm/clk-bcm2835.c static struct clk_hw *bcm2835_register_pll(struct bcm2835_cprman *cprman, · line 1328

Quoted 10 lines
drivers/clk/bcm/clk-bcm2835.c +3 -1
@@ -1320,8 +1320,10 @@ static struct clk_hw *bcm2835_register_pll(struct bcm2835_cprman *cprman,
 	pll->hw.init = &init;
 
 	ret = devm_clk_hw_register(cprman->dev, &pll->hw);
-	if (ret)
+	if (ret) {
+		kfree(pll);
 		return NULL;
+	}
 	return &pll->hw;
 }

Eh, is pll freed at all, even in successful case? I failed to find a corresponding kfree(). The pointer itself is lost once the function returns.
The solution would rather be to use devm_kzalloc instead of kzalloc, like the other clocks in e.g. bcm2835_register_pll()

Best regards,
Alexander