]> rtime.felk.cvut.cz Git - zynq/linux.git/commitdiff
alarmtimer: ensure RTC module is not unloaded
authorAlexandre Belloni <alexandre.belloni@free-electrons.com>
Sun, 20 Aug 2017 22:01:46 +0000 (00:01 +0200)
committerMichal Simek <michal.simek@xilinx.com>
Mon, 21 Aug 2017 10:52:12 +0000 (12:52 +0200)
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-by: Michal Simek <monstr@monstr.eu>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Tested-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
kernel/time/alarmtimer.c

index 12dd190634ab3e0617ac260133818523f142f8a2..a297d70244eb692d40178c633b1fb4348e752a15 100644 (file)
@@ -25,6 +25,8 @@
 #include <linux/posix-timers.h>
 #include <linux/workqueue.h>
 #include <linux/freezer.h>
+#include <linux/module.h>
+
 
 /**
  * struct alarm_base - Alarm timer bases
@@ -88,6 +90,11 @@ static int alarmtimer_rtc_add_device(struct device *dev,
 
        spin_lock_irqsave(&rtcdev_lock, flags);
        if (!rtcdev) {
+               if (!try_module_get(rtc->owner)) {
+                       spin_unlock_irqrestore(&rtcdev_lock, flags);
+                       return -1;
+               }
+
                rtcdev = rtc;
                /* hold a reference so it doesn't go away */
                get_device(dev);