aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Belloni <alexandre.belloni@free-electrons.com>2017-08-20 18:01:46 -0400
committerThomas Gleixner <tglx@linutronix.de>2017-08-31 15:36:45 -0400
commit51218298a25e6942957c5595f2abf130d47d5df9 (patch)
tree235c2bc0f868679108179df74bb2b660719bda87
parentbc30658eff39c5bb562174fcf93618ab6a7afe88 (diff)
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
-rw-r--r--kernel/time/alarmtimer.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 73a2b476e59f..ec09ce9a6012 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -28,6 +28,7 @@
28#include <linux/workqueue.h> 28#include <linux/workqueue.h>
29#include <linux/freezer.h> 29#include <linux/freezer.h>
30#include <linux/compat.h> 30#include <linux/compat.h>
31#include <linux/module.h>
31 32
32#include "posix-timers.h" 33#include "posix-timers.h"
33 34
@@ -103,6 +104,11 @@ static int alarmtimer_rtc_add_device(struct device *dev,
103 104
104 spin_lock_irqsave(&rtcdev_lock, flags); 105 spin_lock_irqsave(&rtcdev_lock, flags);
105 if (!rtcdev) { 106 if (!rtcdev) {
107 if (!try_module_get(rtc->owner)) {
108 spin_unlock_irqrestore(&rtcdev_lock, flags);
109 return -1;
110 }
111
106 rtcdev = rtc; 112 rtcdev = rtc;
107 /* hold a reference so it doesn't go away */ 113 /* hold a reference so it doesn't go away */
108 get_device(dev); 114 get_device(dev);