Linux RTC
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Cong Nguyen" <congnt264@gmail.com>
Cc: linux-rtc@vger.kernel.org, Frank.Li@kernel.org,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	imx@lists.linux.dev
Subject: Re: [PATCH] rtc: mxc_v2: fix clk enable-count underflow warning in remove()
Date: Mon, 14 Sep 2026 13:48:26 +0000	[thread overview]
Message-ID: <20260914134826.EC26D1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260914132505.2356970-1-congnt264@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing cleanup for dev_pm_set_wake_irq() leading to a memory leak and dangling wake IRQ on probe failure or device removal.
- [High] Premature unprepare of the clock in remove() causes a use-after-disable race with devres-managed resources.
--

commit 3311fdd80d87e5108fcbeddc8974c58c3e0da127
Author: Cong Nguyen <congnt264@gmail.com>

rtc: mxc_v2: fix clk enable-count underflow warning in remove()

After probe, the clock is left prepared but disabled, so calling
clk_disable_unprepare() in remove() hits an already disabled warning.
This commit changes it to clk_unprepare() to match the probe-failure paths.

> diff --git a/drivers/rtc/rtc-mxc_v2.c b/drivers/rtc/rtc-mxc_v2.c
> index 570f27af4732e..ab2ab61017f57 100644
> --- a/drivers/rtc/rtc-mxc_v2.c
> +++ b/drivers/rtc/rtc-mxc_v2.c
> @@ -366,7 +366,7 @@ static void mxc_rtc_remove(struct platform_device *pdev)
>  {
>  	struct mxc_rtc_data *pdata = platform_get_drvdata(pdev);
>  
> -	clk_disable_unprepare(pdata->clk);
> +	clk_unprepare(pdata->clk);

[Severity: High]
This is a pre-existing issue, but does unpreparing the clock here cause a
use-after-disable race with devres-managed resources?

The IRQ handler is registered via devm_request_irq() in mxc_rtc_probe(),
which means it stays active after mxc_rtc_remove() returns. If an RTC
interrupt fires after the clock is unprepared (for example, during the
devres cleanup window), the interrupt handler mxc_rtc_interrupt() calls
clk_enable() on an unprepared clock:

drivers/rtc/rtc-mxc_v2.c:mxc_rtc_interrupt() {
    ...
    if (clk_enable(pdata->clk)) {
        spin_unlock(&pdata->lock);
        return IRQ_NONE;
    }
    ...
}

This can trigger a kernel warning for enabling an unprepared clock, and
cause the interrupt handler to return IRQ_NONE without clearing the hardware
status, which could lead to an interrupt storm.

[Severity: High]
This is a pre-existing issue, but is there a missing cleanup for the wake IRQ
when removing the device?

The unmanaged wake IRQ is allocated and attached in mxc_rtc_probe():

drivers/rtc/rtc-mxc_v2.c:mxc_rtc_probe() {
    ...
    ret = dev_pm_set_wake_irq(&pdev->dev, pdata->irq);
    ...
}

However, mxc_rtc_remove() completes without clearing the wake IRQ. This can
lead to a memory leak and leave a dangling wake IRQ on driver unbind.
Subsequent probe attempts could hit an -EEXIST error and trigger a warning
if probe is retried after a failure or during a rebind.

>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260914132505.2356970-1-congnt264@gmail.com?part=1

      reply	other threads:[~2026-09-14 13:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-14 13:25 [PATCH] rtc: mxc_v2: fix clk enable-count underflow warning in remove() Cong Nguyen
2026-09-14 13:48 ` 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=20260914134826.EC26D1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=congnt264@gmail.com \
    --cc=imx@lists.linux.dev \
    --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