mirror of
https://github.com/torvalds/linux.git
synced 2026-09-23 13:14:02 +02:00
rtc: rzn1: Fix weekday underflow when alarm crosses month boundary
rzn1_rtc_set_alarm() calculates the alarm weekday from the difference
between the alarm day and the current day of the month. When the alarm
crosses a month boundary, this difference can become negative. Since
days_ahead is unsigned, it underflows and results in an incorrect
weekday being programmed into RZN1_RTC_ALW.
The RTC core already provides a fully populated struct rtc_time for
the alarm, including the correct tm_wday. Use tm->tm_wday directly
instead of recalculating the weekday from the day-of-month.
This avoids the underflow and ensures alarms scheduled across a month
boundary use the correct weekday.
Fixes: b5ad1bf00d ("rtc: rzn1: Add alarm support")
Cc: stable@vger.kernel.org
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Suggested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Link: https://patch.msgid.link/20260821211032.13554-4-prabhakar.mahadev-lad.rj@bp.renesas.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
This commit is contained in:
parent
708546aa39
commit
022a2839a5
|
|
@ -261,7 +261,6 @@ static int rzn1_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
|
|||
struct rzn1_rtc *rtc = dev_get_drvdata(dev);
|
||||
struct rtc_time *tm = &alrm->time, tm_now;
|
||||
unsigned long alarm, farest;
|
||||
unsigned int days_ahead, wday;
|
||||
int ret;
|
||||
|
||||
ret = rzn1_rtc_read_time(dev, &tm_now);
|
||||
|
|
@ -274,13 +273,9 @@ static int rzn1_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
|
|||
if (time_after(alarm, farest))
|
||||
return -ERANGE;
|
||||
|
||||
/* Convert alarm day into week day */
|
||||
days_ahead = tm->tm_mday - tm_now.tm_mday;
|
||||
wday = (tm_now.tm_wday + days_ahead) % 7;
|
||||
|
||||
writel(bin2bcd(tm->tm_min), rtc->base + RZN1_RTC_ALM);
|
||||
writel(bin2bcd(tm->tm_hour), rtc->base + RZN1_RTC_ALH);
|
||||
writel(BIT(wday), rtc->base + RZN1_RTC_ALW);
|
||||
writel(BIT(tm->tm_wday), rtc->base + RZN1_RTC_ALW);
|
||||
|
||||
rtc->tm_alarm = alrm->time;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user