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