]> Git Repo - linux.git/commitdiff
alarmtimer: Ensure RTC module is not unloaded
authorAlexandre Belloni <[email protected]>
Sun, 20 Aug 2017 22:01:46 +0000 (00:01 +0200)
committerThomas Gleixner <[email protected]>
Thu, 31 Aug 2017 19:36:45 +0000 (21:36 +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-and-tested-by: Michal Simek <[email protected]>
Signed-off-by: Alexandre Belloni <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Acked-by: John Stultz <[email protected]>
Cc: Stephen Boyd <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
kernel/time/alarmtimer.c

index 73a2b476e59f3256387fe48097509bbda44c76af..ec09ce9a6012b0a0cdf5299fcbad8a813433d1e1 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/workqueue.h>
 #include <linux/freezer.h>
 #include <linux/compat.h>
+#include <linux/module.h>
 
 #include "posix-timers.h"
 
@@ -103,6 +104,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);
This page took 0.060059 seconds and 4 git commands to generate.