Skip to content

Commit 5121829

Browse files
alexandrebelloniKAGA-KOKO
authored andcommitted
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
1 parent bc30658 commit 5121829

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

kernel/time/alarmtimer.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/workqueue.h>
2929
#include <linux/freezer.h>
3030
#include <linux/compat.h>
31+
#include <linux/module.h>
3132

3233
#include "posix-timers.h"
3334

@@ -103,6 +104,11 @@ static int alarmtimer_rtc_add_device(struct device *dev,
103104

104105
spin_lock_irqsave(&rtcdev_lock, flags);
105106
if (!rtcdev) {
107+
if (!try_module_get(rtc->owner)) {
108+
spin_unlock_irqrestore(&rtcdev_lock, flags);
109+
return -1;
110+
}
111+
106112
rtcdev = rtc;
107113
/* hold a reference so it doesn't go away */
108114
get_device(dev);

0 commit comments

Comments
 (0)