Linux RTC
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: alexandre.belloni@bootlin.com
Cc: "Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	linux-rtc@vger.kernel.org
Subject: Re: [PATCH] rtc: ftrtc010: fix cast
Date: Mon, 05 Oct 2026 11:11:13 +0000	[thread overview]
Message-ID: <20261005111114.34E2A1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20261005110638.156559-1-alexandre.belloni@bootlin.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] rtc: ftrtc010: broken operator precedence in offset calculation
--

commit d205fb0cae60ed15e7685f77950862e58120dd5a
Author: Alexandre Belloni <alexandre.belloni@bootlin.com>

rtc: ftrtc010: fix cast

This commit removes unnecessary casts to timeu64_t from the hour, min, and sec
registers during the calculation of time and offset, as they will rollover
before exceeding a 32-bit integer.

Link: https://patch.msgid.link/20261002105946.8rdteIpO7uWGEcTlS65F8iSi4gsRoXi2kgq8FTSaDPA@z/

> diff --git a/drivers/rtc/rtc-ftrtc010.c b/drivers/rtc/rtc-ftrtc010.c
> index b29c96be40f4a..5332451bdaa05 100644
> --- a/drivers/rtc/rtc-ftrtc010.c
> +++ b/drivers/rtc/rtc-ftrtc010.c

[ ... ]

> @@ -92,8 +92,7 @@ static int ftrtc010_rtc_set_time(struct device *dev, struct rtc_time *tm)
>  	hour = readl(rtc->rtc_base + FTRTC010_RTC_HOUR);
>  	day = readl(rtc->rtc_base + FTRTC010_RTC_DAYS);
>  
> -	offset = time - ((timeu64_t)day * 86400 + (timeu64_t)hour * 3600 +
> -			 (timeu64_t)min * 60 + (timeu64_t)sec);
> +	offset = time - (timeu64_t)day * 86400 + hour * 3600 + min * 60 + sec;

[Severity: High]
Could this change introduce an operator precedence issue?

Because the grouping parentheses around the time components were removed,
the expression evaluates strictly from left to right. This subtracts only
the days from the system time, and erroneously adds the hour, min, and sec
components instead of subtracting them.

When user-space programs or system time synchronizations invoke
ftrtc010_rtc_set_time(), this will predictably corrupt the stored hardware
time offset written to the FTRTC010_RTC_RECORD register.

>  
>  	writel(offset, rtc->rtc_base + FTRTC010_RTC_RECORD);
>  	writel(0x01, rtc->rtc_base + FTRTC010_RTC_CR);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261005110638.156559-1-alexandre.belloni@bootlin.com?part=1

      reply	other threads:[~2026-10-05 11:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-05 11:06 [PATCH] rtc: ftrtc010: fix cast alexandre.belloni
2026-10-05 11:11 ` sashiko-bot [this message]

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=20261005111114.34E2A1F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=linux-rtc@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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