Commit fd3cbbfb authored by Shawn Lin's avatar Shawn Lin Committed by Heiko Stuebner

clk: rockchip: Free the memory on the error path

rockchip_clk_register_branch() and rockchip_clk_register_frac_branch()
should free the memory internally when seeing any failure.
Signed-off-by: default avatarShawn Lin <shawn.lin@rock-chips.com>
Signed-off-by: default avatarHeiko Stuebner <heiko@sntech.de>
parent dd5bdb79
...@@ -57,6 +57,7 @@ static struct clk *rockchip_clk_register_branch(const char *name, ...@@ -57,6 +57,7 @@ static struct clk *rockchip_clk_register_branch(const char *name,
struct clk_divider *div = NULL; struct clk_divider *div = NULL;
const struct clk_ops *mux_ops = NULL, *div_ops = NULL, const struct clk_ops *mux_ops = NULL, *div_ops = NULL,
*gate_ops = NULL; *gate_ops = NULL;
int ret;
if (num_parents > 1) { if (num_parents > 1) {
mux = kzalloc(sizeof(*mux), GFP_KERNEL); mux = kzalloc(sizeof(*mux), GFP_KERNEL);
...@@ -74,8 +75,10 @@ static struct clk *rockchip_clk_register_branch(const char *name, ...@@ -74,8 +75,10 @@ static struct clk *rockchip_clk_register_branch(const char *name,
if (gate_offset >= 0) { if (gate_offset >= 0) {
gate = kzalloc(sizeof(*gate), GFP_KERNEL); gate = kzalloc(sizeof(*gate), GFP_KERNEL);
if (!gate) if (!gate) {
ret = -ENOMEM;
goto err_gate; goto err_gate;
}
gate->flags = gate_flags; gate->flags = gate_flags;
gate->reg = base + gate_offset; gate->reg = base + gate_offset;
...@@ -86,8 +89,10 @@ static struct clk *rockchip_clk_register_branch(const char *name, ...@@ -86,8 +89,10 @@ static struct clk *rockchip_clk_register_branch(const char *name,
if (div_width > 0) { if (div_width > 0) {
div = kzalloc(sizeof(*div), GFP_KERNEL); div = kzalloc(sizeof(*div), GFP_KERNEL);
if (!div) if (!div) {
ret = -ENOMEM;
goto err_div; goto err_div;
}
div->flags = div_flags; div->flags = div_flags;
div->reg = base + muxdiv_offset; div->reg = base + muxdiv_offset;
...@@ -106,12 +111,19 @@ static struct clk *rockchip_clk_register_branch(const char *name, ...@@ -106,12 +111,19 @@ static struct clk *rockchip_clk_register_branch(const char *name,
gate ? &gate->hw : NULL, gate_ops, gate ? &gate->hw : NULL, gate_ops,
flags); flags);
if (IS_ERR(clk)) {
ret = PTR_ERR(clk);
goto err_composite;
}
return clk; return clk;
err_composite:
kfree(div);
err_div: err_div:
kfree(gate); kfree(gate);
err_gate: err_gate:
kfree(mux); kfree(mux);
return ERR_PTR(-ENOMEM); return ERR_PTR(ret);
} }
struct rockchip_clk_frac { struct rockchip_clk_frac {
...@@ -291,8 +303,10 @@ static struct clk *rockchip_clk_register_frac_branch( ...@@ -291,8 +303,10 @@ static struct clk *rockchip_clk_register_frac_branch(
init.num_parents = child->num_parents; init.num_parents = child->num_parents;
mux_clk = clk_register(NULL, &frac_mux->hw); mux_clk = clk_register(NULL, &frac_mux->hw);
if (IS_ERR(mux_clk)) if (IS_ERR(mux_clk)) {
kfree(frac);
return clk; return clk;
}
rockchip_clk_add_lookup(ctx, mux_clk, child->id); rockchip_clk_add_lookup(ctx, mux_clk, child->id);
......
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