Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1716030 > unrolled thread

[PATCH] alarmtimer: ensure RTC module is not unloaded

Started byAlexandre Belloni <alexandre.belloni@free-electrons.com>
First post2017-08-21 00:10 +0200
Last post2017-08-21 11:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] alarmtimer: ensure RTC module is not unloaded Alexandre Belloni <alexandre.belloni@free-electrons.com> - 2017-08-21 00:10 +0200
    Re: [PATCH] alarmtimer: ensure RTC module is not unloaded Michal Simek <monstr@monstr.eu> - 2017-08-21 11:50 +0200

#1716030 — [PATCH] alarmtimer: ensure RTC module is not unloaded

FromAlexandre Belloni <alexandre.belloni@free-electrons.com>
Date2017-08-21 00:10 +0200
Subject[PATCH] alarmtimer: ensure RTC module is not unloaded
Message-ID<ugGzU-4ie-13@gated-at.bofh.it>
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 <monstr@monstr.eu>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
 kernel/time/alarmtimer.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 0b8ff7d257ea..1c682eef7e6b 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -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);
-- 
2.14.1

[toc] | [next] | [standalone]


#1716252

FromMichal Simek <monstr@monstr.eu>
Date2017-08-21 11:50 +0200
Message-ID<ugRvj-2Gw-5@gated-at.bofh.it>
In reply to#1716030

[Multipart message — attachments visible in raw view] — view raw

On 21.8.2017 00:01, Alexandre Belloni wrote:
> 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 <monstr@monstr.eu>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> ---
>  kernel/time/alarmtimer.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
> index 0b8ff7d257ea..1c682eef7e6b 100644
> --- a/kernel/time/alarmtimer.c
> +++ b/kernel/time/alarmtimer.c
> @@ -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);
> 

Tested-by: Michal Simek <michal.simek@xilinx.com>

Thanks,
Michal


-- 
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


[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web