Re: [PATCH v3 03/12] rtc: rzn1: fix weekday underflow when alarm crosses month boundary
Wolfram Sang <[email protected]>
| Newsgroups | org.kernel.vger.linux-renesas-soc,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-kernel,org.kernel.vger.linux-rtc,org.kernel.vger.stable |
|---|---|
| Message-ID | <aoQvrL8cnnK7uxqw@ninjato> |
On Mon, Jul 06, 2026 at 06:51:29PM +0100, Prabhakar wrote: > From: Lad Prabhakar <[email protected]> > > In rzn1_rtc_set_alarm(), the driver attempts to calculate the weekday > for an alarm by computing the day delta between the alarm time and the > current time: > > days_ahead = tm->tm_mday - tm_now.tm_mday; > wday = (tm_now.tm_wday + days_ahead) % 7; > > However, if an alarm is scheduled for the beginning of the next month > while the current time is at the end of the month (e.g., current day is > 31, alarm day is 1), `tm->tm_mday - tm_now.tm_mday` results in a negative > value (-30). Since `days_ahead` is an unsigned int, this underflows to a > large positive number, leading to an incorrect `wday` being written to > the RZN1_RTC_ALW register. As a result, the alarm fails to fire. > > Fix this by utilizing the already computed `alarm` time64_t timestamp. > Convert it back into an rtc_time struct via rtc_time64_to_tm(), which > automatically handles month boundaries and correctly populates the > `tm_wday` field. > > Fixes: b5ad1bf00d2c4 ("rtc: rzn1: Add alarm support") > Cc: [email protected] > Signed-off-by: Lad Prabhakar <[email protected]> These messages look a bit LLM-generated. Is this true? What about the code? > - days_ahead = tm->tm_mday - tm_now.tm_mday; > - wday = (tm_now.tm_wday + days_ahead) % 7; > + rtc_time64_to_tm(alarm, &alarm_tm); This conversion is superfluous, we already have 'tm'? So, I think we can skip the whole conversion block here and use? writel(BIT(tm->tm_wday), rtc->base + RZN1_RTC_ALW); Only lightly tested, please double check.
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEOZGx6rniZ1Gk92RdFA3kzBSgKbYFAmqEL6wACgkQFA3kzBSg KbbdEQ//X7ob1iohhSuIpEda7+mX2iYuHaEJ6g3q4Wapr8DOqaW/F1NHNGPoAkrh k2ih3YYX1XgjAx9he3kiprn9eJwzP7p9BU1EljIhuLfL5gtzLSuFWx1y8FZom3VY caTFfLU1t206Ly1WykSNWYsXI9hX7DOY1mRobv5XhSDWBtSUt6L0ezlYsusrcpG3 9ydizeH9/jXg6vpDBCGl3tbsJILtlnuSqZUXJb4YuO5EHkVV4geawAK28YWaCoLm sDYZkx9Ww8sA/m37DGPD6aKhxcT8BAxoaGTkct90RvwbOxmtS0gljL184No0OWxo UyCzWWBAqOunVZeqMhZ+26MDUHnmMrc5WPj/82AQvylrj7kawK1xJV37fVdCVtaU OZtNPj/YE7z3QaE/af7tvXm9frb4hSF5iYpdD7hvqISPt3/qtxmfW6V8dInVeg+Y 6AZ0K1iFQ7378YI32Z09XmpdyfcWCWNfMRPdyCAdKenlQW6QUERtUxTFWHOuWWWj ujqVaz1XCpdhI8fJwV7+mBuzJJjpjTY+azFbjrJA0qDu6AVs2gIjTs4QqBKIzxZj IDaRXOUchOqii5qVAeBfLZPg1YWXyuXA5b/kWpq3c9dyEzGiTFmmy/yW4sM0+Wrk eYpV4g5vk9/jJQh+pthi78VJ21rhGJRghAB6peP6C87ZeESWSHE= =KqXE -----END PGP SIGNATURE-----