Devicetree
 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 v6 2/4] rtc: pcf8525: Add NXP PCF8525 RTC driver
Date: Fri, 27 Nov 2026 08:56:19 +0000	[thread overview]
Message-ID: <sashiko-outbox-236926@kernel.org> (raw)
In-Reply-To: <20261127083807.2844507-3-shivprakash.gupta@nxp.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] rtc: pcf8525: premature and unmasked rtc_update_irq() in
  pcf8525_service_inta()
--

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

rtc: pcf8525: Add NXP PCF8525 RTC driver

This commit adds an RTC driver for the NXP PCF8525 I2C real-time clock
with alarm, timestamp capture, 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..06ff14a1dbe14
> --- /dev/null
> +++ b/drivers/rtc/rtc-pcf8525.c
> @@ -0,0 +1,931 @@

[ ... ]

> +static int pcf8525_service_inta(struct device *dev, struct pcf8525 *pcf8525,
> +				bool *handled)
> +{
> +	unsigned int ctrl2, ctrl4;
> +	int i, ret;
> +
> +	*handled = false;
> +
> +	/* Flags can be set again while INTA is low, so re-read until clean. */
> +	for (i = 0; i < PCF8525_IRQ_MAX_PASSES; i++) {
> +		ret = regmap_read(pcf8525->regmap, PCF8525_REG_CTRL2, &ctrl2);
> +		if (ret)
> +			return ret;
> +
> +		ret = regmap_read(pcf8525->regmap, PCF8525_REG_CTRL4, &ctrl4);
> +		if (ret)
> +			return ret;
> +
> +		if (!(ctrl2 & (PCF8525_CTRL2_AF | PCF8525_CTRL2_MSF)) &&
> +		    !(ctrl4 & PCF8525_CTRL4_TSF))
> +			return 0;
> +
> +		if (ctrl4 & PCF8525_CTRL4_TSF) {
> +			ret = pcf8525_handle_ts(dev, pcf8525);
> +			if (ret)
> +				return ret;
> +
> +			*handled = true;
> +		}
> +
> +		if (ctrl2 & PCF8525_CTRL2_AF) {
> +			ret = pcf8525_update_ctrl2(pcf8525, PCF8525_CTRL2_AF, 0);
> +			if (ret)
> +				return ret;
> +
> +			rtc_update_irq(pcf8525->rtc, 1, RTC_IRQF | RTC_AF);
> +			*handled = true;
> +		}

[ ... ]

> +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;
> +
> +	ret = devm_add_action_or_reset(dev, pcf8525_mask_inta, pcf8525);
> +	if (ret)
> +		return ret;
> +
> +	ret = pcf8525_unmask_irqs_inta(pcf8525, true);
> +	if (ret)
> +		return ret;

[ ... ]

> +	/* Wakeup must be set up before registering so wakealarm is exposed. */
> +	if (irq > 0 && !(client->flags & I2C_CLIENT_WAKE)) {
> +		ret = devm_device_init_wakeup(dev);
> +		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;
> +	}
> +
> +	ret = devm_rtc_register_device(pcf8525->rtc);

[Severity: Medium]
Can pcf8525_service_inta() call rtc_update_irq() during probe before
devm_rtc_register_device(), or when PCF8525_CTRL2_AIE is disabled?

In pcf8525_probe(), wakeup is enabled before pcf8525_setup_inta() runs.
If PCF8525_CTRL2_AF is already set when pcf8525_setup_inta() drains
pending flags, pcf8525_service_inta() calls rtc_update_irq(), which
calls pm_stay_awake(rtc->dev.parent) and queues rtc->irqwork
(rtc_timer_do_work()).  When PCF8525_SC_OSF is also set (such as after
power-on), rtc_timer_do_work() calls __rtc_read_time() ->
pcf8525_read_time(), gets -EINVAL, and returns early without calling
pm_relax(rtc->dev.parent), leaving the wakeup source active and blocking
system suspend.

When PCF8525_SC_OSF is clear, queuing rtc->irqwork and unmasking INTA in
pcf8525_setup_inta() before devm_rtc_register_device() races with
__devm_rtc_register_device():

CPU0                              kworker
pcf8525_probe()
  pcf8525_setup_inta()
    pcf8525_service_inta()
      rtc_update_irq()
        schedule_work(&rtc->irqwork)
                                  rtc_timer_do_work()
                                    /* timerqueue is still empty */
                                    rtc_alarm_disable(rtc)
  devm_rtc_register_device()
    rtc_device_get_offset()
    rtc_initialize_alarm()

rtc_timer_do_work() also reads rtc->offset_secs while
rtc_device_get_offset() initializes it without holding rtc->ops_lock,
and disables PCF8525_CTRL2_AIE in hardware before rtc_initialize_alarm()
imports an existing alarm into rtc->timerqueue.

In addition, pcf8525_alarm_irq_enable(dev, 0) only clears
PCF8525_CTRL2_AIE while leaving the per-field alarm enable bits active
in PCF8525_REG_ALM_SEC..YEAR, so the comparator still sets
PCF8525_CTRL2_AF on a match.  Because pcf8525_service_inta() does not
check PCF8525_CTRL2_AIE, a later timestamp interrupt (PCF8525_CTRL4_TSF)
on the shared INTA line triggers a spurious rtc_update_irq().

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

  reply	other threads:[~2026-11-27  8:56 UTC|newest]

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

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-236926@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