Commit 1295e36a authored by Stephen Boyd's avatar Stephen Boyd

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: default avatarMaxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: default avatarStephen Boyd <sboyd@codeaurora.org>
parent d3781a74
...@@ -33,7 +33,7 @@ static DEFINE_SPINLOCK(sun8i_a23_mbus_lock); ...@@ -33,7 +33,7 @@ static DEFINE_SPINLOCK(sun8i_a23_mbus_lock);
static void __init sun8i_a23_mbus_setup(struct device_node *node) static void __init sun8i_a23_mbus_setup(struct device_node *node)
{ {
int num_parents = of_clk_get_parent_count(node); int num_parents = of_clk_get_parent_count(node);
const char *parents[num_parents]; const char **parents;
const char *clk_name = node->name; const char *clk_name = node->name;
struct resource res; struct resource res;
struct clk_divider *div; struct clk_divider *div;
...@@ -43,10 +43,14 @@ static void __init sun8i_a23_mbus_setup(struct device_node *node) ...@@ -43,10 +43,14 @@ static void __init sun8i_a23_mbus_setup(struct device_node *node)
void __iomem *reg; void __iomem *reg;
int err; int err;
parents = kcalloc(num_parents, sizeof(*parents), GFP_KERNEL);
if (!parents)
return;
reg = of_io_request_and_map(node, 0, of_node_full_name(node)); reg = of_io_request_and_map(node, 0, of_node_full_name(node));
if (!reg) { if (!reg) {
pr_err("Could not get registers for sun8i-mbus-clk\n"); pr_err("Could not get registers for sun8i-mbus-clk\n");
return; goto err_free_parents;
} }
div = kzalloc(sizeof(*div), GFP_KERNEL); div = kzalloc(sizeof(*div), GFP_KERNEL);
...@@ -90,6 +94,7 @@ static void __init sun8i_a23_mbus_setup(struct device_node *node) ...@@ -90,6 +94,7 @@ static void __init sun8i_a23_mbus_setup(struct device_node *node)
if (err) if (err)
goto err_unregister_clk; goto err_unregister_clk;
kfree(parents); /* parents is deep copied */
/* The MBUS clocks needs to be always enabled */ /* The MBUS clocks needs to be always enabled */
__clk_get(clk); __clk_get(clk);
clk_prepare_enable(clk); clk_prepare_enable(clk);
...@@ -109,5 +114,7 @@ static void __init sun8i_a23_mbus_setup(struct device_node *node) ...@@ -109,5 +114,7 @@ static void __init sun8i_a23_mbus_setup(struct device_node *node)
iounmap(reg); iounmap(reg);
of_address_to_resource(node, 0, &res); of_address_to_resource(node, 0, &res);
release_mem_region(res.start, resource_size(&res)); release_mem_region(res.start, resource_size(&res));
err_free_parents:
kfree(parents);
} }
CLK_OF_DECLARE(sun8i_a23_mbus, "allwinner,sun8i-a23-mbus-clk", sun8i_a23_mbus_setup); CLK_OF_DECLARE(sun8i_a23_mbus, "allwinner,sun8i-a23-mbus-clk", sun8i_a23_mbus_setup);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment