rtc: fix readback from /sys/class/rtc/rtc?/wakealarm
Fix readback of RTC alarms on platforms which return -1 in
non-hardware-supported RTC alarm fields.
To fill in the missing (-1) values, we grab an RTC timestamp along with the
RTC alarm value, and use the timestamp fields to populate the missing alarm
fields.
To counter field-wrap races (since the timestamp and alarm are not read
together atomically), we read the RTC timestamp both before and after
reading the RTC alarm value, and then check for wrapped fields --> if any
have wrapped, we know we have a possible inconsistency, so we loop and
reread the timestamp and alarm again.
Wrapped fields in the RTC timestamps are an issue because rtc-cmos.c, for
example, also gets/uses an RTC timestamp internally while fetching the RTC
alarm. If our timestamp here wasn't the same (minutes and higher) as what
was used internally there, then we might end up populating the -1 fields
with inconsistent values.
This fixes readbacks from /sys/class/rtc/rtc?/wakealarm, as well as other
code paths which call rtc_read_alarm().
Signed-off-by: Mark Lord <mlord@pobox.com> Cc: David Brownell <david-b@pacbell.net> Cc: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>