From: sashiko-bot@kernel.org
To: "Fil Dunsky" <filipp.dunsky@gmail.com>
Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org,
"Alexandre Belloni" <alexandre.belloni@bootlin.com>
Subject: Re: [PATCH v5 2/3] rtc: Add Cortina Systems CS7542 RTC driver
Date: Tue, 01 Dec 2026 05:48:44 +0000 [thread overview]
Message-ID: <sashiko-outbox-242634@kernel.org> (raw)
In-Reply-To: <20261201-b4-cs7542-rtc-v5-2-4a86460e1fb5@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] rtc: cs75xx: g2_rtc_probe() omits range_min =
RTC_TIMESTAMP_BEGIN_0000
- [Medium] rtc: cs75xx: g2_rtc_gettime() calls rtc_valid_tm() before
core validation
--
commit a8e8adc4666286ba8c3135f712792dd1734294d1
Author: Fil Dunsky <filipp.dunsky@gmail.com>
rtc: Add Cortina Systems CS7542 RTC driver
This commit adds an RTC driver for the Cortina Systems CS7542 SoC with
four-digit BCD year decoding and read/set calendar callbacks.
> diff --git a/drivers/rtc/rtc-cs75xx.c b/drivers/rtc/rtc-cs75xx.c
> new file mode 100644
> index 0000000000000..7746fa689a7b3
> --- /dev/null
> +++ b/drivers/rtc/rtc-cs75xx.c
[ ... ]
> +static int g2_rtc_gettime(struct device *dev, struct rtc_time *tm)
> +{
> + struct g2_rtc *p = dev_get_drvdata(dev);
> + u32 year, ctrl;
> + u8 sec, min, hour, day, mon;
> + int ret, retry;
> +
> + ctrl = g2_rtc_readb(p, G2_RTC_RTCCON);
> + if (!(ctrl & G2_RTC_RTCCON_RTCEN) || (ctrl & G2_RTC_RTCCON_CLKRST))
> + return -EINVAL;
> +
> + for (retry = 0; retry < 3; retry++) {
> + sec = g2_rtc_readb(p, G2_RTC_RTCSEC);
> + min = g2_rtc_readb(p, G2_RTC_RTCMIN);
> + hour = g2_rtc_readb(p, G2_RTC_RTCHOUR);
> + day = g2_rtc_readb(p, G2_RTC_RTCDATE);
> + mon = g2_rtc_readb(p, G2_RTC_RTCMON);
> + year = g2_rtc_readl(p, G2_RTC_RTCYEAR) & 0xffff;
> + if (sec == g2_rtc_readb(p, G2_RTC_RTCSEC)) {
> + if (!bcd_is_valid(sec) || !bcd_is_valid(min) ||
> + !bcd_is_valid(hour) || !bcd_is_valid(day) ||
> + !bcd_is_valid(mon) || !bcd_is_valid(year & 0xff) ||
> + !bcd_is_valid(year >> 8))
> + return -EINVAL;
> +
> + tm->tm_sec = bcd2bin(sec);
> + tm->tm_min = bcd2bin(min);
> + tm->tm_hour = bcd2bin(hour);
> + tm->tm_mday = bcd2bin(day);
> + tm->tm_mon = bcd2bin(mon) - 1;
> + tm->tm_year = bcd2bin(year & 0xff) +
> + bcd2bin(year >> 8) * 100 - 1900;
> + ret = rtc_valid_tm(tm);
> + if (ret)
> + return ret;
> + rtc_time64_to_tm(rtc_tm_to_time64(tm), tm);
> + return 0;
[Severity: Medium]
As reported by Alexandre Belloni on v2 [1], should g2_rtc_gettime() leave
rtc_valid_tm() validation to the RTC core instead of calling it and doing a
rtc_time64_to_tm(rtc_tm_to_time64(tm), tm) round-trip here?
__rtc_read_time() applies rtc_add_offset() after .read_time() returns and
then calls rtc_valid_tm(tm) itself, and the core does not require .read_time
callbacks to populate tm_wday or tm_yday. Validating tm inside
g2_rtc_gettime() rejects pre-1970 raw hardware dates with -EINVAL before
__rtc_read_time() can apply rtc_add_offset(), and also contradicts the commit
message ("Let the RTC core validate calendar fields").
[ ... ]
> +static int g2_rtc_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct g2_rtc *p;
> +
> + p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL);
> + if (!p)
> + return -ENOMEM;
> +
> + p->base = devm_platform_ioremap_resource(pdev, 0);
> + if (IS_ERR(p->base))
> + return PTR_ERR(p->base);
> +
> + platform_set_drvdata(pdev, p);
> +
> + p->rtc = devm_rtc_allocate_device(dev);
> + if (IS_ERR(p->rtc))
> + return PTR_ERR(p->rtc);
> + p->rtc->ops = &g2_rtcops;
> + p->rtc->range_max = RTC_TIMESTAMP_END_9999;
> +
> + return devm_rtc_register_device(p->rtc);
> +}
[Severity: Medium]
As reported by Alexandre Belloni on v2 [2], should g2_rtc_probe() also set
p->rtc->range_min = RTC_TIMESTAMP_BEGIN_0000?
Leaving range_min at 0 causes /sys/class/rtc/rtcN/range and
rtc_device_get_offset() to treat 1970-01-01 rather than 0000-01-01 as the
hardware lower bound, and contradicts the third paragraph of the commit
message ("Describe the physical 0000-9999 calendar with
RTC_TIMESTAMP_BEGIN_0000 and RTC_TIMESTAMP_END_9999").
[1] https://lore.kernel.org/r/202611232056209fabb078@mail.local
[2] https://lore.kernel.org/r/202611232056209fabb078@mail.local
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-b4-cs7542-rtc-v5-0-4a86460e1fb5@gmail.com?part=2
next prev parent reply other threads:[~2026-12-01 5:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 5:27 [PATCH v5 0/3] rtc: Add Cortina Systems CS7542 calendar clock support Fil Dunsky via B4 Relay
2026-12-01 5:27 ` [PATCH v5 1/3] dt-bindings: rtc: Add Cortina Systems CS7542 RTC Fil Dunsky via B4 Relay
2026-12-01 5:27 ` [PATCH v5 2/3] rtc: Add Cortina Systems CS7542 RTC driver Fil Dunsky via B4 Relay
2026-12-01 5:48 ` sashiko-bot [this message]
2026-12-01 5:27 ` [PATCH v5 3/3] MAINTAINERS: Add Cortina Systems CS7542 RTC support Fil Dunsky via B4 Relay
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=sashiko-outbox-242634@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alexandre.belloni@bootlin.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=filipp.dunsky@gmail.com \
--cc=linux-rtc@vger.kernel.org \
--cc=robh@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