alarmtimer: Ensure RTC module is not unloaded

When registering the rtc device to be used to handle alarm timers,
get_device is used to ensure the device doesn't go away but the module can
still be unloaded.

Call try_module_get to ensure the rtc driver will not go away.

Reported-and-tested-by: Michal Simek <monstr@monstr.eu>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: John Stultz <john.stultz@linaro.org>
Cc: Stephen Boyd <sboyd@codeaurora.org>
Link: http://lkml.kernel.org/r/20170820220146.30969-1-alexandre.belloni@free-electrons.com

authored by

Alexandre Belloni and committed by
Thomas Gleixner
51218298 bc30658e

+6
+6
kernel/time/alarmtimer.c
··· 28 28 #include <linux/workqueue.h> 29 29 #include <linux/freezer.h> 30 30 #include <linux/compat.h> 31 + #include <linux/module.h> 31 32 32 33 #include "posix-timers.h" 33 34 ··· 104 103 105 104 spin_lock_irqsave(&rtcdev_lock, flags); 106 105 if (!rtcdev) { 106 + if (!try_module_get(rtc->owner)) { 107 + spin_unlock_irqrestore(&rtcdev_lock, flags); 108 + return -1; 109 + } 110 + 107 111 rtcdev = rtc; 108 112 /* hold a reference so it doesn't go away */ 109 113 get_device(dev);