linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: tglx@linutronix.de
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 11/13] clocksource/drivers/cadence_ttc: Fix memory leak in ttc_setup_clockevent()
Date: Thu,  3 Dec 2020 20:32:59 +0100	[thread overview]
Message-ID: <20201203193301.2405835-11-daniel.lezcano@linaro.org> (raw)
In-Reply-To: <20201203193301.2405835-1-daniel.lezcano@linaro.org>

From: Yu Kuai <yukuai3@huawei.com>

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 80e960602030..4efd0cf3b602 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.1


  parent reply	other threads:[~2020-12-03 19:35 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-03 19:23 [GIT PULL] timer drivers for v5.11 Daniel Lezcano
2020-12-03 19:32 ` [PATCH 01/13] clocksource/drivers/sp804: Add static for functions such as sp804_clockevents_init() Daniel Lezcano
2020-12-03 19:32   ` [PATCH 02/13] clocksource/drivers/sp804: Make some symbol static Daniel Lezcano
2020-12-03 19:32   ` [PATCH 03/13] clocksource/drivers/sp804: Use clk_prepare_enable and clk_disable_unprepare Daniel Lezcano
2020-12-03 19:32   ` [PATCH 04/13] clocksource/drivers/sp804: Correct clk_get_rate handle Daniel Lezcano
2020-12-03 19:32   ` [PATCH 05/13] clocksource/drivers/sp804: Use pr_fmt Daniel Lezcano
2020-12-03 19:32   ` [PATCH 06/13] dt-bindings: timer: Add new OST support for the upcoming new driver Daniel Lezcano
2020-12-03 19:32   ` [PATCH 07/13] clocksource/drivers/nps: Remove EZChip NPS clocksource driver Daniel Lezcano
2020-12-03 19:32   ` [PATCH 08/13] clocksource/drivers/orion: Add missing clk_disable_unprepare() on error path Daniel Lezcano
2020-12-03 19:32   ` [PATCH 09/13] dt-bindings: timer: renesas: tmu: Document r8a774e1 bindings Daniel Lezcano
2020-12-03 19:32   ` [PATCH 10/13] dt-bindings: timer: renesas: tmu: Convert to json-schema Daniel Lezcano
2020-12-03 19:32   ` Daniel Lezcano [this message]
2020-12-03 19:33   ` [PATCH 12/13] clocksource/drivers/ingenic: Fix section mismatch Daniel Lezcano
2020-12-03 19:33   ` [PATCH 13/13] clocksource/drivers/riscv: Make RISCV_TIMER depends on RISCV_SBI Daniel Lezcano
2020-12-03 23:41 ` [GIT PULL] timer drivers for v5.11 Thomas Gleixner
2020-12-03 23:47 ` [tip: timers/core] Merge tag 'timers-v5.11' of https://git.linaro.org/people/daniel.lezcano/linux into timers/core tip-bot2 for Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201203193301.2405835-11-daniel.lezcano@linaro.org \
    --to=daniel.lezcano@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).