* [PATCH] rtc: ds1347: fix value written to century register
@ 2022-10-27 16:32 Ian Abbott
2022-11-04 13:29 ` Ian Abbott
2022-11-14 22:50 ` Alexandre Belloni
0 siblings, 2 replies; 3+ messages in thread
From: Ian Abbott @ 2022-10-27 16:32 UTC (permalink / raw)
To: linux-rtc; +Cc: Alessandro Zummo, Alexandre Belloni, Ian Abbott, stable
In `ds1347_set_time()`, the wrong value is being written to the
`DS1347_CENTURY_REG` register. It needs to be converted to BCD. Fix
it.
Fixes: 147dae76dbb9 ("rtc: ds1347: handle century register")
Cc: <stable@vger.kernel.org> # v5.5+
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
drivers/rtc/rtc-ds1347.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/rtc/rtc-ds1347.c b/drivers/rtc/rtc-ds1347.c
index 157bf5209ac4..a40c1a52df65 100644
--- a/drivers/rtc/rtc-ds1347.c
+++ b/drivers/rtc/rtc-ds1347.c
@@ -112,7 +112,7 @@ static int ds1347_set_time(struct device *dev, struct rtc_time *dt)
return err;
century = (dt->tm_year / 100) + 19;
- err = regmap_write(map, DS1347_CENTURY_REG, century);
+ err = regmap_write(map, DS1347_CENTURY_REG, bin2bcd(century));
if (err)
return err;
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] rtc: ds1347: fix value written to century register
2022-10-27 16:32 [PATCH] rtc: ds1347: fix value written to century register Ian Abbott
@ 2022-11-04 13:29 ` Ian Abbott
2022-11-14 22:50 ` Alexandre Belloni
1 sibling, 0 replies; 3+ messages in thread
From: Ian Abbott @ 2022-11-04 13:29 UTC (permalink / raw)
To: linux-rtc; +Cc: Alessandro Zummo, Alexandre Belloni, stable
On 27/10/2022 17:32, Ian Abbott wrote:
> In `ds1347_set_time()`, the wrong value is being written to the
> `DS1347_CENTURY_REG` register. It needs to be converted to BCD. Fix
> it.
>
> Fixes: 147dae76dbb9 ("rtc: ds1347: handle century register")
> Cc: <stable@vger.kernel.org> # v5.5+
> Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
> ---
> drivers/rtc/rtc-ds1347.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/rtc/rtc-ds1347.c b/drivers/rtc/rtc-ds1347.c
> index 157bf5209ac4..a40c1a52df65 100644
> --- a/drivers/rtc/rtc-ds1347.c
> +++ b/drivers/rtc/rtc-ds1347.c
> @@ -112,7 +112,7 @@ static int ds1347_set_time(struct device *dev, struct rtc_time *dt)
> return err;
>
> century = (dt->tm_year / 100) + 19;
> - err = regmap_write(map, DS1347_CENTURY_REG, century);
> + err = regmap_write(map, DS1347_CENTURY_REG, bin2bcd(century));
> if (err)
> return err;
>
I'm sure this isn't a commonly used driver, but I'd just like to mention
that I consider it critically broken without this bug fix. Any dates in
the 21st century written to the RTC end up being in the 15th century
inside the chip, and the kernel treats it as invalid when it is read
back. (The times are out of range of a 32-bit Unix time. I'm not sure
if 64-bit Unix times from the RTC before 1970 are supported or not.)
--
-=( Ian Abbott <abbotti@mev.co.uk> || MEV Ltd. is a company )=-
-=( registered in England & Wales. Regd. number: 02862268. )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] rtc: ds1347: fix value written to century register
2022-10-27 16:32 [PATCH] rtc: ds1347: fix value written to century register Ian Abbott
2022-11-04 13:29 ` Ian Abbott
@ 2022-11-14 22:50 ` Alexandre Belloni
1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2022-11-14 22:50 UTC (permalink / raw)
To: Ian Abbott, linux-rtc; +Cc: stable, Alessandro Zummo
On Thu, 27 Oct 2022 17:32:49 +0100, Ian Abbott wrote:
> In `ds1347_set_time()`, the wrong value is being written to the
> `DS1347_CENTURY_REG` register. It needs to be converted to BCD. Fix
> it.
>
>
Applied, thanks!
[1/1] rtc: ds1347: fix value written to century register
commit: c397361d7339fa3a2949758ffd5298231fb43173
Best regards,
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-14 22:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-27 16:32 [PATCH] rtc: ds1347: fix value written to century register Ian Abbott
2022-11-04 13:29 ` Ian Abbott
2022-11-14 22:50 ` Alexandre Belloni
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.