drivers/rtc/rtc-m41t80.c: avoid out of range year values
PATCH 1/1 drivers/rtc/rtc-m41t80.c: avoid out of range year values
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 <[email protected]>
--- drivers/rtc/rtc-m41t80.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/rtc/rtc-m41t80.c +6 -0
@@ -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 (!(100 <= tm->tm_year && 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 ) {
Signature · 12 lines
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 [email protected]. For more options, visit https://groups.google.com/d/optout.
Hi,
Quoted 18 lines · Stefan Christ
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 <[email protected]>--- drivers/rtc/rtc-m41t80.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/rtc/rtc-m41t80.c +0
-0
drivers/rtc/rtc-m41t80.c static int m41t80_set_datetime(struct i2c_client *client, struct rtc_time *tm) · line 181
Quoted 6 lines
drivers/rtc/rtc-m41t80.c +2
-0@@ -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 (!(100 <= tm->tm_year && tm->tm_year <=199 )) {
This introduces a checkpatch warning, can you fix that and resend
drivers/rtc/rtc-m41t80.c static int m41t80_set_datetime(struct i2c_client *client, struct rtc_time *tm) · line 183
Quoted 2 lines
drivers/rtc/rtc-m41t80.c +2
-0+dev_err (&client->dev,"Year must be between 2000 and 2099. It's %d.\n" , + tm->tm_year +1900 );
This is not properly aligned.
Quoted 8 lines
drivers/rtc/rtc-m41t80.c +2
-0+return -EINVAL ; + } buf[M41T80_REG_YEAR ] =bin2bcd (tm->tm_year %100 );if (i2c_transfer (client->adapter, msgs,1 ) !=1 ) {Signature · 1 line
1.9.1
Signature · 14 lines
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 [email protected]. For more options, visit https://groups.google.com/d/optout.