clk: iproc: fix memory leak from clock name

of_property_read_string_index takes array of pointers and assign them to
strings read from device tree property. No additional memory allocation
is needed prior to calling of_property_read_string_index. In fact, since
the array of pointers will be re-assigned to other strings, any memory
that it points to prior to calling of_property_read_string_index will be
leaked

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Ray Jui <rjui@broadcom.com>
Fixes: 5fe225c105 ("clk: iproc: add initial common clock support")
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
This commit is contained in:
Ray Jui 2015-06-29 14:30:09 -07:00 committed by Stephen Boyd
parent 358bdf892f
commit 45a481c217
2 changed files with 2 additions and 12 deletions

View File

@ -222,10 +222,6 @@ void __init iproc_asiu_setup(struct device_node *node,
struct iproc_asiu_clk *asiu_clk; struct iproc_asiu_clk *asiu_clk;
const char *clk_name; const char *clk_name;
clk_name = kzalloc(IPROC_CLK_NAME_LEN, GFP_KERNEL);
if (WARN_ON(!clk_name))
goto err_clk_register;
ret = of_property_read_string_index(node, "clock-output-names", ret = of_property_read_string_index(node, "clock-output-names",
i, &clk_name); i, &clk_name);
if (WARN_ON(ret)) if (WARN_ON(ret))
@ -259,7 +255,7 @@ void __init iproc_asiu_setup(struct device_node *node,
err_clk_register: err_clk_register:
for (i = 0; i < num_clks; i++) for (i = 0; i < num_clks; i++)
kfree(asiu->clks[i].name); clk_unregister(asiu->clk_data.clks[i]);
iounmap(asiu->gate_base); iounmap(asiu->gate_base);
err_iomap_gate: err_iomap_gate:

View File

@ -655,10 +655,6 @@ void __init iproc_pll_clk_setup(struct device_node *node,
memset(&init, 0, sizeof(init)); memset(&init, 0, sizeof(init));
parent_name = node->name; parent_name = node->name;
clk_name = kzalloc(IPROC_CLK_NAME_LEN, GFP_KERNEL);
if (WARN_ON(!clk_name))
goto err_clk_register;
ret = of_property_read_string_index(node, "clock-output-names", ret = of_property_read_string_index(node, "clock-output-names",
i, &clk_name); i, &clk_name);
if (WARN_ON(ret)) if (WARN_ON(ret))
@ -690,10 +686,8 @@ void __init iproc_pll_clk_setup(struct device_node *node,
return; return;
err_clk_register: err_clk_register:
for (i = 0; i < num_clks; i++) { for (i = 0; i < num_clks; i++)
kfree(pll->clks[i].name);
clk_unregister(pll->clk_data.clks[i]); clk_unregister(pll->clk_data.clks[i]);
}
err_pll_register: err_pll_register:
if (pll->asiu_base) if (pll->asiu_base)