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-by: Michal Simek <[email protected]>
Signed-off-by: Alexandre Belloni <[email protected]>
Tested-by: Michal Simek <[email protected]>
Signed-off-by: Michal Simek <[email protected]>
  • Loading branch information
alexandrebelloni authored and Michal Simek committed Aug 21, 2017
1 parent 5e5e895 commit 281097a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions kernel/time/alarmtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 281097a

Please sign in to comment.