summaryrefslogtreecommitdiff
path: root/drivers/rtc/rtc-wilco-ec.c
diff options
context:
space:
mode:
authorNick Crews <ncrews@chromium.org>2019-10-04 17:26:08 +0300
committerAlexandre Belloni <alexandre.belloni@bootlin.com>2019-10-14 18:49:17 +0300
commit9aa0d0be3856749c3be08089fe12a1f4494a030b (patch)
tree617da4fb8a41edf387b1774620ca9dc945d12e9e /drivers/rtc/rtc-wilco-ec.c
parent147dae76dbb9b20ba48385911c6fc04bf038a64a (diff)
downloadlinux-9aa0d0be3856749c3be08089fe12a1f4494a030b.tar.xz
rtc: wilco-ec: Handle reading invalid times
If the RTC HW returns an invalid time, the rtc_year_days() call would crash. This patch adds error logging in this situation, and removes the tm_yday and tm_wday calculations. These fields should not be relied upon by userspace according to man rtc, and thus we don't need to calculate them. Signed-off-by: Nick Crews <ncrews@chromium.org> Reviewed-by: Daniel Campello <campello@chromium.org> Link: https://lore.kernel.org/r/20191004142608.170159-1-ncrews@chromium.org Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Diffstat (limited to 'drivers/rtc/rtc-wilco-ec.c')
-rw-r--r--drivers/rtc/rtc-wilco-ec.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/drivers/rtc/rtc-wilco-ec.c b/drivers/rtc/rtc-wilco-ec.c
index 8ad4c4e6d557..ff46066a68a4 100644
--- a/drivers/rtc/rtc-wilco-ec.c
+++ b/drivers/rtc/rtc-wilco-ec.c
@@ -110,10 +110,12 @@ static int wilco_ec_rtc_read(struct device *dev, struct rtc_time *tm)
tm->tm_mday = rtc.day;
tm->tm_mon = rtc.month - 1;
tm->tm_year = rtc.year + (rtc.century * 100) - 1900;
- tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year);
+ /* Ignore other tm fields, man rtc says userspace shouldn't use them. */
- /* Don't compute day of week, we don't need it. */
- tm->tm_wday = -1;
+ if (rtc_valid_tm(tm)) {
+ dev_err(dev, "Time from RTC is invalid: %ptRr\n", tm);
+ return -EIO;
+ }
return 0;
}