Commit 78ca95c7 authored by Chen-Yu Tsai's avatar Chen-Yu Tsai Committed by Maxime Ripard

clk: sunxi: factors: Add clk cleanup in sunxi_factors_register() error path

sunxi_factors_register() does not check for failures or cleanup after
clk_register_composite() or other clk-related calls.
Signed-off-by: default avatarChen-Yu Tsai <wens@csie.org>
Signed-off-by: default avatarMaxime Ripard <maxime.ripard@free-electrons.com>
parent b3e919e0
...@@ -172,7 +172,7 @@ struct clk *sunxi_factors_register(struct device_node *node, ...@@ -172,7 +172,7 @@ struct clk *sunxi_factors_register(struct device_node *node,
struct clk_hw *mux_hw = NULL; struct clk_hw *mux_hw = NULL;
const char *clk_name = node->name; const char *clk_name = node->name;
const char *parents[FACTORS_MAX_PARENTS]; const char *parents[FACTORS_MAX_PARENTS];
int i = 0; int ret, i = 0;
/* if we have a mux, we will have >1 parents */ /* if we have a mux, we will have >1 parents */
i = of_clk_parent_fill(node, parents, FACTORS_MAX_PARENTS); i = of_clk_parent_fill(node, parents, FACTORS_MAX_PARENTS);
...@@ -188,7 +188,7 @@ struct clk *sunxi_factors_register(struct device_node *node, ...@@ -188,7 +188,7 @@ struct clk *sunxi_factors_register(struct device_node *node,
factors = kzalloc(sizeof(struct clk_factors), GFP_KERNEL); factors = kzalloc(sizeof(struct clk_factors), GFP_KERNEL);
if (!factors) if (!factors)
return NULL; goto err_factors;
/* set up factors properties */ /* set up factors properties */
factors->reg = reg; factors->reg = reg;
...@@ -199,10 +199,8 @@ struct clk *sunxi_factors_register(struct device_node *node, ...@@ -199,10 +199,8 @@ struct clk *sunxi_factors_register(struct device_node *node,
/* Add a gate if this factor clock can be gated */ /* Add a gate if this factor clock can be gated */
if (data->enable) { if (data->enable) {
gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL); gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
if (!gate) { if (!gate)
kfree(factors); goto err_gate;
return NULL;
}
/* set up gate properties */ /* set up gate properties */
gate->reg = reg; gate->reg = reg;
...@@ -214,11 +212,8 @@ struct clk *sunxi_factors_register(struct device_node *node, ...@@ -214,11 +212,8 @@ struct clk *sunxi_factors_register(struct device_node *node,
/* Add a mux if this factor clock can be muxed */ /* Add a mux if this factor clock can be muxed */
if (data->mux) { if (data->mux) {
mux = kzalloc(sizeof(struct clk_mux), GFP_KERNEL); mux = kzalloc(sizeof(struct clk_mux), GFP_KERNEL);
if (!mux) { if (!mux)
kfree(factors); goto err_mux;
kfree(gate);
return NULL;
}
/* set up gate properties */ /* set up gate properties */
mux->reg = reg; mux->reg = reg;
...@@ -233,11 +228,30 @@ struct clk *sunxi_factors_register(struct device_node *node, ...@@ -233,11 +228,30 @@ struct clk *sunxi_factors_register(struct device_node *node,
mux_hw, &clk_mux_ops, mux_hw, &clk_mux_ops,
&factors->hw, &clk_factors_ops, &factors->hw, &clk_factors_ops,
gate_hw, &clk_gate_ops, 0); gate_hw, &clk_gate_ops, 0);
if (IS_ERR(clk))
goto err_register;
if (!IS_ERR(clk)) { ret = of_clk_add_provider(node, of_clk_src_simple_get, clk);
of_clk_add_provider(node, of_clk_src_simple_get, clk); if (ret)
clk_register_clkdev(clk, clk_name, NULL); goto err_provider;
}
ret = clk_register_clkdev(clk, clk_name, NULL);
if (ret)
goto err_clkdev;
return clk; return clk;
err_clkdev:
of_clk_del_provider(node);
err_provider:
/* TODO: The composite clock stuff will leak a bit here. */
clk_unregister(clk);
err_register:
kfree(mux);
err_mux:
kfree(gate);
err_gate:
kfree(factors);
err_factors:
return NULL;
} }
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