* [PATCH v3 0/2] fix memory leak and unregister issue in clk_boston_setup()
@ 2018-10-31 7:41 Yi Wang
2018-10-31 7:41 ` [PATCH v3 1/2] clk: boston: fix possible memory leak " Yi Wang
2018-10-31 7:41 ` [PATCH v3 2/2] clk: boston: unregister clks on failure " Yi Wang
0 siblings, 2 replies; 5+ messages in thread
From: Yi Wang @ 2018-10-31 7:41 UTC (permalink / raw)
To: paul.burton, sboyd
Cc: mturquette, linux-mips, linux-clk, linux-kernel, zhong.weidong, Yi Wang
This fix two issues in clk_boston_setup() function:
- possible memory leak of 'onecell'
- registered clks not unregister when error happens
Changes from v2:
- include smatch to the commit
- unregister clks which registered before going out
Yi Wang (2):
clk: boston: fix possible memory leak in clk_boston_setup()
clk: boston: unregister clks on failure in clk_boston_setup()
drivers/clk/imgtec/clk-boston.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
--
1.8.3.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 1/2] clk: boston: fix possible memory leak in clk_boston_setup()
2018-10-31 7:41 [PATCH v3 0/2] fix memory leak and unregister issue in clk_boston_setup() Yi Wang
@ 2018-10-31 7:41 ` Yi Wang
2018-11-08 18:19 ` Stephen Boyd
2018-10-31 7:41 ` [PATCH v3 2/2] clk: boston: unregister clks on failure " Yi Wang
1 sibling, 1 reply; 5+ messages in thread
From: Yi Wang @ 2018-10-31 7:41 UTC (permalink / raw)
To: paul.burton, sboyd
Cc: mturquette, linux-mips, linux-clk, linux-kernel, zhong.weidong, Yi Wang
Smatch report warnings:
drivers/clk/imgtec/clk-boston.c:76 clk_boston_setup() warn: possible memory leak of 'onecell'
drivers/clk/imgtec/clk-boston.c:83 clk_boston_setup() warn: possible memory leak of 'onecell'
drivers/clk/imgtec/clk-boston.c:90 clk_boston_setup() warn: possible memory leak of 'onecell'
'onecell' is malloced in clk_boston_setup(), but not be freed
before leaving from the error handling cases.
Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
---
drivers/clk/imgtec/clk-boston.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/clk/imgtec/clk-boston.c b/drivers/clk/imgtec/clk-boston.c
index 15af423..f5d54a6 100644
--- a/drivers/clk/imgtec/clk-boston.c
+++ b/drivers/clk/imgtec/clk-boston.c
@@ -73,27 +73,32 @@ static void __init clk_boston_setup(struct device_node *np)
hw = clk_hw_register_fixed_rate(NULL, "input", NULL, 0, in_freq);
if (IS_ERR(hw)) {
pr_err("failed to register input clock: %ld\n", PTR_ERR(hw));
- return;
+ goto error;
}
onecell->hws[BOSTON_CLK_INPUT] = hw;
hw = clk_hw_register_fixed_rate(NULL, "sys", "input", 0, sys_freq);
if (IS_ERR(hw)) {
pr_err("failed to register sys clock: %ld\n", PTR_ERR(hw));
- return;
+ goto error;
}
onecell->hws[BOSTON_CLK_SYS] = hw;
hw = clk_hw_register_fixed_rate(NULL, "cpu", "input", 0, cpu_freq);
if (IS_ERR(hw)) {
pr_err("failed to register cpu clock: %ld\n", PTR_ERR(hw));
- return;
+ goto error;
}
onecell->hws[BOSTON_CLK_CPU] = hw;
err = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, onecell);
if (err)
pr_err("failed to add DT provider: %d\n", err);
+
+ return;
+
+error:
+ kfree(onecell);
}
/*
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 2/2] clk: boston: unregister clks on failure in clk_boston_setup()
2018-10-31 7:41 [PATCH v3 0/2] fix memory leak and unregister issue in clk_boston_setup() Yi Wang
2018-10-31 7:41 ` [PATCH v3 1/2] clk: boston: fix possible memory leak " Yi Wang
@ 2018-10-31 7:41 ` Yi Wang
2018-11-08 18:19 ` Stephen Boyd
1 sibling, 1 reply; 5+ messages in thread
From: Yi Wang @ 2018-10-31 7:41 UTC (permalink / raw)
To: paul.burton, sboyd
Cc: mturquette, linux-mips, linux-clk, linux-kernel, zhong.weidong, Yi Wang
The registered clks should unregister when something wrong happens
before going out in function clk_boston_setup().
Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
---
drivers/clk/imgtec/clk-boston.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/clk/imgtec/clk-boston.c b/drivers/clk/imgtec/clk-boston.c
index f5d54a6..dddda45 100644
--- a/drivers/clk/imgtec/clk-boston.c
+++ b/drivers/clk/imgtec/clk-boston.c
@@ -73,31 +73,39 @@ static void __init clk_boston_setup(struct device_node *np)
hw = clk_hw_register_fixed_rate(NULL, "input", NULL, 0, in_freq);
if (IS_ERR(hw)) {
pr_err("failed to register input clock: %ld\n", PTR_ERR(hw));
- goto error;
+ goto fail_input;
}
onecell->hws[BOSTON_CLK_INPUT] = hw;
hw = clk_hw_register_fixed_rate(NULL, "sys", "input", 0, sys_freq);
if (IS_ERR(hw)) {
pr_err("failed to register sys clock: %ld\n", PTR_ERR(hw));
- goto error;
+ goto fail_sys;
}
onecell->hws[BOSTON_CLK_SYS] = hw;
hw = clk_hw_register_fixed_rate(NULL, "cpu", "input", 0, cpu_freq);
if (IS_ERR(hw)) {
pr_err("failed to register cpu clock: %ld\n", PTR_ERR(hw));
- goto error;
+ goto fail_cpu;
}
onecell->hws[BOSTON_CLK_CPU] = hw;
err = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, onecell);
- if (err)
+ if (err) {
pr_err("failed to add DT provider: %d\n", err);
+ goto fail_clk_add;
+ }
return;
-error:
+fail_clk_add:
+ clk_hw_unregister_fixed_rate(onecell->hws[BOSTON_CLK_CPU]);
+fail_cpu:
+ clk_hw_unregister_fixed_rate(onecell->hws[BOSTON_CLK_SYS]);
+fail_sys:
+ clk_hw_unregister_fixed_rate(onecell->hws[BOSTON_CLK_INPUT]);
+fail_input:
kfree(onecell);
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/2] clk: boston: fix possible memory leak in clk_boston_setup()
2018-10-31 7:41 ` [PATCH v3 1/2] clk: boston: fix possible memory leak " Yi Wang
@ 2018-11-08 18:19 ` Stephen Boyd
0 siblings, 0 replies; 5+ messages in thread
From: Stephen Boyd @ 2018-11-08 18:19 UTC (permalink / raw)
To: Yi Wang, paul.burton
Cc: mturquette, linux-mips, linux-clk, linux-kernel, zhong.weidong, Yi Wang
Quoting Yi Wang (2018-10-31 00:41:41)
> Smatch report warnings:
> drivers/clk/imgtec/clk-boston.c:76 clk_boston_setup() warn: possible memory leak of 'onecell'
> drivers/clk/imgtec/clk-boston.c:83 clk_boston_setup() warn: possible memory leak of 'onecell'
> drivers/clk/imgtec/clk-boston.c:90 clk_boston_setup() warn: possible memory leak of 'onecell'
>
> 'onecell' is malloced in clk_boston_setup(), but not be freed
> before leaving from the error handling cases.
>
> Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
> ---
Applied to clk-next
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 2/2] clk: boston: unregister clks on failure in clk_boston_setup()
2018-10-31 7:41 ` [PATCH v3 2/2] clk: boston: unregister clks on failure " Yi Wang
@ 2018-11-08 18:19 ` Stephen Boyd
0 siblings, 0 replies; 5+ messages in thread
From: Stephen Boyd @ 2018-11-08 18:19 UTC (permalink / raw)
To: Yi Wang, paul.burton
Cc: mturquette, linux-mips, linux-clk, linux-kernel, zhong.weidong, Yi Wang
Quoting Yi Wang (2018-10-31 00:41:42)
> The registered clks should unregister when something wrong happens
> before going out in function clk_boston_setup().
>
> Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
> ---
Applied to clk-next
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-11-08 18:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-31 7:41 [PATCH v3 0/2] fix memory leak and unregister issue in clk_boston_setup() Yi Wang
2018-10-31 7:41 ` [PATCH v3 1/2] clk: boston: fix possible memory leak " Yi Wang
2018-11-08 18:19 ` Stephen Boyd
2018-10-31 7:41 ` [PATCH v3 2/2] clk: boston: unregister clks on failure " Yi Wang
2018-11-08 18:19 ` Stephen Boyd
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).