mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhen Ni <zhen.ni@easystack.cn>
To: daniel.lezcano@linaro.org, tglx@linutronix.de
Cc: linux-kernel@vger.kernel.org, Zhen Ni <zhen.ni@easystack.cn>,
	stable@vger.kernel.org
Subject: [PATCH v4] clocksource: clps711x: Fix resource leaks in error paths
Date: Fri, 19 Sep 2025 11:54:37 +0800	[thread overview]
Message-ID: <20250919035437.587540-1-zhen.ni@easystack.cn> (raw)
In-Reply-To: <20250814123324.1516495-1-zhen.ni@easystack.cn>

The current implementation of clps711x_timer_init() has multiple error
paths that directly return without releasing the base I/O memory mapped
via of_iomap(). Fix of_iomap leaks in error paths.

Fixes: 04410efbb6bc ("clocksource/drivers/clps711x: Convert init function to return error")
Fixes: 2a6a8e2d9004 ("clocksource/drivers/clps711x: Remove board support")
Cc: stable@vger.kernel.org
Signed-off-by: Zhen Ni <zhen.ni@easystack.cn>
---
changes in v4:
- Change the default value of ret from 0 to -INVAL
- Do not release the iomap in success paths
changes in v3:
- Change "err" to "error" in the commit message.
changes in v2:
- Add tags of 'Fixes' and 'Cc'
- Reduce detailed enumeration of err paths
- Omit a pointer check before iounmap()
- Change goto target from out to unmap_io
---
 drivers/clocksource/clps711x-timer.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/clocksource/clps711x-timer.c b/drivers/clocksource/clps711x-timer.c
index e95fdc49c226..84dbcd049c25 100644
--- a/drivers/clocksource/clps711x-timer.c
+++ b/drivers/clocksource/clps711x-timer.c
@@ -78,24 +78,33 @@ static int __init clps711x_timer_init(struct device_node *np)
 	unsigned int irq = irq_of_parse_and_map(np, 0);
 	struct clk *clock = of_clk_get(np, 0);
 	void __iomem *base = of_iomap(np, 0);
+	int ret = -EINVAL;
 
 	if (!base)
 		return -ENOMEM;
 	if (!irq)
-		return -EINVAL;
-	if (IS_ERR(clock))
-		return PTR_ERR(clock);
+		goto unmap_io;
+	if (IS_ERR(clock)) {
+		ret = PTR_ERR(clock);
+		goto unmap_io;
+	}
 
 	switch (of_alias_get_id(np, "timer")) {
 	case CLPS711X_CLKSRC_CLOCKSOURCE:
 		clps711x_clksrc_init(clock, base);
+		ret = 0;
 		break;
 	case CLPS711X_CLKSRC_CLOCKEVENT:
-		return _clps711x_clkevt_init(clock, base, irq);
+		ret =  _clps711x_clkevt_init(clock, base, irq);
+		break;
 	default:
-		return -EINVAL;
+		break;
 	}
+	if (!ret)
+		return ret;
 
-	return 0;
+unmap_io:
+	iounmap(base);
+	return ret;
 }
 TIMER_OF_DECLARE(clps711x, "cirrus,ep7209-timer", clps711x_timer_init);
-- 
2.20.1


      parent reply	other threads:[~2025-09-19  6:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-31  6:23 [PATCH] " Zhen Ni
2025-08-01 14:00 ` Markus Elfring
2025-08-04 12:36 ` [PATCH v2] " Zhen Ni
2025-08-04 12:52   ` Markus Elfring
     [not found]   ` <20250805035637.169422-1-zhen.ni@easystack.cn>
2025-08-13 12:14     ` [PATCH v3] " Daniel Lezcano
2025-08-14 12:33   ` Zhen Ni
2025-09-17 16:05     ` Daniel Lezcano
2025-09-19  3:54     ` Zhen Ni [this message]

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=20250919035437.587540-1-zhen.ni@easystack.cn \
    --to=zhen.ni@easystack.cn \
    --cc=daniel.lezcano@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@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

all inboxes | Powered by JetHome®