drivers: clk: sunxi: Fix memory leakage in clk-sunxi.c
Fix a possible memory leak in sun4i_osc_clk_setup(). Moved clock-frequency check to save superfluous allocation. Signed-off-by: Victor N. Ramos Mello <victornrm@gmail.com> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
This commit is contained in:
committed by
Maxime Ripard
parent
8e6a4c40bb
commit
e71c69fc33
@@ -38,18 +38,16 @@ static void __init sun4i_osc_clk_setup(struct device_node *node)
|
|||||||
const char *clk_name = node->name;
|
const char *clk_name = node->name;
|
||||||
u32 rate;
|
u32 rate;
|
||||||
|
|
||||||
|
if (of_property_read_u32(node, "clock-frequency", &rate))
|
||||||
|
return;
|
||||||
|
|
||||||
/* allocate fixed-rate and gate clock structs */
|
/* allocate fixed-rate and gate clock structs */
|
||||||
fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
|
fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
|
||||||
if (!fixed)
|
if (!fixed)
|
||||||
return;
|
return;
|
||||||
gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
|
gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
|
||||||
if (!gate) {
|
if (!gate)
|
||||||
kfree(fixed);
|
goto err_free_fixed;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (of_property_read_u32(node, "clock-frequency", &rate))
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* set up gate and fixed rate properties */
|
/* set up gate and fixed rate properties */
|
||||||
gate->reg = of_iomap(node, 0);
|
gate->reg = of_iomap(node, 0);
|
||||||
@@ -64,10 +62,18 @@ static void __init sun4i_osc_clk_setup(struct device_node *node)
|
|||||||
&gate->hw, &clk_gate_ops,
|
&gate->hw, &clk_gate_ops,
|
||||||
CLK_IS_ROOT);
|
CLK_IS_ROOT);
|
||||||
|
|
||||||
if (!IS_ERR(clk)) {
|
if (IS_ERR(clk))
|
||||||
of_clk_add_provider(node, of_clk_src_simple_get, clk);
|
goto err_free_gate;
|
||||||
clk_register_clkdev(clk, clk_name, NULL);
|
|
||||||
}
|
of_clk_add_provider(node, of_clk_src_simple_get, clk);
|
||||||
|
clk_register_clkdev(clk, clk_name, NULL);
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
err_free_gate:
|
||||||
|
kfree(gate);
|
||||||
|
err_free_fixed:
|
||||||
|
kfree(fixed);
|
||||||
}
|
}
|
||||||
CLK_OF_DECLARE(sun4i_osc, "allwinner,sun4i-osc-clk", sun4i_osc_clk_setup);
|
CLK_OF_DECLARE(sun4i_osc, "allwinner,sun4i-osc-clk", sun4i_osc_clk_setup);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user