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 3/4] spi: fsl-dspi: clean up after failed suspend and resume
Date: Sat, 20 Jun 2026 08:53:16 +0000	[thread overview]
Message-ID: <20260620085316.DF6B21F000E9@smtp.kernel.org> (raw)
In-Reply-To: <tencent_427FA55E3D59112524886E9C931CA0F92F06@qq.com>

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

Pre-existing issues:
- [High] Deadlock and guaranteed 5-second suspend timeout due to incorrect lifecycle ordering in dspi_suspend().
- [High] Race condition and potential deadlock in dspi_resume() due to resuming the SPI queue before hardware initialization.
--

commit 98c391bd91fadd1b60a50d12e8e2491310c7b7ea
Author: Jiawen Liu <1298662399@qq.com>

spi: fsl-dspi: clean up after failed suspend and resume

This patch updates the suspend and resume routines to better handle failures.
It ensures the IRQ is re-enabled if spi_controller_suspend() fails, and
properly unwinds clock preparation if controller resume or hardware
initialization fails.

> diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
> index 019d05cdefe69..c2d283876ef80 100644
> --- a/drivers/spi/spi-fsl-dspi.c
> +++ b/drivers/spi/spi-fsl-dspi.c
> @@ -1464,10 +1464,18 @@ static int dspi_init(struct fsl_dspi *dspi)
>  static int dspi_suspend(struct device *dev)
>  {
>  	struct fsl_dspi *dspi = dev_get_drvdata(dev);
> +	int ret;
>  
>  	if (dspi->irq)
>  		disable_irq(dspi->irq);
> -	spi_controller_suspend(dspi->ctlr);
> +
> +	ret = spi_controller_suspend(dspi->ctlr);

[Severity: High]
This is a pre-existing issue, but does disabling the IRQ before suspending
the controller cause active transfers to hang?

Looking at dspi_suspend(), disable_irq() is called before
spi_controller_suspend(). When spi_controller_suspend() stops the queue, it
waits up to 5 seconds for the active transfer to finish.

However, if the active transfer requires the hardware interrupt handler to
complete, it will never finish because the IRQ is already disabled. This
seems like it would guarantee a 5-second timeout, causing
spi_controller_suspend() to return -EBUSY and abort the suspend.

Should the controller be suspended before the IRQ is disabled?

> +	if (ret) {
> +		if (dspi->irq)
> +			enable_irq(dspi->irq);
> +		return ret;
> +	}
> +
>  	clk_disable_unprepare(dspi->clk);

[ ... ]

> @@ -1485,12 +1493,15 @@ static int dspi_resume(struct device *dev)
>  	ret = clk_prepare_enable(dspi->clk);
>  	if (ret)
>  		return ret;
> -	spi_controller_resume(dspi->ctlr);
> +
> +	ret = spi_controller_resume(dspi->ctlr);
> +	if (ret)
> +		goto disable_clk;
>  
>  	ret = dspi_init(dspi);

[Severity: High]
This isn't a bug introduced by this patch, but does calling
spi_controller_resume() before dspi_init() and enable_irq() create a race
window?

spi_controller_resume() unblocks the message pump, allowing the worker
thread to immediately dispatch pending transfers. If a transfer starts
before dspi_init() initializes the hardware state, it might interact with
uninitialized registers.

Additionally, dspi_init() clears the status registers:

	regmap_write(dspi->regmap, SPI_SR, SPI_SR_CLEAR);

If a racing transfer sets completion flags in the hardware right as
dspi_init() clears them, the interrupt could be permanently lost. The
worker thread would then deadlock waiting for the xfer_done completion
event.

Should the hardware and IRQs be fully restored before resuming the queue?

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

  reply	other threads:[~2026-06-20  8:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260620083931.1120616-1-1298662399@qq.com>
2026-06-20  8:39 ` [PATCH 1/4] spi: atcspi200: return error from failed controller suspend Jiawen Liu
2026-06-20  8:57   ` sashiko-bot
2026-06-20  8:39 ` [PATCH 2/4] spi: bcmbca-hsspi: " Jiawen Liu
2026-06-20  8:54   ` sashiko-bot
2026-06-20  8:39 ` [PATCH 3/4] spi: fsl-dspi: clean up after failed suspend and resume Jiawen Liu
2026-06-20  8:53   ` sashiko-bot [this message]
2026-06-20  8:39 ` [PATCH 4/4] spi: nxp-fspi: disable runtime PM on probe failures Jiawen Liu
2026-06-20  8:57   ` sashiko-bot
2026-06-20 14:09   ` Frank Li

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=20260620085316.DF6B21F000E9@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.