* [PATCH] rtc: disable the alarm in the hardware
@ 2011-11-22 10:03 Linus Walleij
2011-11-22 20:32 ` John Stultz
0 siblings, 1 reply; 3+ messages in thread
From: Linus Walleij @ 2011-11-22 10:03 UTC (permalink / raw)
To: Alessandro Zummo, rtc-linux, John Stultz, linux-kernel
Cc: Rabin Vincent, stable, John Stultz
From: Rabin Vincent <rabin.vincent@stericsson.com>
Currently, the RTC code does not disable the alarm in the hardware.
This means that after a sequence such as the one below (the files are in the
RTC sysfs), the box will boot up after 2 minutes even though we've
asked for the alarm to be turned off.
# echo $((`cat since_epoch`)+120) > wakealarm
# echo 0 > wakealarm
# poweroff
Fix this by disabling the alarm when there are no timers to run.
Cc: stable@kernel.org
Cc: John Stultz <john.stultz@linaro.org>
Signed-off-by: Rabin Vincent <rabin.vincent@stericsson.com>
---
drivers/rtc/interface.c | 44 ++++++++++++++++++++++++++++++++++----------
1 files changed, 34 insertions(+), 10 deletions(-)
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 8e28625..fa4d9f3 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -319,6 +319,20 @@ int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
}
EXPORT_SYMBOL_GPL(rtc_read_alarm);
+static int ___rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
+{
+ int err;
+
+ if (!rtc->ops)
+ err = -ENODEV;
+ else if (!rtc->ops->set_alarm)
+ err = -EINVAL;
+ else
+ err = rtc->ops->set_alarm(rtc->dev.parent, alarm);
+
+ return err;
+}
+
static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
{
struct rtc_time tm;
@@ -342,14 +356,7 @@ static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
* over right here, before we set the alarm.
*/
- if (!rtc->ops)
- err = -ENODEV;
- else if (!rtc->ops->set_alarm)
- err = -EINVAL;
- else
- err = rtc->ops->set_alarm(rtc->dev.parent, alarm);
-
- return err;
+ return ___rtc_set_alarm(rtc, alarm);
}
int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
@@ -763,6 +770,20 @@ static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer)
return 0;
}
+static void rtc_alarm_disable(struct rtc_device *rtc)
+{
+ struct rtc_wkalrm alarm;
+ struct rtc_time tm;
+
+ __rtc_read_time(rtc, &tm);
+
+ alarm.time = rtc_ktime_to_tm(ktime_add(rtc_tm_to_ktime(tm),
+ ktime_set(300, 0)));
+ alarm.enabled = 0;
+
+ ___rtc_set_alarm(rtc, &alarm);
+}
+
/**
* rtc_timer_remove - Removes a rtc_timer from the rtc_device timerqueue
* @rtc rtc device
@@ -784,8 +805,10 @@ static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer)
struct rtc_wkalrm alarm;
int err;
next = timerqueue_getnext(&rtc->timerqueue);
- if (!next)
+ if (!next) {
+ rtc_alarm_disable(rtc);
return;
+ }
alarm.time = rtc_ktime_to_tm(next->expires);
alarm.enabled = 1;
err = __rtc_set_alarm(rtc, &alarm);
@@ -847,7 +870,8 @@ again:
err = __rtc_set_alarm(rtc, &alarm);
if (err == -ETIME)
goto again;
- }
+ } else
+ rtc_alarm_disable(rtc);
mutex_unlock(&rtc->ops_lock);
}
--
1.7.3.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] rtc: disable the alarm in the hardware
2011-11-22 10:03 [PATCH] rtc: disable the alarm in the hardware Linus Walleij
@ 2011-11-22 20:32 ` John Stultz
2011-11-23 12:53 ` [rtc-linux] " Linus Walleij
0 siblings, 1 reply; 3+ messages in thread
From: John Stultz @ 2011-11-22 20:32 UTC (permalink / raw)
To: Linus Walleij
Cc: Alessandro Zummo, rtc-linux, linux-kernel, Rabin Vincent, stable
On Tue, 2011-11-22 at 11:03 +0100, Linus Walleij wrote:
> From: Rabin Vincent <rabin.vincent@stericsson.com>
>
> Currently, the RTC code does not disable the alarm in the hardware.
>
> This means that after a sequence such as the one below (the files are in the
> RTC sysfs), the box will boot up after 2 minutes even though we've
> asked for the alarm to be turned off.
>
> # echo $((`cat since_epoch`)+120) > wakealarm
> # echo 0 > wakealarm
> # poweroff
>
> Fix this by disabling the alarm when there are no timers to run.
Hey Linus,
Thanks for sending this along! It looks like a good fix to me! I'm a
little amazed this hasn't cropped up sooner. I'll do some further
testing and then queue it for upstream.
thanks
-john
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [rtc-linux] Re: [PATCH] rtc: disable the alarm in the hardware
2011-11-22 20:32 ` John Stultz
@ 2011-11-23 12:53 ` Linus Walleij
0 siblings, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2011-11-23 12:53 UTC (permalink / raw)
To: rtc-linux
Cc: Linus Walleij, Alessandro Zummo, linux-kernel, Rabin Vincent, stable
On Tue, Nov 22, 2011 at 9:32 PM, John Stultz <john.stultz@linaro.org> wrote:
> On Tue, 2011-11-22 at 11:03 +0100, Linus Walleij wrote:
>> From: Rabin Vincent <rabin.vincent@stericsson.com>
>>(...)
>> Fix this by disabling the alarm when there are no timers to run.
>
> Hey Linus,
> Thanks for sending this along! It looks like a good fix to me! I'm a
> little amazed this hasn't cropped up sooner. I'll do some further
> testing and then queue it for upstream.
Thanks, but thank Rabin who did all the root cause analysis,
I'm just his secretary... :-)
Linus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-11-23 12:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-22 10:03 [PATCH] rtc: disable the alarm in the hardware Linus Walleij
2011-11-22 20:32 ` John Stultz
2011-11-23 12:53 ` [rtc-linux] " Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).