Linux RTC
 help / color / mirror / Atom feed
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
To: Prabhakar <prabhakar.csengg@gmail.com>
Cc: Miquel Raynal <miquel.raynal@bootlin.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Magnus Damm <magnus.damm@gmail.com>,
	linux-rtc@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	Prabhakar <prabhakar.csengg+renesas@gmail.com>,
	Biju Das <biju.das.jz@bp.renesas.com>,
	Fabrizio Castro <fabrizio.castro.jz@renesas.com>,
	Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH v3 03/12] rtc: rzn1: fix weekday underflow when alarm crosses month boundary
Date: Tue, 18 Aug 2026 12:10:52 +0200	[thread overview]
Message-ID: <aoQvrL8cnnK7uxqw@ninjato> (raw)
In-Reply-To: <20260706175138.12587-4-prabhakar.mahadev-lad.rj@bp.renesas.com>

[-- Attachment #1: Type: text/plain, Size: 1693 bytes --]

On Mon, Jul 06, 2026 at 06:51:29PM +0100, Prabhakar wrote:
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> 
> 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: stable@vger.kernel.org
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

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.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2026-08-18 10:10 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-06 17:51 [PATCH v3 00/12] Add RTC support for Renesas RZ/T2H and RZ/N2H SoCs Prabhakar
2026-07-06 17:51 ` [PATCH v3 01/12] dt-bindings: rtc: renesas,rzn1-rtc: Add RZ/T2H and RZ/N2H support Prabhakar
2026-07-06 17:58   ` sashiko-bot
2026-08-18  7:42     ` Wolfram Sang
2026-08-18 14:32       ` Lad, Prabhakar
2026-07-06 17:51 ` [PATCH v3 02/12] rtc: rzn1: Handle EPROBE_DEFER for optional pps interrupt Prabhakar
2026-07-06 17:56   ` sashiko-bot
2026-08-18  7:43   ` Wolfram Sang
2026-07-06 17:51 ` [PATCH v3 03/12] rtc: rzn1: fix weekday underflow when alarm crosses month boundary Prabhakar
2026-07-06 18:00   ` sashiko-bot
2026-08-18 10:10   ` Wolfram Sang [this message]
2026-08-18 14:35     ` Lad, Prabhakar
2026-07-06 17:51 ` [PATCH v3 04/12] rtc: rzn1: Fix malformed MODULE_AUTHOR string Prabhakar
2026-07-06 17:53   ` sashiko-bot
2026-07-06 17:51 ` [PATCH v3 05/12] rtc: Kconfig: Broaden RTC_DRV_RZN1 dependency to ARCH_RENESAS Prabhakar
2026-07-06 17:54   ` sashiko-bot
2026-08-18 10:11   ` Wolfram Sang
2026-07-06 17:51 ` [PATCH v3 06/12] rtc: rzn1: Fix alarm range check truncation on 32-bit systems Prabhakar
2026-07-06 18:04   ` sashiko-bot
2026-08-18 10:32   ` Wolfram Sang
2026-07-06 17:51 ` [PATCH v3 07/12] rtc: rzn1: Replace remove callback with devm_add_action_or_reset() Prabhakar
2026-07-06 17:58   ` sashiko-bot
2026-08-18 10:37   ` Wolfram Sang
2026-07-06 17:51 ` [PATCH v3 08/12] rtc: rzn1: Dynamically calculate synchronization delay based on clock rate Prabhakar
2026-07-06 17:58   ` sashiko-bot
2026-08-18 10:49   ` Wolfram Sang
2026-08-18 14:37     ` Lad, Prabhakar
2026-07-06 17:51 ` [PATCH v3 09/12] rtc: rzn1: Use temporary variable for struct device Prabhakar
2026-07-06 17:56   ` sashiko-bot
2026-08-18 10:51     ` Wolfram Sang
2026-08-18 14:58       ` Lad, Prabhakar
2026-07-06 17:51 ` [PATCH v3 10/12] rtc: rzn1: Consistently use dev_err_probe() Prabhakar
2026-07-06 17:55   ` sashiko-bot
2026-07-06 17:51 ` [PATCH v3 11/12] rtc: rzn1: use FIELD_PREP/FIELD_GET and GENMASK for register access Prabhakar
2026-07-06 17:57   ` sashiko-bot
2026-08-18 11:19   ` Wolfram Sang
2026-07-06 17:51 ` [PATCH v3 12/12] rtc: rzn1: Add support for Renesas RZ/T2H and RZ/N2H SoCs Prabhakar
2026-07-06 18:03   ` sashiko-bot
2026-08-18 11:28     ` Wolfram Sang
2026-08-03 12:47 ` [PATCH v3 00/12] Add RTC " Lad, Prabhakar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aoQvrL8cnnK7uxqw@ninjato \
    --to=wsa+renesas@sang-engineering.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=fabrizio.castro.jz@renesas.com \
    --cc=geert+renesas@glider.be \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=prabhakar.csengg+renesas@gmail.com \
    --cc=prabhakar.csengg@gmail.com \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=robh@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox