Skip to contentSkip to conversation

alarmtimer: ensure RTC module is not unloaded

PATCH In review Alexandre Belloni 3 participants 3 messages Aug 20, 2017 – Aug 31, 2017 Timekeeping, clocksource core, NTP, alarmtimer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 kernel/time/alarmtimer.c | 6 ++++++
 1 file changed, 6 insertions(+)
kernel/time/alarmtimer.c +6 -0
index 0b8ff7d257ea..1c682eef7e6b 100644
@@ -28,6 +28,7 @@
 #include <linux/workqueue.h>
 #include <linux/freezer.h>
 #include <linux/compat.h>
+#include <linux/module.h>
 
 #include "posix-timers.h"
 
@@ -100,6 +101,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);
Signature · 1 line
2.14.1
Tested-by on v1 1/1
#1 lore raw
Quoted 26 lines · Alexandre Belloni

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.

---
 kernel/time/alarmtimer.c | 6 ++++++
 1 file changed, 6 insertions(+)
kernel/time/alarmtimer.c +1 -0
index 0b8ff7d257ea..1c682eef7e6b 100644
@@ -28,6 +28,7 @@
 #include <linux/workqueue.h>
 #include <linux/freezer.h>
 #include <linux/compat.h>
+#include <linux/module.h>
 
 #include "posix-timers.h"
 
@@ -100,6 +101,11 @@ static int alarmtimer_rtc_add_device(struct device *dev,
 

kernel/time/alarmtimer.c static int alarmtimer_rtc_add_device(struct device *dev, · line 111

Quoted 10 lines
kernel/time/alarmtimer.c +5 -0
 	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);

Thanks,
Michal

Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP SoCs
#2 lore raw

[tip:timers/core] alarmtimer: Ensure RTC module is not unloaded

In reply to Alexandre Belloni
alarmtimer: Ensure RTC module is not unloaded
Commit-ID:  51218298a25e6942957c5595f2abf130d47d5df9
Gitweb:     http://git.kernel.org/tip/51218298a25e6942957c5595f2abf130d47d5df9
Author:     Alexandre Belloni <[email protected]>
AuthorDate: Mon, 21 Aug 2017 00:01:46 +0200
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 31 Aug 2017 21:36:45 +0200

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.

---
 kernel/time/alarmtimer.c | 6 ++++++
 1 file changed, 6 insertions(+)
kernel/time/alarmtimer.c +6 -0
index 73a2b47..ec09ce9 100644
@@ -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);