99b0db892d07a40599cd696fd5259076aab3ed58
[openwrt/svn-archive/archive.git] / target / linux / sunxi / patches-3.13 / 104-clk-sunxi-fix-memory-leak.patch
1 From 9dc8189536f4c59bb7ad8c736021cefc1488bf74 Mon Sep 17 00:00:00 2001
2 From: "Victor N. Ramos Mello" <victornrm@gmail.com>
3 Date: Fri, 18 Oct 2013 20:27:51 -0300
4 Subject: [PATCH] drivers: clk: sunxi: Fix memory leakage in clk-sunxi.c
5
6 Fix a possible memory leak in sun4i_osc_clk_setup().
7 Moved clock-frequency check to save superfluous allocation.
8
9 Signed-off-by: Victor N. Ramos Mello <victornrm@gmail.com>
10 Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
11 ---
12 drivers/clk/sunxi/clk-sunxi.c | 28 +++++++++++++++++-----------
13 1 file changed, 17 insertions(+), 11 deletions(-)
14
15 diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c
16 index 8fc1375..492ef0e 100644
17 --- a/drivers/clk/sunxi/clk-sunxi.c
18 +++ b/drivers/clk/sunxi/clk-sunxi.c
19 @@ -37,18 +37,16 @@ static void __init sun4i_osc_clk_setup(struct device_node *node)
20 const char *clk_name = node->name;
21 u32 rate;
22
23 + if (of_property_read_u32(node, "clock-frequency", &rate))
24 + return;
25 +
26 /* allocate fixed-rate and gate clock structs */
27 fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
28 if (!fixed)
29 return;
30 gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
31 - if (!gate) {
32 - kfree(fixed);
33 - return;
34 - }
35 -
36 - if (of_property_read_u32(node, "clock-frequency", &rate))
37 - return;
38 + if (!gate)
39 + goto err_free_fixed;
40
41 /* set up gate and fixed rate properties */
42 gate->reg = of_iomap(node, 0);
43 @@ -63,10 +61,18 @@ static void __init sun4i_osc_clk_setup(struct device_node *node)
44 &gate->hw, &clk_gate_ops,
45 CLK_IS_ROOT);
46
47 - if (!IS_ERR(clk)) {
48 - of_clk_add_provider(node, of_clk_src_simple_get, clk);
49 - clk_register_clkdev(clk, clk_name, NULL);
50 - }
51 + if (IS_ERR(clk))
52 + goto err_free_gate;
53 +
54 + of_clk_add_provider(node, of_clk_src_simple_get, clk);
55 + clk_register_clkdev(clk, clk_name, NULL);
56 +
57 + return;
58 +
59 +err_free_gate:
60 + kfree(gate);
61 +err_free_fixed:
62 + kfree(fixed);
63 }
64 CLK_OF_DECLARE(sun4i_osc, "allwinner,sun4i-osc-clk", sun4i_osc_clk_setup);
65
66 --
67 1.8.5.1
68