* [PATCH] "clocksource/drivers/cadence_ttc: fix memory leak in ttc_setup_clockevent() @ 2020-11-10 1:15 Yu Kuai 2020-11-10 10:04 ` Michal Simek 0 siblings, 1 reply; 9+ messages in thread From: Yu Kuai @ 2020-11-10 1:15 UTC (permalink / raw) To: michal.simek, daniel.lezcano, tglx, soren.brinkmann Cc: linux-arm-kernel, linux-kernel, yukuai3, yi.zhang, zhangxiaoxu5 If clk_notifier_register() failed, ttc_setup_clockevent() will return without freeing 'ttcce', which will leak memory. Fixes: 70504f311d4b ("clocksource/drivers/cadence_ttc: Convert init function to return error") Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Yu Kuai <yukuai3@huawei.com> --- drivers/clocksource/timer-cadence-ttc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/clocksource/timer-cadence-ttc.c b/drivers/clocksource/timer-cadence-ttc.c index 80e960602030..32b9560ce408 100644 --- a/drivers/clocksource/timer-cadence-ttc.c +++ b/drivers/clocksource/timer-cadence-ttc.c @@ -426,6 +426,7 @@ static int __init ttc_setup_clockevent(struct clk *clk, &ttcce->ttc.clk_rate_change_nb); if (err) { pr_warn("Unable to register clock notifier.\n"); + kfree(ttcce); return err; } -- 2.25.4 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] "clocksource/drivers/cadence_ttc: fix memory leak in ttc_setup_clockevent() 2020-11-10 1:15 [PATCH] "clocksource/drivers/cadence_ttc: fix memory leak in ttc_setup_clockevent() Yu Kuai @ 2020-11-10 10:04 ` Michal Simek 2020-11-10 10:07 ` Michal Simek 0 siblings, 1 reply; 9+ messages in thread From: Michal Simek @ 2020-11-10 10:04 UTC (permalink / raw) To: Yu Kuai, michal.simek, daniel.lezcano, tglx, soren.brinkmann Cc: linux-arm-kernel, linux-kernel, yi.zhang, zhangxiaoxu5 On 10. 11. 20 2:15, Yu Kuai wrote: > If clk_notifier_register() failed, ttc_setup_clockevent() will return > without freeing 'ttcce', which will leak memory. > > Fixes: 70504f311d4b ("clocksource/drivers/cadence_ttc: Convert init function to return error") > Reported-by: Hulk Robot <hulkci@huawei.com> > Signed-off-by: Yu Kuai <yukuai3@huawei.com> > --- > drivers/clocksource/timer-cadence-ttc.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/clocksource/timer-cadence-ttc.c b/drivers/clocksource/timer-cadence-ttc.c > index 80e960602030..32b9560ce408 100644 > --- a/drivers/clocksource/timer-cadence-ttc.c > +++ b/drivers/clocksource/timer-cadence-ttc.c > @@ -426,6 +426,7 @@ static int __init ttc_setup_clockevent(struct clk *clk, > &ttcce->ttc.clk_rate_change_nb); > if (err) { > pr_warn("Unable to register clock notifier.\n"); > + kfree(ttcce); > return err; > } > > Reviewed-by: Michal Simek <michal.simek@xilinx.com> Thanks, Michal ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] "clocksource/drivers/cadence_ttc: fix memory leak in ttc_setup_clockevent() 2020-11-10 10:04 ` Michal Simek @ 2020-11-10 10:07 ` Michal Simek 2020-11-11 1:16 ` [PATCH V2] clocksource/drivers/cadence_ttc: " Yu Kuai 0 siblings, 1 reply; 9+ messages in thread From: Michal Simek @ 2020-11-10 10:07 UTC (permalink / raw) To: Michal Simek, Yu Kuai, daniel.lezcano, tglx, soren.brinkmann Cc: linux-arm-kernel, linux-kernel, yi.zhang, zhangxiaoxu5 On 10. 11. 20 11:04, Michal Simek wrote: > > > On 10. 11. 20 2:15, Yu Kuai wrote: >> If clk_notifier_register() failed, ttc_setup_clockevent() will return >> without freeing 'ttcce', which will leak memory. >> >> Fixes: 70504f311d4b ("clocksource/drivers/cadence_ttc: Convert init function to return error") >> Reported-by: Hulk Robot <hulkci@huawei.com> >> Signed-off-by: Yu Kuai <yukuai3@huawei.com> >> --- >> drivers/clocksource/timer-cadence-ttc.c | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/drivers/clocksource/timer-cadence-ttc.c b/drivers/clocksource/timer-cadence-ttc.c >> index 80e960602030..32b9560ce408 100644 >> --- a/drivers/clocksource/timer-cadence-ttc.c >> +++ b/drivers/clocksource/timer-cadence-ttc.c >> @@ -426,6 +426,7 @@ static int __init ttc_setup_clockevent(struct clk *clk, >> &ttcce->ttc.clk_rate_change_nb); >> if (err) { >> pr_warn("Unable to register clock notifier.\n"); >> + kfree(ttcce); >> return err; >> } >> >> > > Reviewed-by: Michal Simek <michal.simek@xilinx.com> One thing I have noticed. Please fix your subject. Remove " from it. Thanks, Michal ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH V2] clocksource/drivers/cadence_ttc: fix memory leak in ttc_setup_clockevent() 2020-11-10 10:07 ` Michal Simek @ 2020-11-11 1:16 ` Yu Kuai 2020-11-12 9:59 ` Daniel Lezcano 0 siblings, 1 reply; 9+ messages in thread From: Yu Kuai @ 2020-11-11 1:16 UTC (permalink / raw) To: michal.simek, daniel.lezcano, tglx, soren.brinkmann Cc: linux-arm-kernel, linux-kernel, yukuai3, yi.zhang, zhangxiaoxu5 If clk_notifier_register() failed, ttc_setup_clockevent() will return without freeing 'ttcce', which will leak memory. Fixes: 70504f311d4b ("clocksource/drivers/cadence_ttc: Convert init function to return error") Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Yu Kuai <yukuai3@huawei.com> Reviewed-by: Michal Simek <michal.simek@xilinx.com> --- drivers/clocksource/timer-cadence-ttc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/clocksource/timer-cadence-ttc.c b/drivers/clocksource/timer-cadence-ttc.c index 80e960602030..32b9560ce408 100644 --- a/drivers/clocksource/timer-cadence-ttc.c +++ b/drivers/clocksource/timer-cadence-ttc.c @@ -426,6 +426,7 @@ static int __init ttc_setup_clockevent(struct clk *clk, &ttcce->ttc.clk_rate_change_nb); if (err) { pr_warn("Unable to register clock notifier.\n"); + kfree(ttcce); return err; } -- 2.25.4 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH V2] clocksource/drivers/cadence_ttc: fix memory leak in ttc_setup_clockevent() 2020-11-11 1:16 ` [PATCH V2] clocksource/drivers/cadence_ttc: " Yu Kuai @ 2020-11-12 9:59 ` Daniel Lezcano 2020-11-16 7:08 ` [PATCH V3] " Yu Kuai 0 siblings, 1 reply; 9+ messages in thread From: Daniel Lezcano @ 2020-11-12 9:59 UTC (permalink / raw) To: Yu Kuai, michal.simek, tglx, soren.brinkmann Cc: linux-arm-kernel, linux-kernel, yi.zhang, zhangxiaoxu5 On 11/11/2020 02:16, Yu Kuai wrote: > If clk_notifier_register() failed, ttc_setup_clockevent() will return > without freeing 'ttcce', which will leak memory. > > Fixes: 70504f311d4b ("clocksource/drivers/cadence_ttc: Convert init function to return error") > Reported-by: Hulk Robot <hulkci@huawei.com> > Signed-off-by: Yu Kuai <yukuai3@huawei.com> > Reviewed-by: Michal Simek <michal.simek@xilinx.com> > --- > drivers/clocksource/timer-cadence-ttc.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/clocksource/timer-cadence-ttc.c b/drivers/clocksource/timer-cadence-ttc.c > index 80e960602030..32b9560ce408 100644 > --- a/drivers/clocksource/timer-cadence-ttc.c > +++ b/drivers/clocksource/timer-cadence-ttc.c > @@ -426,6 +426,7 @@ static int __init ttc_setup_clockevent(struct clk *clk, > &ttcce->ttc.clk_rate_change_nb); > if (err) { > pr_warn("Unable to register clock notifier.\n"); > + kfree(ttcce); > return err; > } Please fix the error path by adding a label (eg. out_kfree) and jump to it in case of error everywhere in the function. out_kfree: kfree(ttcce); return err; -- <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH V3] clocksource/drivers/cadence_ttc: fix memory leak in ttc_setup_clockevent() 2020-11-12 9:59 ` Daniel Lezcano @ 2020-11-16 7:08 ` Yu Kuai 2020-11-16 13:51 ` [PATCH V4] " Yu Kuai 0 siblings, 1 reply; 9+ messages in thread From: Yu Kuai @ 2020-11-16 7:08 UTC (permalink / raw) To: michal.simek, daniel.lezcano, tglx, soren.brinkmann Cc: linux-arm-kernel, linux-kernel, yukuai3, yi.zhang, zhangxiaoxu5 If clk_notifier_register() failed, ttc_setup_clockevent() will return without freeing 'ttcce', which will leak memory. Fixes: 70504f311d4b ("clocksource/drivers/cadence_ttc: Convert init function to return error") Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Yu Kuai <yukuai3@huawei.com> --- drivers/clocksource/timer-cadence-ttc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/clocksource/timer-cadence-ttc.c b/drivers/clocksource/timer-cadence-ttc.c index 80e960602030..c410d1620e24 100644 --- a/drivers/clocksource/timer-cadence-ttc.c +++ b/drivers/clocksource/timer-cadence-ttc.c @@ -413,10 +413,8 @@ static int __init ttc_setup_clockevent(struct clk *clk, ttcce->ttc.clk = clk; err = clk_prepare_enable(ttcce->ttc.clk); - if (err) { - kfree(ttcce); - return err; - } + if (err) + go out_kfree; ttcce->ttc.clk_rate_change_nb.notifier_call = ttc_rate_change_clockevent_cb; @@ -426,7 +424,7 @@ static int __init ttc_setup_clockevent(struct clk *clk, &ttcce->ttc.clk_rate_change_nb); if (err) { pr_warn("Unable to register clock notifier.\n"); - return err; + goto out_kfree; } ttcce->ttc.freq = clk_get_rate(ttcce->ttc.clk); @@ -455,15 +453,17 @@ static int __init ttc_setup_clockevent(struct clk *clk, err = request_irq(irq, ttc_clock_event_interrupt, IRQF_TIMER, ttcce->ce.name, ttcce); - if (err) { - kfree(ttcce); - return err; - } + if (err) + goto out_kfree; clockevents_config_and_register(&ttcce->ce, ttcce->ttc.freq / PRESCALE, 1, 0xfffe); return 0; + +out_kfree: + kfree(ttcce); + return err; } static int __init ttc_timer_probe(struct platform_device *pdev) -- 2.25.4 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH V4] clocksource/drivers/cadence_ttc: fix memory leak in ttc_setup_clockevent() 2020-11-16 7:08 ` [PATCH V3] " Yu Kuai @ 2020-11-16 13:51 ` Yu Kuai 2020-11-17 9:07 ` Daniel Lezcano 2020-12-03 23:47 ` [tip: timers/core] clocksource/drivers/cadence_ttc: Fix " tip-bot2 for Yu Kuai 0 siblings, 2 replies; 9+ messages in thread From: Yu Kuai @ 2020-11-16 13:51 UTC (permalink / raw) To: michal.simek, daniel.lezcano, tglx, soren.brinkmann Cc: linux-arm-kernel, linux-kernel, yukuai3, yi.zhang, zhangxiaoxu5 If clk_notifier_register() failed, ttc_setup_clockevent() will return without freeing 'ttcce', which will leak memory. Fixes: 70504f311d4b ("clocksource/drivers/cadence_ttc: Convert init function to return error") Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Yu Kuai <yukuai3@huawei.com> --- Changes from V3: - fix the spelling mistake "go"->"goto", My sincere apology for this foolish mistake. drivers/clocksource/timer-cadence-ttc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/clocksource/timer-cadence-ttc.c b/drivers/clocksource/timer-cadence-ttc.c index 80e960602030..c410d1620e24 100644 --- a/drivers/clocksource/timer-cadence-ttc.c +++ b/drivers/clocksource/timer-cadence-ttc.c @@ -413,10 +413,8 @@ static int __init ttc_setup_clockevent(struct clk *clk, ttcce->ttc.clk = clk; err = clk_prepare_enable(ttcce->ttc.clk); - if (err) { - kfree(ttcce); - return err; - } + if (err) + goto out_kfree; ttcce->ttc.clk_rate_change_nb.notifier_call = ttc_rate_change_clockevent_cb; @@ -426,7 +424,7 @@ static int __init ttc_setup_clockevent(struct clk *clk, &ttcce->ttc.clk_rate_change_nb); if (err) { pr_warn("Unable to register clock notifier.\n"); - return err; + goto out_kfree; } ttcce->ttc.freq = clk_get_rate(ttcce->ttc.clk); @@ -455,15 +453,17 @@ static int __init ttc_setup_clockevent(struct clk *clk, err = request_irq(irq, ttc_clock_event_interrupt, IRQF_TIMER, ttcce->ce.name, ttcce); - if (err) { - kfree(ttcce); - return err; - } + if (err) + goto out_kfree; clockevents_config_and_register(&ttcce->ce, ttcce->ttc.freq / PRESCALE, 1, 0xfffe); return 0; + +out_kfree: + kfree(ttcce); + return err; } static int __init ttc_timer_probe(struct platform_device *pdev) -- 2.25.4 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH V4] clocksource/drivers/cadence_ttc: fix memory leak in ttc_setup_clockevent() 2020-11-16 13:51 ` [PATCH V4] " Yu Kuai @ 2020-11-17 9:07 ` Daniel Lezcano 2020-12-03 23:47 ` [tip: timers/core] clocksource/drivers/cadence_ttc: Fix " tip-bot2 for Yu Kuai 1 sibling, 0 replies; 9+ messages in thread From: Daniel Lezcano @ 2020-11-17 9:07 UTC (permalink / raw) To: Yu Kuai, michal.simek, tglx, soren.brinkmann Cc: linux-arm-kernel, linux-kernel, yi.zhang, zhangxiaoxu5 On 16/11/2020 14:51, Yu Kuai wrote: > If clk_notifier_register() failed, ttc_setup_clockevent() will return > without freeing 'ttcce', which will leak memory. > > Fixes: 70504f311d4b ("clocksource/drivers/cadence_ttc: Convert init function to return error") > Reported-by: Hulk Robot <hulkci@huawei.com> > Signed-off-by: Yu Kuai <yukuai3@huawei.com> > --- Applied, thanks -- <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog ^ permalink raw reply [flat|nested] 9+ messages in thread
* [tip: timers/core] clocksource/drivers/cadence_ttc: Fix memory leak in ttc_setup_clockevent() 2020-11-16 13:51 ` [PATCH V4] " Yu Kuai 2020-11-17 9:07 ` Daniel Lezcano @ 2020-12-03 23:47 ` tip-bot2 for Yu Kuai 1 sibling, 0 replies; 9+ messages in thread From: tip-bot2 for Yu Kuai @ 2020-12-03 23:47 UTC (permalink / raw) To: linux-tip-commits; +Cc: Hulk Robot, Yu Kuai, Daniel Lezcano, x86, linux-kernel The following commit has been merged into the timers/core branch of tip: Commit-ID: eee422c46e6840a81c9db18a497b74387a557b29 Gitweb: https://git.kernel.org/tip/eee422c46e6840a81c9db18a497b74387a557b29 Author: Yu Kuai <yukuai3@huawei.com> AuthorDate: Mon, 16 Nov 2020 21:51:23 +08:00 Committer: Daniel Lezcano <daniel.lezcano@linaro.org> CommitterDate: Thu, 03 Dec 2020 19:16:26 +01:00 clocksource/drivers/cadence_ttc: Fix memory leak in ttc_setup_clockevent() If clk_notifier_register() failed, ttc_setup_clockevent() will return without freeing 'ttcce', which will leak memory. Fixes: 70504f311d4b ("clocksource/drivers/cadence_ttc: Convert init function to return error") Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Yu Kuai <yukuai3@huawei.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Link: https://lore.kernel.org/r/20201116135123.2164033-1-yukuai3@huawei.com --- drivers/clocksource/timer-cadence-ttc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/clocksource/timer-cadence-ttc.c b/drivers/clocksource/timer-cadence-ttc.c index 80e9606..4efd0cf 100644 --- a/drivers/clocksource/timer-cadence-ttc.c +++ b/drivers/clocksource/timer-cadence-ttc.c @@ -413,10 +413,8 @@ static int __init ttc_setup_clockevent(struct clk *clk, ttcce->ttc.clk = clk; err = clk_prepare_enable(ttcce->ttc.clk); - if (err) { - kfree(ttcce); - return err; - } + if (err) + goto out_kfree; ttcce->ttc.clk_rate_change_nb.notifier_call = ttc_rate_change_clockevent_cb; @@ -426,7 +424,7 @@ static int __init ttc_setup_clockevent(struct clk *clk, &ttcce->ttc.clk_rate_change_nb); if (err) { pr_warn("Unable to register clock notifier.\n"); - return err; + goto out_kfree; } ttcce->ttc.freq = clk_get_rate(ttcce->ttc.clk); @@ -455,15 +453,17 @@ static int __init ttc_setup_clockevent(struct clk *clk, err = request_irq(irq, ttc_clock_event_interrupt, IRQF_TIMER, ttcce->ce.name, ttcce); - if (err) { - kfree(ttcce); - return err; - } + if (err) + goto out_kfree; clockevents_config_and_register(&ttcce->ce, ttcce->ttc.freq / PRESCALE, 1, 0xfffe); return 0; + +out_kfree: + kfree(ttcce); + return err; } static int __init ttc_timer_probe(struct platform_device *pdev) ^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-12-03 23:48 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-11-10 1:15 [PATCH] "clocksource/drivers/cadence_ttc: fix memory leak in ttc_setup_clockevent() Yu Kuai 2020-11-10 10:04 ` Michal Simek 2020-11-10 10:07 ` Michal Simek 2020-11-11 1:16 ` [PATCH V2] clocksource/drivers/cadence_ttc: " Yu Kuai 2020-11-12 9:59 ` Daniel Lezcano 2020-11-16 7:08 ` [PATCH V3] " Yu Kuai 2020-11-16 13:51 ` [PATCH V4] " Yu Kuai 2020-11-17 9:07 ` Daniel Lezcano 2020-12-03 23:47 ` [tip: timers/core] clocksource/drivers/cadence_ttc: Fix " tip-bot2 for Yu Kuai
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).