Linux RTC
 help / color / mirror / Atom feed
* [rtc-linux] [PATCH v2] drivers/rtc/rtc-m41t80.c: avoid out of range year values
@ 2016-03-15 13:22 Stefan Christ
  2016-03-18 23:07 ` [rtc-linux] " Alexandre Belloni
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Christ @ 2016-03-15 13:22 UTC (permalink / raw)
  To: rtc-linux; +Cc: alexandre.belloni, a.zummo

Avoid saving an out of range year value to the RTC. Reading that value
from the RTC again returns a totally wrong time value. For Example

    $ timedatectl set-ntp no
    $ timedatectl set-time "1990-01-01 12:12:00"
    # Reboot
    rtc-m41t80 0-0068: setting system clock to 2090-01-01 12:12:35 UTC (3786955955)

Signed-off-by: Stefan Christ <s.christ@phytec.de>
---
v2: fix checkpatch warning in if
v2: align arguments in dev_err call
---
 drivers/rtc/rtc-m41t80.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index a82937e..d107a8e 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -176,7 +176,13 @@ static int m41t80_set_datetime(struct i2c_client *client, struct rtc_time *tm)
 		bin2bcd(tm->tm_mday) | (buf[M41T80_REG_DAY] & ~0x3f);
 	buf[M41T80_REG_MON] =
 		bin2bcd(tm->tm_mon + 1) | (buf[M41T80_REG_MON] & ~0x1f);
+
 	/* assume 20YY not 19YY */
+	if (tm->tm_year < 100 || tm->tm_year > 199) {
+		dev_err(&client->dev, "Year must be between 2000 and 2099. It's %d.\n",
+			tm->tm_year + 1900);
+		return -EINVAL;
+	}
 	buf[M41T80_REG_YEAR] = bin2bcd(tm->tm_year % 100);
 
 	if (i2c_transfer(client->adapter, msgs, 1) != 1) {
-- 
1.9.1

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

* [rtc-linux] Re: [PATCH v2] drivers/rtc/rtc-m41t80.c: avoid out of range year values
  2016-03-15 13:22 [rtc-linux] [PATCH v2] drivers/rtc/rtc-m41t80.c: avoid out of range year values Stefan Christ
@ 2016-03-18 23:07 ` Alexandre Belloni
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Belloni @ 2016-03-18 23:07 UTC (permalink / raw)
  To: Stefan Christ; +Cc: rtc-linux, a.zummo

On 15/03/2016 at 14:22:26 +0100, Stefan Christ wrote :
> Avoid saving an out of range year value to the RTC. Reading that value
> from the RTC again returns a totally wrong time value. For Example
> 
>     $ timedatectl set-ntp no
>     $ timedatectl set-time "1990-01-01 12:12:00"
>     # Reboot
>     rtc-m41t80 0-0068: setting system clock to 2090-01-01 12:12:35 UTC (3786955955)
> 
> Signed-off-by: Stefan Christ <s.christ@phytec.de>
> ---
> v2: fix checkpatch warning in if
> v2: align arguments in dev_err call
> ---
>  drivers/rtc/rtc-m41t80.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
Applied, thanks.

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

end of thread, other threads:[~2016-03-18 23:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-15 13:22 [rtc-linux] [PATCH v2] drivers/rtc/rtc-m41t80.c: avoid out of range year values Stefan Christ
2016-03-18 23:07 ` [rtc-linux] " Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox