diff options
author | Stephen Boyd <swboyd@chromium.org> | 2020-01-09 07:59:07 -0800 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2020-01-15 11:16:54 +0100 |
commit | 6b6d188aae79a630957aefd88ff5c42af6553ee3 (patch) | |
tree | 12fe809c25800e4109df5f9f13456c61e8279419 | |
parent | a750c7474a5333a76e7278d353c460d26012deb6 (diff) | |
download | linux-6b6d188aae79a630957aefd88ff5c42af6553ee3.tar.gz linux-6b6d188aae79a630957aefd88ff5c42af6553ee3.tar.bz2 linux-6b6d188aae79a630957aefd88ff5c42af6553ee3.zip |
alarmtimer: Unregister wakeup source when module get fails
The alarmtimer_rtc_add_device() function creates a wakeup source and then
tries to grab a module reference. If that fails the function returns early
with an error code, but fails to remove the wakeup source.
Cleanup this exit path so there is no dangling wakeup source, which is
named 'alarmtime' left allocated which will conflict with another RTC
device that may be registered later.
Fixes: 51218298a25e ("alarmtimer: Ensure RTC module is not unloaded")
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20200109155910.907-2-swboyd@chromium.org
-rw-r--r-- | kernel/time/alarmtimer.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index b51b36e533c4..9dc7a0913190 100644 --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -91,6 +91,7 @@ static int alarmtimer_rtc_add_device(struct device *dev, unsigned long flags; struct rtc_device *rtc = to_rtc_device(dev); struct wakeup_source *__ws; + int ret = 0; if (rtcdev) return -EBUSY; @@ -105,8 +106,8 @@ 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; + ret = -1; + goto unlock; } rtcdev = rtc; @@ -115,11 +116,12 @@ static int alarmtimer_rtc_add_device(struct device *dev, ws = __ws; __ws = NULL; } +unlock: spin_unlock_irqrestore(&rtcdev_lock, flags); wakeup_source_unregister(__ws); - return 0; + return ret; } static inline void alarmtimer_rtc_timer_init(void) |