Skip to contentSkip to conversation

clk: gpio: fix memory leak

PATCH Applied Sudip Mukherjee 2 participants 2 messages Dec 23, 2015 – Jan 1, 2016 Common clk

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: gpio: fix memory leak

If we fail to allocate parent_name then we are returning but we missed freeing data which has already been allocated.

---
 drivers/clk/clk-gpio.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/clk-gpio.c +3 -1
index 335322d..c1baa89 100644
@@ -294,8 +294,10 @@ static void __init of_gpio_clk_setup(struct device_node *node,
 	num_parents = of_clk_get_parent_count(node);
 
 	parent_names = kcalloc(num_parents, sizeof(char *), GFP_KERNEL);
-	if (!parent_names)
+	if (!parent_names) {
+		kfree(data);
 		return;
+	}
 
 	for (i = 0; i < num_parents; i++)
 		parent_names[i] = of_clk_get_parent_name(node, i);
Signature · 1 line
1.9.1
#1 lore raw

Quoting Sudip Mukherjee (2015-12-22 22:33:59)

Quoted 5 lines

If we fail to allocate parent_name then we are returning but we missed freeing data which has already been allocated.
=

Applied.

Thanks,
Mike

drivers/clk/clk-gpio.c static void __init of_gpio_clk_setup(struct device_n=

Quoted 10 lines
---
 drivers/clk/clk-gpio.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

=

drivers/clk/clk-gpio.c +0 -0
index 335322d..c1baa89 100644
@@ -294,8 +294,10 @@ static void __init of_gpio_clk_setup(struct device_n=

ode *node,

Quoted 17 lines
drivers/clk/clk-gpio.c +3 -1
        num_parents =3D of_clk_get_parent_count(node);
 =
 
        parent_names =3D kcalloc(num_parents, sizeof(char *), GFP_KERNEL);
-       if (!parent_names)
+       if (!parent_names) {
+               kfree(data);
                return;
+       }
 =
 
        for (i =3D 0; i < num_parents; i++)
                parent_names[i] =3D of_clk_get_parent_name(node, i);

-- =

1.9.1
=20