* [PATCH] RTC: Fix infinite loop in initializing the alarm.
@ 2014-04-07 22:54 Ales Novak
2014-04-08 14:43 ` Alessandro Zummo
2014-05-08 5:56 ` [PATCH] drivers/rtc/interface.c: fix for fix of alarm initialization Ales Novak
0 siblings, 2 replies; 3+ messages in thread
From: Ales Novak @ 2014-04-07 22:54 UTC (permalink / raw)
To: Alessandro Zummo, Andrew Morton
Cc: rtc-linux, linux-kernel, Jiri Kosina, John Stultz, Ales Novak
In __rtc_read_alarm(), if the alarm time retrieved by
rtc_read_alarm_internal() from the device contains invalid values
(e.g. month=2,mday=31) and the year not set (=-1), the initialization
will loop infinitely because the year-fixing loop expects the
time being invalid due to leap year.
Fix reduces the loop to the leap years and adds final validity check.
Signed-off-by: Ales Novak <alnovak@suse.cz>
---
drivers/rtc/interface.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 544be72..a2df283 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -292,7 +292,9 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
dev_dbg(&rtc->dev, "alarm rollover: %s\n", "year");
do {
alarm->time.tm_year++;
- } while (rtc_valid_tm(&alarm->time) != 0);
+ } while (alarm->time.tm_mon == 1
+ && is_leap_year(alarm->time.tm_year + 1900)
+ && rtc_valid_tm(&alarm->time) != 0);
break;
default:
@@ -300,7 +302,16 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
}
done:
- return 0;
+ err = rtc_valid_tm(&alarm->time);
+
+ if (err) {
+ dev_warn(&rtc->dev, "invalid alarm value: %d-%d-%d %d:%d:%d\n",
+ alarm->time.tm_year + 1900, alarm->time.tm_mon + 1,
+ alarm->time.tm_mday, alarm->time.tm_hour, alarm->time.tm_min,
+ alarm->time.tm_sec);
+ }
+
+ return err;
}
int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
--
1.8.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] RTC: Fix infinite loop in initializing the alarm.
2014-04-07 22:54 [PATCH] RTC: Fix infinite loop in initializing the alarm Ales Novak
@ 2014-04-08 14:43 ` Alessandro Zummo
2014-05-08 5:56 ` [PATCH] drivers/rtc/interface.c: fix for fix of alarm initialization Ales Novak
1 sibling, 0 replies; 3+ messages in thread
From: Alessandro Zummo @ 2014-04-08 14:43 UTC (permalink / raw)
To: Ales Novak
Cc: Andrew Morton, rtc-linux, linux-kernel, Jiri Kosina, John Stultz
On Tue, 8 Apr 2014 00:54:42 +0200
Ales Novak <alnovak@suse.cz> wrote:
> In __rtc_read_alarm(), if the alarm time retrieved by
> rtc_read_alarm_internal() from the device contains invalid values
> (e.g. month=2,mday=31) and the year not set (=-1), the initialization
> will loop infinitely because the year-fixing loop expects the
> time being invalid due to leap year.
>
> Fix reduces the loop to the leap years and adds final validity check.
>
> Signed-off-by: Ales Novak <alnovak@suse.cz>
Seems reasonable.
Acked-by: Alessandro Zummo <a.zummo@towertech.it>
--
Best regards,
Alessandro Zummo,
Tower Technologies - Torino, Italy
http://www.towertech.it
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] drivers/rtc/interface.c: fix for fix of alarm initialization
2014-04-07 22:54 [PATCH] RTC: Fix infinite loop in initializing the alarm Ales Novak
2014-04-08 14:43 ` Alessandro Zummo
@ 2014-05-08 5:56 ` Ales Novak
1 sibling, 0 replies; 3+ messages in thread
From: Ales Novak @ 2014-05-08 5:56 UTC (permalink / raw)
To: Alessandro Zummo, Andrew Morton
Cc: rtc-linux, linux-kernel, Jiri Kosina, John Stultz, Ales Novak
Seems the previous patch "fix infinite loop in initializing the alarm"
did break the infinite loop in alarm initialization, but not in the right
way. The loop indeed should walk through the not-leap years and stop on
the leap one.
This patch does apply on top of the previous one.
Signed-off-by: Ales Novak <alnovak@suse.cz>
---
Fix for patch drivers-rtc-interfacec-fix-infinite-loop-in-initializing-the-alarm
drivers/rtc/interface.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index a2df283..bd6314a 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -292,8 +292,7 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
dev_dbg(&rtc->dev, "alarm rollover: %s\n", "year");
do {
alarm->time.tm_year++;
- } while (alarm->time.tm_mon == 1
- && is_leap_year(alarm->time.tm_year + 1900)
+ } while (!is_leap_year(alarm->time.tm_year + 1900)
&& rtc_valid_tm(&alarm->time) != 0);
break;
--
1.8.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-05-08 7:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-07 22:54 [PATCH] RTC: Fix infinite loop in initializing the alarm Ales Novak
2014-04-08 14:43 ` Alessandro Zummo
2014-05-08 5:56 ` [PATCH] drivers/rtc/interface.c: fix for fix of alarm initialization Ales Novak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox