All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jiawen Liu" <1298662399@qq.com>
Cc: Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH v2 3/3] spi: nxp-fspi: check runtime PM get in cleanup
Date: Tue, 28 Jul 2026 08:21:30 +0000	[thread overview]
Message-ID: <20260728082131.9C72B1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <tencent_9A37C7A91DB0EF57A552A99EAC881CD24605@qq.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Asynchronous runtime PM put in cleanup path causes a race condition leading to double clock disable.
--

--- Patch [3]: [PATCH v2 3/3] spi: nxp-fspi: check runtime PM get in cleanup ---
commit 7a9a4bc911b3e8e33c657c1f4c72809d1937328c
Author: Jiawen Liu <1298662399@qq.com>

spi: nxp-fspi: check runtime PM get in cleanup

This commit updates nxp_fspi_cleanup() to use PM_RUNTIME_ACQUIRE() to
safely check the result of the runtime PM get operation. If the device
fails to resume, it skips the MMIO write that disables the hardware.

> diff --git a/drivers/spi/spi-nxp-fspi.c b/drivers/spi/spi-nxp-fspi.c
> index 3f1c3ed748eba..2671ffb490968 100644
> --- a/drivers/spi/spi-nxp-fspi.c
> +++ b/drivers/spi/spi-nxp-fspi.c
> @@ -1268,14 +1268,21 @@ static void nxp_fspi_cleanup(void *data)
>  {
>  	struct nxp_fspi *f = data;
> +	int ret;
>  
> -	/* enable clock first since there is register access */
> -	pm_runtime_get_sync(f->dev);
> +	{
> +		/* enable clock first since there is register access */
> +		PM_RUNTIME_ACQUIRE(f->dev, pm);
>  
> -	/* disable the hardware */
> -	fspi_writel(f, FSPI_MCR0_MDIS, f->iobase + FSPI_MCR0);
> +		ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
> +		if (ret < 0) {
> +			dev_warn(f->dev, "Failed to enable clock for cleanup: %d\n", ret);
> +		} else {
> +			/* disable the hardware */
> +			fspi_writel(f, FSPI_MCR0_MDIS, f->iobase + FSPI_MCR0);
> +		}
> +	}

[Severity: High]
Could this scope-based PM_RUNTIME_ACQUIRE() introduce a race condition?

The PM_RUNTIME_ACQUIRE() macro acts as a guard that calls an asynchronous
pm_runtime_put() when it goes out of scope at the end of this block.

Because it is asynchronous, the queued suspend could execute concurrently
and call nxp_fspi_runtime_suspend(), which disables the clocks.

Meanwhile, the cleanup thread immediately proceeds to explicitly call
nxp_fspi_clk_disable_unprep(f), which could result in a concurrent double
clock disable and trigger a common clock framework warning.

Additionally, using an asynchronous put just before device removal or
pm_runtime_disable() means the pending suspend work might be cancelled
by __pm_runtime_barrier(). Does this leave the PM core thinking the device
is active while its hardware clocks have been manually turned off?

> -	pm_runtime_put_noidle(f->dev);
>  	nxp_fspi_clk_disable_unprep(f);
>  
>  	if (f->ahb_addr)

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260728080443.153827-1-1298662399@qq.com?part=3

      reply	other threads:[~2026-07-28  8:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260728080443.153827-1-1298662399@qq.com>
2026-07-28  8:04 ` [PATCH v2 1/3] spi: nxp-fspi: use devm runtime PM enablement Jiawen Liu
2026-07-28  8:21   ` sashiko-bot
2026-07-28  8:04 ` [PATCH v2 2/3] spi: nxp-fspi: propagate default setup failures Jiawen Liu
2026-07-28  8:18   ` sashiko-bot
2026-07-28  8:04 ` [PATCH v2 3/3] spi: nxp-fspi: check runtime PM get in cleanup Jiawen Liu
2026-07-28  8:21   ` 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=20260728082131.9C72B1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=1298662399@qq.com \
    --cc=Frank.Li@kernel.org \
    --cc=imx@lists.linux.dev \
    --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.