Linux-RTC Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v4] rtc: wilco-ec: Handle reading invalid times
@ 2019-10-04 14:26 Nick Crews
  2019-10-08 22:26 ` Daniel Campello
  2019-10-14 15:50 ` Alexandre Belloni
  0 siblings, 2 replies; 3+ messages in thread
From: Nick Crews @ 2019-10-04 14:26 UTC (permalink / raw)
  To: Alexandre Belloni, Alessandro Zummo
  Cc: linux-rtc, linux-kernel, Pavel Machek, enric.balletbo, bleung,
	dlaurie, djkurtz, dtor, campello, Nick Crews

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>
---
 drivers/rtc/rtc-wilco-ec.c | 8 +++++---
 1 file 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;
 }
-- 
2.21.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] rtc: wilco-ec: Handle reading invalid times
  2019-10-04 14:26 [PATCH v4] rtc: wilco-ec: Handle reading invalid times Nick Crews
@ 2019-10-08 22:26 ` Daniel Campello
  2019-10-14 15:50 ` Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Campello @ 2019-10-08 22:26 UTC (permalink / raw)
  To: Nick Crews
  Cc: Alexandre Belloni, Alessandro Zummo, linux-rtc, linux-kernel,
	Pavel Machek, enric.balletbo, bleung, dlaurie, djkurtz, dtor

LGTM.
Reviewed-by: Daniel Campello <campello@chromium.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] rtc: wilco-ec: Handle reading invalid times
  2019-10-04 14:26 [PATCH v4] rtc: wilco-ec: Handle reading invalid times Nick Crews
  2019-10-08 22:26 ` Daniel Campello
@ 2019-10-14 15:50 ` Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2019-10-14 15:50 UTC (permalink / raw)
  To: Nick Crews
  Cc: Alessandro Zummo, linux-rtc, linux-kernel, Pavel Machek,
	enric.balletbo, bleung, dlaurie, djkurtz, dtor, campello

On 04/10/2019 08:26:08-0600, Nick Crews wrote:
> 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>
> ---
>  drivers/rtc/rtc-wilco-ec.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
Applied, thanks.

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-04 14:26 [PATCH v4] rtc: wilco-ec: Handle reading invalid times Nick Crews
2019-10-08 22:26 ` Daniel Campello
2019-10-14 15:50 ` Alexandre Belloni

Linux-RTC Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-rtc/0 linux-rtc/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-rtc linux-rtc/ https://lore.kernel.org/linux-rtc \
		linux-rtc@vger.kernel.org
	public-inbox-index linux-rtc

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-rtc


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git