[tip: timers/core] alarmtimer: Drop the spinlock around the rtcdev variable
From: tip-bot2 for Thomas Weißschuh
Date: Mon Nov 09 2026 - 14:57:31 EST
The following commit has been merged into the timers/core branch of tip:
Commit-ID: 6d771f75f3761d7c8aaf57b06a2b4ddcb25b4ce8
Gitweb: https://git.kernel.org/tip/6d771f75f3761d7c8aaf57b06a2b4ddcb25b4ce8
Author: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
AuthorDate: Mon, 02 Nov 2026 06:11:54
Committer: Thomas Gleixner <tglx@xxxxxxxxxx>
CommitterDate: Mon, 09 Nov 2026 20:50:03 +01:00
alarmtimer: Drop the spinlock around the rtcdev variable
The spinlock serializes calls to alarmtimer_rtc_add_device(), making sure
the 'rtcdev' variable is written only once. It also protects the read of
the 'rtcdev' variable in alarmtimer_get_rtcdev().
But alarmtimer_rtc_add_device() is already synchronized externally through
the driver core's subsystem lock. So the additional spinlock can be dropped
and replaced with WRITE_ONCE()/READ_ONCE() for consistent access.
This removes lock/unlock operations from the alarmtimer's clock callbacks.
[ tglx: Massage change log ]
Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxx>
Link: https://patch.msgid.link/20261102-alarmtimer-locking-v1-1-3c79a698aeae@xxxxxxxxxxxxxx
---
kernel/time/alarmtimer.c | 24 ++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index d6dc6e8..601ebdc 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -61,7 +61,6 @@ static DEFINE_SPINLOCK(freezer_delta_lock);
/* rtc timer and device for setting alarm wakeups at suspend */
static struct rtc_timer rtctimer;
static struct rtc_device *rtcdev;
-static DEFINE_SPINLOCK(rtcdev_lock);
/**
* alarmtimer_get_rtcdev - Return selected rtcdevice
@@ -70,12 +69,7 @@ static DEFINE_SPINLOCK(rtcdev_lock);
*/
struct rtc_device *alarmtimer_get_rtcdev(void)
{
- struct rtc_device *ret;
-
- guard(spinlock_irqsave)(&rtcdev_lock);
- ret = rtcdev;
-
- return ret;
+ return READ_ONCE(rtcdev);
}
EXPORT_SYMBOL_GPL(alarmtimer_get_rtcdev);
@@ -98,15 +92,13 @@ static int alarmtimer_rtc_add_device(struct device *dev)
if (!IS_ERR(pdev))
device_init_wakeup(&pdev->dev, true);
- scoped_guard(spinlock_irqsave, &rtcdev_lock) {
- if (!IS_ERR(pdev) && !rtcdev && try_module_get(rtc->owner)) {
- rtcdev = rtc;
- /* hold a reference so it doesn't go away */
- get_device(dev);
- pdev = NULL;
- } else {
- ret = -1;
- }
+ if (!IS_ERR(pdev) && 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;
}
platform_device_unregister(pdev);