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>

authored by

Geert Uytterhoeven and committed by
John Stultz
47b4a457 a529bea8

+9 -2
+9 -2
kernel/time/alarmtimer.c
··· 56 56 static DEFINE_SPINLOCK(freezer_delta_lock); 57 57 #endif 58 58 59 + #ifdef CONFIG_RTC_CLASS 59 60 static struct wakeup_source *ws; 60 61 61 - #ifdef CONFIG_RTC_CLASS 62 62 /* rtc timer and device for setting alarm wakeups at suspend */ 63 63 static struct rtc_timer rtctimer; 64 64 static struct rtc_device *rtcdev; ··· 89 89 { 90 90 unsigned long flags; 91 91 struct rtc_device *rtc = to_rtc_device(dev); 92 + struct wakeup_source *__ws; 92 93 93 94 if (rtcdev) 94 95 return -EBUSY; ··· 99 98 if (!device_may_wakeup(rtc->dev.parent)) 100 99 return -1; 101 100 101 + __ws = wakeup_source_register("alarmtimer"); 102 + 102 103 spin_lock_irqsave(&rtcdev_lock, flags); 103 104 if (!rtcdev) { 104 105 rtcdev = rtc; 105 106 /* hold a reference so it doesn't go away */ 106 107 get_device(dev); 108 + ws = __ws; 109 + __ws = NULL; 107 110 } 108 111 spin_unlock_irqrestore(&rtcdev_lock, flags); 112 + 113 + wakeup_source_unregister(__ws); 114 + 109 115 return 0; 110 116 } 111 117 ··· 868 860 error = PTR_ERR(pdev); 869 861 goto out_drv; 870 862 } 871 - ws = wakeup_source_register("alarmtimer"); 872 863 return 0; 873 864 874 865 out_drv: