OSDN Git Service

rtc: stm32: fix issues of stm32_rtc_valid_alrm function
authorValentin Caron <valentin.caron@foss.st.com>
Wed, 5 Jul 2023 17:43:56 +0000 (19:43 +0200)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Thu, 27 Jul 2023 21:03:34 +0000 (23:03 +0200)
commit46828a5f89044b8e057f6bbb50ae2bac926a0fa2
treecb4c6df28593e63df98fb226fa3da34df28f2673
parentfb9a7e5360dc8089097337a9685f6fed350a310f
rtc: stm32: fix issues of stm32_rtc_valid_alrm function

stm32_rtc_valid_alrm function has some issues :
- arithmetical operations are impossible on BCD values
- "cur_mon + 1" can overflow
- the use case with the next month, the same day/hour/minutes went wrong

To solve that, we prefer to use timestamp comparison.
e.g. : On 5 Dec. 2021, the alarm limit is 5 Jan. 2022 (+31 days)
       On 31 Jan 2021, the alarm limit is 28 Feb. 2022 (+28 days)

Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
Link: https://lore.kernel.org/r/20230705174357.353616-7-valentin.caron@foss.st.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/rtc/rtc-stm32.c