upgrade 3.13 targets to 3.13.2, refresh patches
[openwrt.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 --- a/drivers/clk/sunxi/clk-sunxi.c
16 +++ b/drivers/clk/sunxi/clk-sunxi.c
17 @@ -37,18 +37,16 @@ static void __init sun4i_osc_clk_setup(s
18         const char *clk_name = node->name;
19         u32 rate;
20  
21 +       if (of_property_read_u32(node, "clock-frequency", &rate))
22 +               return;
23 +
24         /* allocate fixed-rate and gate clock structs */
25         fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
26         if (!fixed)
27                 return;
28         gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
29 -       if (!gate) {
30 -               kfree(fixed);
31 -               return;
32 -       }
33 -
34 -       if (of_property_read_u32(node, "clock-frequency", &rate))
35 -               return;
36 +       if (!gate)
37 +               goto err_free_fixed;
38  
39         /* set up gate and fixed rate properties */
40         gate->reg = of_iomap(node, 0);
41 @@ -63,10 +61,18 @@ static void __init sun4i_osc_clk_setup(s
42                         &gate->hw, &clk_gate_ops,
43                         CLK_IS_ROOT);
44  
45 -       if (!IS_ERR(clk)) {
46 -               of_clk_add_provider(node, of_clk_src_simple_get, clk);
47 -               clk_register_clkdev(clk, clk_name, NULL);
48 -       }
49 +       if (IS_ERR(clk))
50 +               goto err_free_gate;
51 +
52 +       of_clk_add_provider(node, of_clk_src_simple_get, clk);
53 +       clk_register_clkdev(clk, clk_name, NULL);
54 +
55 +       return;
56 +
57 +err_free_gate:
58 +       kfree(gate);
59 +err_free_fixed:
60 +       kfree(fixed);
61  }
62  CLK_OF_DECLARE(sun4i_osc, "allwinner,sun4i-osc-clk", sun4i_osc_clk_setup);
63