Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: sunxi: Remove use of variable length array

Using an array allocated on the stack may lead to stack overflows
and other problems so let's move the allocation to the heap
instead. This silences the following checker warning as well.

drivers/clk/sunxi/clk-sun8i-mbus.c:36:29: warning: Variable length array is used

Cc: Chen-Yu Tsai <wens@csie.org>
Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

+9 -2
+9 -2
drivers/clk/sunxi/clk-sun8i-mbus.c
··· 33 33 static void __init sun8i_a23_mbus_setup(struct device_node *node) 34 34 { 35 35 int num_parents = of_clk_get_parent_count(node); 36 - const char *parents[num_parents]; 36 + const char **parents; 37 37 const char *clk_name = node->name; 38 38 struct resource res; 39 39 struct clk_divider *div; ··· 43 43 void __iomem *reg; 44 44 int err; 45 45 46 + parents = kcalloc(num_parents, sizeof(*parents), GFP_KERNEL); 47 + if (!parents) 48 + return; 49 + 46 50 reg = of_io_request_and_map(node, 0, of_node_full_name(node)); 47 51 if (!reg) { 48 52 pr_err("Could not get registers for sun8i-mbus-clk\n"); 49 - return; 53 + goto err_free_parents; 50 54 } 51 55 52 56 div = kzalloc(sizeof(*div), GFP_KERNEL); ··· 94 90 if (err) 95 91 goto err_unregister_clk; 96 92 93 + kfree(parents); /* parents is deep copied */ 97 94 /* The MBUS clocks needs to be always enabled */ 98 95 __clk_get(clk); 99 96 clk_prepare_enable(clk); ··· 114 109 iounmap(reg); 115 110 of_address_to_resource(node, 0, &res); 116 111 release_mem_region(res.start, resource_size(&res)); 112 + err_free_parents: 113 + kfree(parents); 117 114 } 118 115 CLK_OF_DECLARE(sun8i_a23_mbus, "allwinner,sun8i-a23-mbus-clk", sun8i_a23_mbus_setup);