aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor N. Ramos Mello <victornrm@gmail.com>2013-10-18 19:27:51 -0400
committerMaxime Ripard <maxime.ripard@free-electrons.com>2013-11-10 05:40:51 -0500
commite71c69fc3362b88b09194d486dda6d721a8004f6 (patch)
tree8a58c691ed3fdbfb1643171bd5468dbe6fec5dae
parent8e6a4c40bb6f3866548811f9f3882a627293fc2f (diff)
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>
-rw-r--r--drivers/clk/sunxi/clk-sunxi.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c
index 83d3eace3ebc..9665cb8d0238 100644
--- a/drivers/clk/sunxi/clk-sunxi.c
+++ b/drivers/clk/sunxi/clk-sunxi.c
@@ -38,18 +38,16 @@ static void __init sun4i_osc_clk_setup(struct device_node *node)
38 const char *clk_name = node->name; 38 const char *clk_name = node->name;
39 u32 rate; 39 u32 rate;
40 40
41 if (of_property_read_u32(node, "clock-frequency", &rate))
42 return;
43
41 /* allocate fixed-rate and gate clock structs */ 44 /* allocate fixed-rate and gate clock structs */
42 fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL); 45 fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
43 if (!fixed) 46 if (!fixed)
44 return; 47 return;
45 gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL); 48 gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
46 if (!gate) { 49 if (!gate)
47 kfree(fixed); 50 goto err_free_fixed;
48 return;
49 }
50
51 if (of_property_read_u32(node, "clock-frequency", &rate))
52 return;
53 51
54 /* set up gate and fixed rate properties */ 52 /* set up gate and fixed rate properties */
55 gate->reg = of_iomap(node, 0); 53 gate->reg = of_iomap(node, 0);
@@ -64,10 +62,18 @@ static void __init sun4i_osc_clk_setup(struct device_node *node)
64 &gate->hw, &clk_gate_ops, 62 &gate->hw, &clk_gate_ops,
65 CLK_IS_ROOT); 63 CLK_IS_ROOT);
66 64
67 if (!IS_ERR(clk)) { 65 if (IS_ERR(clk))
68 of_clk_add_provider(node, of_clk_src_simple_get, clk); 66 goto err_free_gate;
69 clk_register_clkdev(clk, clk_name, NULL); 67
70 } 68 of_clk_add_provider(node, of_clk_src_simple_get, clk);
69 clk_register_clkdev(clk, clk_name, NULL);
70
71 return;
72
73err_free_gate:
74 kfree(gate);
75err_free_fixed:
76 kfree(fixed);
71} 77}
72CLK_OF_DECLARE(sun4i_osc, "allwinner,sun4i-osc-clk", sun4i_osc_clk_setup); 78CLK_OF_DECLARE(sun4i_osc, "allwinner,sun4i-osc-clk", sun4i_osc_clk_setup);
73 79