Skip to content

Commit 6b6d188

Browse files
bebarinoKAGA-KOKO
authored andcommitted
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: 5121829 ("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
1 parent a750c74 commit 6b6d188

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

kernel/time/alarmtimer.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ static int alarmtimer_rtc_add_device(struct device *dev,
9191
unsigned long flags;
9292
struct rtc_device *rtc = to_rtc_device(dev);
9393
struct wakeup_source *__ws;
94+
int ret = 0;
9495

9596
if (rtcdev)
9697
return -EBUSY;
@@ -105,8 +106,8 @@ static int alarmtimer_rtc_add_device(struct device *dev,
105106
spin_lock_irqsave(&rtcdev_lock, flags);
106107
if (!rtcdev) {
107108
if (!try_module_get(rtc->owner)) {
108-
spin_unlock_irqrestore(&rtcdev_lock, flags);
109-
return -1;
109+
ret = -1;
110+
goto unlock;
110111
}
111112

112113
rtcdev = rtc;
@@ -115,11 +116,12 @@ static int alarmtimer_rtc_add_device(struct device *dev,
115116
ws = __ws;
116117
__ws = NULL;
117118
}
119+
unlock:
118120
spin_unlock_irqrestore(&rtcdev_lock, flags);
119121

120122
wakeup_source_unregister(__ws);
121123

122-
return 0;
124+
return ret;
123125
}
124126

125127
static inline void alarmtimer_rtc_timer_init(void)

0 commit comments

Comments
 (0)