From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: sashiko-reviews@lists.linux.dev
Cc: kr494167@gmail.com, linux-rtc@vger.kernel.org
Subject: Re: [PATCH v2] rtc: spacemit: handle regmap_test_bits() error return
Date: Fri, 24 Jul 2026 16:17:44 +0200 [thread overview]
Message-ID: <202607241417442690eba3@mail.local> (raw)
In-Reply-To: <20260724140633.8FED41F000E9@smtp.kernel.org>
On 24/07/2026 14:06:33+0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] The RTC time read retry loop in `p1_rtc_read_time` is vulnerable to a torn read (time corruption) if a time roll-over occurs during the register read.
> --
>
> --- Patch [1]: [PATCH v2] rtc: spacemit: handle regmap_test_bits() error return ---
> commit a044092d776fab1e96ae2f8b48ace64aa0ab2325
> Author: Surendra Singh Chouhan <kr494167@gmail.com>
>
> rtc: spacemit: handle regmap_test_bits() error return
>
> p1_rtc_read_time() called if (!regmap_test_bits(regmap, RTC_CTRL, RTC_EN))
> to check if the RTC was enabled. This evaluates negative error codes as
> boolean false, causing read failures to be ignored. Fix this by capturing
> the return value of regmap_test_bits() and returning the error code.
>
> > diff --git a/drivers/rtc/rtc-spacemit-p1.c b/drivers/rtc/rtc-spacemit-p1.c
> > index 43ab62494bb4b..1de7bd995d296 100644
> > --- a/drivers/rtc/rtc-spacemit-p1.c
> > +++ b/drivers/rtc/rtc-spacemit-p1.c
> > @@ -57,8 +57,9 @@ static int p1_rtc_read_time(struct device *dev, struct rtc_time *t)
> > u8 time[6];
> > int ret;
> >
> > - if (!regmap_test_bits(regmap, RTC_CTRL, RTC_EN))
> > - return -EINVAL; /* RTC is disabled */
> > + ret = regmap_test_bits(regmap, RTC_CTRL, RTC_EN);
> > + if (ret <= 0)
> > + return ret ?: -EINVAL; /* RTC is disabled or error */
> >
> > ret = regmap_bulk_read(regmap, RTC_TIME, time, sizeof(time));
> > if (ret)
> > return ret;
> >
> > do {
> > seconds = time[0];
> > ret = regmap_bulk_read(regmap, RTC_TIME, time, sizeof(time));
> > if (ret)
> > return ret;
> > } while (time[0] != seconds && --count);
>
> [Severity: High]
> This is a pre-existing issue, but does this loop correctly detect time
> roll-overs that happen during the read?
>
> If a time roll-over occurs during the second regmap_bulk_read() in
> p1_rtc_read_time(), specifically after reading time[0] (seconds) but before
> reading higher units, time[0] will match the seconds from the previous read.
>
> This would cause the loop to terminate early and accept the newly read time
> array.
>
> Could this return a torn time from the RTC (for example, 14:00:59 instead of
> 13:59:59 or 14:00:00)?
>
While this is a valid concern, I guess this RTC latches the registers
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
prev parent reply other threads:[~2026-07-24 14:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 13:58 [PATCH v2] rtc: spacemit: handle regmap_test_bits() error return kr494167
2026-07-24 13:58 ` kr494167
2026-07-24 14:06 ` sashiko-bot
2026-07-24 14:17 ` Alexandre Belloni [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=202607241417442690eba3@mail.local \
--to=alexandre.belloni@bootlin.com \
--cc=kr494167@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.