Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Ales Novak <alnovak@suse.cz>
Acked-by: Alessandro Zummo <a.zummo@towertech.it>
Reported-by: Jiri Bohac <jbohac@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Ales Novak and committed by
Linus Torvalds
ee1d9014 3364d113

+12 -2
+12 -2
drivers/rtc/interface.c
··· 292 292 dev_dbg(&rtc->dev, "alarm rollover: %s\n", "year"); 293 293 do { 294 294 alarm->time.tm_year++; 295 - } while (rtc_valid_tm(&alarm->time) != 0); 295 + } while (!is_leap_year(alarm->time.tm_year + 1900) 296 + && rtc_valid_tm(&alarm->time) != 0); 296 297 break; 297 298 298 299 default: ··· 301 300 } 302 301 303 302 done: 304 - return 0; 303 + err = rtc_valid_tm(&alarm->time); 304 + 305 + if (err) { 306 + dev_warn(&rtc->dev, "invalid alarm value: %d-%d-%d %d:%d:%d\n", 307 + alarm->time.tm_year + 1900, alarm->time.tm_mon + 1, 308 + alarm->time.tm_mday, alarm->time.tm_hour, alarm->time.tm_min, 309 + alarm->time.tm_sec); 310 + } 311 + 312 + return err; 305 313 } 306 314 307 315 int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)