Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shiv Prakash Gupta" <shivprakash.gupta@nxp.com>,
	linux-rtc@vger.kernel.org, linux-hwmon@vger.kernel.org,
	linux-watchdog@vger.kernel.org, devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>
Subject: Re: [PATCH v5 2/4] rtc: pcf8525: Add NXP PCF8525 RTC driver
Date: Thu, 26 Nov 2026 07:30:40 +0000	[thread overview]
Message-ID: <sashiko-outbox-234957@kernel.org> (raw)
In-Reply-To: <20261126071124.2383368-3-shivprakash.gupta@nxp.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] rtc: pcf8525: devm_rtc_register_device() called before INTA
  setup in probe
--

commit ac013f157325db026a034ab7ceb349efee94dcf3
Author: Shiv Prakash Gupta <shivprakash.gupta@nxp.com>

rtc: pcf8525: Add NXP PCF8525 RTC driver

This commit adds an I2C RTC driver for the NXP PCF8525 with calendar,
alarm, timestamp capture, crystal aging offset, and backup switchover
support.

> diff --git a/drivers/rtc/rtc-pcf8525.c b/drivers/rtc/rtc-pcf8525.c
> new file mode 100644
> index 0000000000000..2b23b17d6750c
> --- /dev/null
> +++ b/drivers/rtc/rtc-pcf8525.c
[ ... ]
> +static ssize_t timestamp0_show(struct device *dev,
> +			       struct device_attribute *attr, char *buf)
> +{
> +	struct pcf8525 *pcf8525 = dev_get_drvdata(dev->parent);
> +	unsigned int ctrl4;
> +	time64_t ts = 0;
> +	int ret;
> +
> +	guard(mutex)(&pcf8525->ts_mutex);
> +
> +	if (pcf8525->irq_enabled) {
> +		if (!pcf8525->ts_valid)
> +			return 0;
> +
> +		ts = pcf8525->ts;
> +	} else {
> +		ret = regmap_read(pcf8525->regmap, PCF8525_REG_CTRL4, &ctrl4);
> +		if (ret)
> +			return ret;
> +
> +		if (!(ctrl4 & PCF8525_CTRL4_TSF))
> +			return 0;
> +
> +		ret = pcf8525_ts_read(pcf8525, PCF8525_REG_TS1_SEC, &ts);
> +		if (ret)
> +			return ret == -ENODATA ? 0 : ret;
> +	}
> +
> +	return sysfs_emit(buf, "%lld\n",
> +			  (long long)pcf8525_ts_apply_offset(pcf8525, ts));
> +}
[ ... ]
> +static int pcf8525_setup_inta(struct i2c_client *client,
> +			      struct pcf8525 *pcf8525, int irq)
> +{
> +	struct device *dev = &client->dev;
> +	bool handled;
> +	int ret;
> +
> +	/* INTA is still masked, so drain all stale flags before enabling it. */
> +	ret = pcf8525_service_inta(dev, pcf8525, &handled);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "failed to drain pending INTA\n");
> +
> +	ret = devm_request_threaded_irq(dev, irq, NULL, pcf8525_irq,
> +					IRQF_ONESHOT, dev_name(dev), dev);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "failed to request INTA IRQ\n");
> +
> +	pcf8525->irq_enabled = true;
[ ... ]
> +static int pcf8525_probe(struct i2c_client *client)
> +{
[ ... ]
> +	ret = devm_rtc_register_device(pcf8525->rtc);
> +	if (ret)
> +		return ret;
> +
> +	if (irq > 0) {
> +		ret = pcf8525_setup_inta(client, pcf8525, irq);
> +		if (ret)
> +			return ret;
> +	} else if (wakeup) {
> +		ret = pcf8525_setup_wakeup_only(dev, pcf8525);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	return 0;
> +}

[Severity: Medium]
Should pcf8525_setup_inta() and pcf8525_setup_wakeup_only() run before
devm_rtc_register_device()?

Registering the RTC device first exposes the sysfs attributes and /dev/rtcX
before pending INTA flags are drained and before pcf8525->irq_enabled is
set:

CPU0                              CPU1
pcf8525_probe()
  devm_rtc_register_device()
  pcf8525_setup_inta()
    pcf8525_service_inta()
      pcf8525_handle_ts()
        lock(&pcf8525->ts_mutex)
        regmap_write(CTRL4, 0)
        pcf8525->ts_valid = true
        unlock(&pcf8525->ts_mutex)
                                  timestamp0_show()
                                    lock(&pcf8525->ts_mutex)
                                    if (pcf8525->irq_enabled) // false
                                    regmap_read(CTRL4, &ctrl4)
                                    !(ctrl4 & TSF) -> returns 0
    devm_request_threaded_irq()
    pcf8525->irq_enabled = true

Because pcf8525_handle_ts() clears PCF8525_CTRL4_TSF in hardware and caches
the timestamp in pcf8525->ts while pcf8525->irq_enabled is still false, a
concurrent reader of timestamp0 takes the polling branch, sees TSF cleared,
and returns 0 instead of the captured timestamp.

In the wakeup-only path, pcf8525_setup_wakeup_only() also clears
PCF8525_CTRL2_AF and unmasks INTA after devm_rtc_register_device() has
already read the alarm state, and on driver unbind devres masks INTA and
frees the IRQ before unregistering the RTC device while
pcf8525->irq_enabled remains true.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126071124.2383368-1-shivprakash.gupta@nxp.com?part=2

  reply	other threads:[~2026-11-26  7:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  7:11 [PATCH v5 0/4] rtc: Add NXP PCF8525 RTC support Shiv Prakash Gupta
2026-11-26  7:11 ` [PATCH v5 1/4] dt-bindings: rtc: Add NXP PCF8525 RTC Shiv Prakash Gupta
2026-11-26  7:11 ` [PATCH v5 2/4] rtc: pcf8525: Add NXP PCF8525 RTC driver Shiv Prakash Gupta
2026-11-26  7:30   ` sashiko-bot [this message]
2026-11-26  7:11 ` [PATCH v5 3/4] rtc: pcf8525: Add watchdog support Shiv Prakash Gupta
2026-11-26  7:26   ` sashiko-bot
2026-11-26  7:11 ` [PATCH v5 4/4] rtc: pcf8525: Add temperature sensor support via hwmon Shiv Prakash Gupta
2026-11-26  7:30 ` [PATCH v5 0/4] rtc: Add NXP PCF8525 RTC support sashiko-bot

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-234957@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shivprakash.gupta@nxp.com \
    /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