* [PATCH] clk: rockchip: Free the memory on the error path
@ 2018-02-28 6:56 Shawn Lin
2018-03-02 7:53 ` Heiko Stuebner
0 siblings, 1 reply; 2+ messages in thread
From: Shawn Lin @ 2018-02-28 6:56 UTC (permalink / raw)
To: Heiko Stuebner, Michael Turquette, Stephen Boyd; +Cc: linux-clk, Shawn Lin
rockchip_clk_register_branch() and rockchip_clk_register_branch()
should free the memory internally when seeing any failure.
Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---
drivers/clk/rockchip/clk.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/drivers/clk/rockchip/clk.c b/drivers/clk/rockchip/clk.c
index 35dbd63..3cd8ad5 100644
--- a/drivers/clk/rockchip/clk.c
+++ b/drivers/clk/rockchip/clk.c
@@ -57,6 +57,7 @@ static struct clk *rockchip_clk_register_branch(const char *name,
struct clk_divider *div = NULL;
const struct clk_ops *mux_ops = NULL, *div_ops = NULL,
*gate_ops = NULL;
+ int ret;
if (num_parents > 1) {
mux = kzalloc(sizeof(*mux), GFP_KERNEL);
@@ -74,8 +75,10 @@ static struct clk *rockchip_clk_register_branch(const char *name,
if (gate_offset >= 0) {
gate = kzalloc(sizeof(*gate), GFP_KERNEL);
- if (!gate)
+ if (!gate) {
+ ret = -ENOMEM;
goto err_gate;
+ }
gate->flags = gate_flags;
gate->reg = base + gate_offset;
@@ -86,8 +89,10 @@ static struct clk *rockchip_clk_register_branch(const char *name,
if (div_width > 0) {
div = kzalloc(sizeof(*div), GFP_KERNEL);
- if (!div)
+ if (!div) {
+ ret = -ENOMEM;
goto err_div;
+ }
div->flags = div_flags;
div->reg = base + muxdiv_offset;
@@ -106,12 +111,19 @@ static struct clk *rockchip_clk_register_branch(const char *name,
gate ? &gate->hw : NULL, gate_ops,
flags);
+ if (IS_ERR(clk)) {
+ ret = PTR_ERR(clk);
+ goto err_composite;
+ }
+
return clk;
+err_composite:
+ kfree(div);
err_div:
kfree(gate);
err_gate:
kfree(mux);
- return ERR_PTR(-ENOMEM);
+ return ERR_PTR(ret);
}
struct rockchip_clk_frac {
@@ -291,8 +303,10 @@ static struct clk *rockchip_clk_register_frac_branch(
init.num_parents = child->num_parents;
mux_clk = clk_register(NULL, &frac_mux->hw);
- if (IS_ERR(mux_clk))
+ if (IS_ERR(mux_clk)) {
+ kfree(frac);
return clk;
+ }
rockchip_clk_add_lookup(ctx, mux_clk, child->id);
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] clk: rockchip: Free the memory on the error path
2018-02-28 6:56 [PATCH] clk: rockchip: Free the memory on the error path Shawn Lin
@ 2018-03-02 7:53 ` Heiko Stuebner
0 siblings, 0 replies; 2+ messages in thread
From: Heiko Stuebner @ 2018-03-02 7:53 UTC (permalink / raw)
To: Shawn Lin; +Cc: Michael Turquette, Stephen Boyd, linux-clk
Am Mittwoch, 28. Februar 2018, 07:56:48 CET schrieb Shawn Lin:
> rockchip_clk_register_branch() and rockchip_clk_register_branch()
> should free the memory internally when seeing any failure.
>
> Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
applied for 4.17
Thanks
Heiko
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-03-02 7:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-28 6:56 [PATCH] clk: rockchip: Free the memory on the error path Shawn Lin
2018-03-02 7:53 ` Heiko Stuebner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox