提交 ee1d9014 编写于 作者: A Ales Novak 提交者: Linus Torvalds

drivers/rtc/interface.c: fix infinite loop in initializing the alarm

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: NAles Novak <alnovak@suse.cz>
Acked-by: NAlessandro Zummo <a.zummo@towertech.it>
Reported-by: NJiri Bohac <jbohac@suse.cz>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 3364d113
...@@ -292,7 +292,8 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) ...@@ -292,7 +292,8 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
dev_dbg(&rtc->dev, "alarm rollover: %s\n", "year"); dev_dbg(&rtc->dev, "alarm rollover: %s\n", "year");
do { do {
alarm->time.tm_year++; alarm->time.tm_year++;
} while (rtc_valid_tm(&alarm->time) != 0); } while (!is_leap_year(alarm->time.tm_year + 1900)
&& rtc_valid_tm(&alarm->time) != 0);
break; break;
default: default:
...@@ -300,7 +301,16 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) ...@@ -300,7 +301,16 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
} }
done: 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) int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册