Skip to content

Commit 47b4a45

Browse files
geertujohnstultz-work
authored andcommitted
alarmtimer: Fix unavailable wake-up source in sysfs
Currently the alarmtimer registers a wake-up source unconditionally, regardless of the system having a (wake-up capable) RTC or not. Hence the alarmtimer will always show up in /sys/kernel/debug/wakeup_sources, even if it is not available, and thus cannot be a wake-up source. To fix this, postpone registration until a wake-up capable RTC device is added. Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@kernel.org> Cc: Miroslav Lichvar <mlichvar@redhat.com> Cc: Richard Cochran <richardcochran@gmail.com> Cc: Prarit Bhargava <prarit@redhat.com> Cc: Stephen Boyd <stephen.boyd@linaro.org> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: John Stultz <john.stultz@linaro.org>
1 parent a529bea commit 47b4a45

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎kernel/time/alarmtimer.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ static ktime_t freezer_delta;
5656
static DEFINE_SPINLOCK(freezer_delta_lock);
5757
#endif
5858

59+
#ifdef CONFIG_RTC_CLASS
5960
static struct wakeup_source *ws;
6061

61-
#ifdef CONFIG_RTC_CLASS
6262
/* rtc timer and device for setting alarm wakeups at suspend */
6363
static struct rtc_timer rtctimer;
6464
static struct rtc_device *rtcdev;
@@ -89,6 +89,7 @@ static int alarmtimer_rtc_add_device(struct device *dev,
8989
{
9090
unsigned long flags;
9191
struct rtc_device *rtc = to_rtc_device(dev);
92+
struct wakeup_source *__ws;
9293

9394
if (rtcdev)
9495
return -EBUSY;
@@ -98,13 +99,20 @@ static int alarmtimer_rtc_add_device(struct device *dev,
9899
if (!device_may_wakeup(rtc->dev.parent))
99100
return -1;
100101

102+
__ws = wakeup_source_register("alarmtimer");
103+
101104
spin_lock_irqsave(&rtcdev_lock, flags);
102105
if (!rtcdev) {
103106
rtcdev = rtc;
104107
/* hold a reference so it doesn't go away */
105108
get_device(dev);
109+
ws = __ws;
110+
__ws = NULL;
106111
}
107112
spin_unlock_irqrestore(&rtcdev_lock, flags);
113+
114+
wakeup_source_unregister(__ws);
115+
108116
return 0;
109117
}
110118

@@ -860,7 +868,6 @@ static int __init alarmtimer_init(void)
860868
error = PTR_ERR(pdev);
861869
goto out_drv;
862870
}
863-
ws = wakeup_source_register("alarmtimer");
864871
return 0;
865872

866873
out_drv:

0 commit comments

Comments
 (0)