Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753401AbdHTWCC (ORCPT ); Sun, 20 Aug 2017 18:02:02 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:59163 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753300AbdHTWCB (ORCPT ); Sun, 20 Aug 2017 18:02:01 -0400 From: Alexandre Belloni To: Thomas Gleixner , John Stultz Cc: Stephen Boyd , linux-kernel@vger.kernel.org, Michal Simek , Alexandre Belloni Subject: [PATCH] alarmtimer: ensure RTC module is not unloaded Date: Mon, 21 Aug 2017 00:01:46 +0200 Message-Id: <20170820220146.30969-1-alexandre.belloni@free-electrons.com> X-Mailer: git-send-email 2.14.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1089 Lines: 37 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 Signed-off-by: Alexandre Belloni --- 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 #include #include +#include #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