possible off-by-one error on month counting in rtc rv8803 driver

Oliver Graute
2022-04-25T12:58:06Z

Hello,

I stumbled across the following possible off-by-one error in counting the
month in RTC driver rv8803.

I'am using struct rtc_time to define a EOL date for my U-Boots. So after
this date U-Boot stops booting by reading the RTC before with rtc_get().
I'am using the same EOL code for two different imx boards with different
RTCs and therefore different RTC drivers. On both boards I have set the
same EOL date.

So the EOL Date is 25.09.2022 23:59:59

The board with rv3029 stopps booting on 26.09.2022 0:00:00
The board with rv8803 stopps booting on 26.08.2022 0:00:00

U-Boot Code:
(drivers/rtc/rv3029.c)

v3029_rtc_set()
...
regs[RV3029_W_MONTHS - RV3029_W_SEC] = bin2bcd(tm->tm_mon + 1);
...

rv3029_rtc_get()
...
tm->tm_mon = bcd2bin(regs[RV3029_W_MONTHS - RV3029_W_SEC]) - 1;
...

(drivers/rtc/rv8803.c)
rv8803_rtc_set()
...
buf[RTC_MON_REG_ADDR] = bin2bcd(tm->tm_mon)
...

rv8803_rtc_get()
...
tm->tm_mon = bcd2bin(buf[RTC_MON_REG_ADDR] & 0x1F);
...

I assume that the error is here and increase and decrease by one is also
required here like in the Linux driver code for RTC 8803.

Linux Code:

rv3029_set_time()
...
regs[RV3029_W_MONTHS - RV3029_W_SEC] = bin2bcd(tm->tm_mon + 1);
...

rv3029_read_time()
...
tm->tm_mon = bcd2bin(regs[RV3029_W_MONTHS - RV3029_W_SEC]) - 1;
...

rv8803_set_time()
...
date[RV8803_MONTH] = bin2bcd(tm->tm_mon + 1);
...

rv8803_get_time()
...
tm->tm_mon = bcd2bin(date[RV8803_MONTH] & 0x1f) - 1;
...

Can someone verify and comment on this. Then I would prepare a patch
later on.

Best Regards,

Oliver