Skip to content

Commit

Permalink
alarmtimer: Ensure RTC module is not unloaded
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Alexandre Belloni authored and Thomas Gleixner committed Aug 31, 2017
1 parent bc30658 commit 5121829
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions kernel/time/alarmtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <linux/workqueue.h>
#include <linux/freezer.h>
#include <linux/compat.h>
#include <linux/module.h>

#include "posix-timers.h"

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5121829

Please sign in to comment.