mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Igor Velkov via B4 Relay <devnull+iav.iav.lv@kernel.org>
To: John Stultz <jstultz@google.com>,
	Thomas Gleixner <tglx@kernel.org>,
	 Alexandre Belloni <alexandre.belloni@bootlin.com>,
	 Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>,
	 Neil Armstrong <neil.armstrong@linaro.org>,
	 Kevin Hilman <khilman@baylibre.com>
Cc: Stephen Boyd <sboyd@kernel.org>,
	Miroslav Lichvar <mlichvar@redhat.com>,
	 Jerome Brunet <jbrunet@baylibre.com>,
	 Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
	 linux-rtc@vger.kernel.org, devicetree@vger.kernel.org,
	 linux-arm-kernel@lists.infradead.org,
	linux-amlogic@lists.infradead.org,  linux-kernel@vger.kernel.org,
	Igor Velkov <iav@iav.lv>
Subject: [PATCH v2 1/8] alarmtimer: Replace alarmtimer_get_rtcdev() with alarmtimer_has_rtcdev()
Date: Mon, 16 Nov 2026 00:25:00 +0000	[thread overview]
Message-ID: <20261116-b4-alarmtimer-rtc-priority-v2-1-b2c69721e489@iav.lv> (raw)
In-Reply-To: <20261116-b4-alarmtimer-rtc-priority-v2-0-b2c69721e489@iav.lv>

From: Igor Velkov <iav@iav.lv>

alarmtimer_get_rtcdev() returns the wakeup RTC without taking a reference.
Apart from alarmtimer_suspend() and alarmtimer_resume(), its callers only
test the result for NULL: the alarm clock functions to tell whether alarm
clocks are supported, and charger-manager to decide whether to set up its
alarm.

A later patch lets a different RTC wake the system from each suspend
state, so there is no single RTC to return.

Provide alarmtimer_has_rtcdev() for these tests and read rtcdev directly
in alarmtimer_suspend() and alarmtimer_resume().

Signed-off-by: Igor Velkov <iav@iav.lv>
---
 drivers/power/supply/charger-manager.c |  2 +-
 include/linux/alarmtimer.h             |  7 ++-----
 kernel/time/alarmtimer.c               | 24 ++++++++++++------------
 3 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c
index 8e8c5109401a..754ff4b3de1a 100644
--- a/drivers/power/supply/charger-manager.c
+++ b/drivers/power/supply/charger-manager.c
@@ -1456,7 +1456,7 @@ static int charger_manager_probe(struct platform_device *pdev)
 	psy_cfg.drv_data = cm;
 
 	/* Initialize alarm timer */
-	if (alarmtimer_get_rtcdev()) {
+	if (alarmtimer_has_rtcdev()) {
 		cm_timer = devm_kzalloc(cm->dev, sizeof(*cm_timer), GFP_KERNEL);
 		if (!cm_timer)
 			return -ENOMEM;
diff --git a/include/linux/alarmtimer.h b/include/linux/alarmtimer.h
index 2014288ca2f4..3dd6d8762a73 100644
--- a/include/linux/alarmtimer.h
+++ b/include/linux/alarmtimer.h
@@ -6,8 +6,6 @@
 #include <linux/hrtimer.h>
 #include <linux/timerqueue.h>
 
-struct rtc_device;
-
 enum alarmtimer_type {
 	ALARM_REALTIME,
 	ALARM_BOOTTIME,
@@ -58,10 +56,9 @@ u64 alarm_forward_now(struct alarm *alarm, ktime_t interval);
 ktime_t alarm_expires_remaining(const struct alarm *alarm);
 
 #ifdef CONFIG_RTC_CLASS
-/* Provide way to access the rtc device being used by alarmtimers */
-struct rtc_device *alarmtimer_get_rtcdev(void);
+bool alarmtimer_has_rtcdev(void);
 #else
-static inline struct rtc_device *alarmtimer_get_rtcdev(void) { return NULL; }
+static inline bool alarmtimer_has_rtcdev(void) { return false; }
 #endif
 
 #endif
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index ecf8c89f7eaf..6c663f7d93c2 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -63,15 +63,15 @@ static struct rtc_timer		rtctimer;
 static struct rtc_device	*rtcdev;
 
 /**
- * alarmtimer_get_rtcdev - Return selected rtcdevice
+ * alarmtimer_has_rtcdev - Check whether an RTC can wake the system for alarms
  *
- * This function returns the rtc device to use for wakealarms.
+ * Return: True when alarmtimer has an RTC to program on suspend
  */
-struct rtc_device *alarmtimer_get_rtcdev(void)
+bool alarmtimer_has_rtcdev(void)
 {
-	return READ_ONCE(rtcdev);
+	return !!READ_ONCE(rtcdev);
 }
-EXPORT_SYMBOL_GPL(alarmtimer_get_rtcdev);
+EXPORT_SYMBOL_GPL(alarmtimer_has_rtcdev);
 
 static int alarmtimer_rtc_add_device(struct device *dev)
 {
@@ -221,7 +221,7 @@ static int alarmtimer_suspend(struct device *dev)
 		freezer_delta = 0;
 	}
 
-	rtc = alarmtimer_get_rtcdev();
+	rtc = READ_ONCE(rtcdev);
 	/* If we have no rtcdev, just return */
 	if (!rtc)
 		return 0;
@@ -285,7 +285,7 @@ static int alarmtimer_resume(struct device *dev)
 {
 	struct rtc_device *rtc;
 
-	rtc = alarmtimer_get_rtcdev();
+	rtc = READ_ONCE(rtcdev);
 	if (rtc)
 		rtc_timer_cancel(rtc, &rtctimer);
 	return 0;
@@ -591,7 +591,7 @@ static bool alarm_timer_arm(struct k_itimer *timr, ktime_t expires,
  */
 static int alarm_clock_getres(const clockid_t which_clock, struct timespec64 *tp)
 {
-	if (!alarmtimer_get_rtcdev())
+	if (!alarmtimer_has_rtcdev())
 		return -EINVAL;
 
 	tp->tv_sec = 0;
@@ -610,7 +610,7 @@ static int alarm_clock_get_timespec(clockid_t which_clock, struct timespec64 *tp
 {
 	struct alarm_base *base = &alarm_bases[clock2alarm(which_clock)];
 
-	if (!alarmtimer_get_rtcdev())
+	if (!alarmtimer_has_rtcdev())
 		return -EINVAL;
 
 	base->get_timespec(tp);
@@ -628,7 +628,7 @@ static ktime_t alarm_clock_get_ktime(clockid_t which_clock)
 {
 	struct alarm_base *base = &alarm_bases[clock2alarm(which_clock)];
 
-	if (!alarmtimer_get_rtcdev())
+	if (!alarmtimer_has_rtcdev())
 		return -EINVAL;
 
 	return base->get_ktime();
@@ -644,7 +644,7 @@ static int alarm_timer_create(struct k_itimer *new_timer)
 {
 	enum  alarmtimer_type type;
 
-	if (!alarmtimer_get_rtcdev())
+	if (!alarmtimer_has_rtcdev())
 		return -EOPNOTSUPP;
 
 	if (!capable(CAP_WAKE_ALARM))
@@ -763,7 +763,7 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
 	ktime_t exp;
 	int ret;
 
-	if (!alarmtimer_get_rtcdev())
+	if (!alarmtimer_has_rtcdev())
 		return -EOPNOTSUPP;
 
 	if (flags & ~TIMER_ABSTIME)

-- 
2.43.0



  reply	other threads:[~2026-11-16  0:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  0:24 [PATCH v2 0/8] alarmtimer: Pick the wakeup RTC per suspend state Igor Velkov via B4 Relay
2026-11-16  0:25 ` Igor Velkov via B4 Relay [this message]
2026-11-16  0:25 ` [PATCH v2 2/8] alarmtimer: Move the wakeup state into struct rtc_wakeup Igor Velkov via B4 Relay
2026-11-16  0:25 ` [PATCH v2 3/8] alarmtimer: Replace the freezer delta with per type expiry times Igor Velkov via B4 Relay
2026-11-16  0:25 ` [PATCH v2 4/8] alarmtimer: Register the platform device without a parent Igor Velkov via B4 Relay
2026-11-16  0:25 ` [PATCH v2 5/8] alarmtimer: Keep an RTC per suspend state Igor Velkov via B4 Relay
2026-11-16  0:25 ` [PATCH v2 6/8] dt-bindings: rtc: Add linux,wakeup-states Igor Velkov via B4 Relay
2026-11-16  0:25 ` [PATCH v2 7/8] alarmtimer: Read the wakeup states of an RTC from linux,wakeup-states Igor Velkov via B4 Relay
2026-11-16  0:25 ` [PATCH v2 8/8] arm64: dts: amlogic: meson-sm1-odroid-hc4: Describe which RTC wakes the board Igor Velkov via B4 Relay

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=20261116-b4-alarmtimer-rtc-priority-v2-1-b2c69721e489@iav.lv \
    --to=devnull+iav.iav.lv@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=iav@iav.lv \
    --cc=jbrunet@baylibre.com \
    --cc=jstultz@google.com \
    --cc=khilman@baylibre.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=mlichvar@redhat.com \
    --cc=neil.armstrong@linaro.org \
    --cc=robh@kernel.org \
    --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®