Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751952AbdHaTmp (ORCPT ); Thu, 31 Aug 2017 15:42:45 -0400 Received: from terminus.zytor.com ([65.50.211.136]:46775 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751355AbdHaTmm (ORCPT ); Thu, 31 Aug 2017 15:42:42 -0400 Date: Thu, 31 Aug 2017 12:40:28 -0700 From: tip-bot for Alexandre Belloni Message-ID: Cc: monstr@monstr.eu, hpa@zytor.com, alexandre.belloni@free-electrons.com, tglx@linutronix.de, sboyd@codeaurora.org, john.stultz@linaro.org, mingo@kernel.org, linux-kernel@vger.kernel.org Reply-To: linux-kernel@vger.kernel.org, mingo@kernel.org, john.stultz@linaro.org, sboyd@codeaurora.org, tglx@linutronix.de, monstr@monstr.eu, hpa@zytor.com, alexandre.belloni@free-electrons.com In-Reply-To: <20170820220146.30969-1-alexandre.belloni@free-electrons.com> References: <20170820220146.30969-1-alexandre.belloni@free-electrons.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:timers/core] alarmtimer: Ensure RTC module is not unloaded Git-Commit-ID: 51218298a25e6942957c5595f2abf130d47d5df9 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1697 Lines: 50 Commit-ID: 51218298a25e6942957c5595f2abf130d47d5df9 Gitweb: http://git.kernel.org/tip/51218298a25e6942957c5595f2abf130d47d5df9 Author: Alexandre Belloni AuthorDate: Mon, 21 Aug 2017 00:01:46 +0200 Committer: Thomas Gleixner 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. Reported-and-tested-by: Michal Simek Signed-off-by: Alexandre Belloni Signed-off-by: Thomas Gleixner Acked-by: John Stultz Cc: Stephen Boyd Link: http://lkml.kernel.org/r/20170820220146.30969-1-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 73a2b47..ec09ce9 100644 --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -28,6 +28,7 @@ #include #include #include +#include #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);