mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <linux@weissschuh.net>
To: John Stultz <jstultz@google.com>,
	Thomas Gleixner <tglx@kernel.org>,
	 Stephen Boyd <sboyd@kernel.org>,
	Miroslav Lichvar <mlichvar@redhat.com>
Cc: linux-kernel@vger.kernel.org, "Thomas Weißschuh" <linux@weissschuh.net>
Subject: [PATCH 3/3] alarmtimer: Return early if try_module_get() fails
Date: Mon, 02 Nov 2026 06:11:56 +0000	[thread overview]
Message-ID: <20261102-alarmtimer-locking-v1-3-3c79a698aeae@weissschuh.net> (raw)
In-Reply-To: <20261102-alarmtimer-locking-v1-0-3c79a698aeae@weissschuh.net>

Simplify the logic by returning early if try_module_get() fails.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 kernel/time/alarmtimer.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 9ab1b053a2fb..b1ae0d2c6a7d 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -77,7 +77,6 @@ static int alarmtimer_rtc_add_device(struct device *dev)
 {
 	struct rtc_device *rtc = to_rtc_device(dev);
 	struct platform_device *pdev;
-	int ret = 0;
 
 	if (rtcdev)
 		return -EBUSY;
@@ -94,17 +93,16 @@ static int alarmtimer_rtc_add_device(struct device *dev)
 
 	device_init_wakeup(&pdev->dev, true);
 
-	if (try_module_get(rtc->owner)) {
-		WRITE_ONCE(rtcdev, rtc);
-		/* hold a reference so it doesn't go away */
-		get_device(dev);
-		pdev = NULL;
-	} else {
-		ret = -1;
+	if (!try_module_get(rtc->owner)) {
+		platform_device_unregister(pdev);
+		return -1;
 	}
 
-	platform_device_unregister(pdev);
-	return ret;
+	WRITE_ONCE(rtcdev, rtc);
+	/* hold a reference so it doesn't go away */
+	get_device(dev);
+
+	return 0;
 }
 
 static inline void alarmtimer_rtc_timer_init(void)

-- 
2.56.0


      parent reply	other threads:[~2026-11-02  6:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02  6:11 [PATCH 0/3] alarmtimer: Drop the spinlock around the rtcdev variable Thomas Weißschuh
2026-11-02  6:11 ` [PATCH 1/3] " Thomas Weißschuh
2026-11-02  6:11 ` [PATCH 2/3] alarmtimer: Return early if platform_device_register_data() fails Thomas Weißschuh
2026-11-02  6:11 ` Thomas Weißschuh [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=20261102-alarmtimer-locking-v1-3-3c79a698aeae@weissschuh.net \
    --to=linux@weissschuh.net \
    --cc=jstultz@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mlichvar@redhat.com \
    --cc=sboyd@kernel.org \
    --cc=tglx@kernel.org \
    /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®