[PATCH 1/2] spi: stm32-ospi: handle runtime resume failure in remove

Patrice CHOTARD patrice.chotard at foss.st.com
Fri Oct 30 07:47:44 PDT 2026



On 10/19/26 10:44, Jiale Yao wrote:
> stm32_ospi_remove() continues with the controller teardown when runtime
> resume fails. The register write can then access an unavailable device,
> and the final runtime PM put does not match an acquired reference.
> 
> Keep the resource cleanup, but skip the register access and matching
> runtime PM put when the resume operation fails.
> 
> Fixes: 73cd1f97946a ("spi: stm32-ospi: Fix resource leak in remove() callback")
> Signed-off-by: Jiale Yao <yaojiale02 at 163.com>
> ---
>  drivers/spi/spi-stm32-ospi.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/spi/spi-stm32-ospi.c b/drivers/spi/spi-stm32-ospi.c
> index fa0e8e83cb1b..1340e62ebe1b 100644
> --- a/drivers/spi/spi-stm32-ospi.c
> +++ b/drivers/spi/spi-stm32-ospi.c
> @@ -986,12 +986,15 @@ static int stm32_ospi_probe(struct platform_device *pdev)
>  static void stm32_ospi_remove(struct platform_device *pdev)
>  {
>  	struct stm32_ospi *ospi = platform_get_drvdata(pdev);
> +	int ret;
>  
> -	pm_runtime_resume_and_get(ospi->dev);
> +	ret = pm_runtime_resume_and_get(ospi->dev);
>  
>  	spi_unregister_controller(ospi->ctrl);
> -	/* Disable ospi */
> -	writel_relaxed(0, ospi->regs_base + OSPI_CR);
> +	if (ret >= 0) {
> +		/* Disable ospi */
> +		writel_relaxed(0, ospi->regs_base + OSPI_CR);
> +	}
>  	mutex_destroy(&ospi->lock);
>  
>  	if (ospi->dma_chtx)
> @@ -1001,7 +1004,8 @@ static void stm32_ospi_remove(struct platform_device *pdev)
>  
>  	reset_control_release(ospi->rstc);
>  
> -	pm_runtime_put_sync_suspend(ospi->dev);
> +	if (ret >= 0)
> +		pm_runtime_put_sync_suspend(ospi->dev);
>  	pm_runtime_force_suspend(ospi->dev);
>  }
>  
Hi Jiale

Reviewed-by: Patrice Chotard <patrice.chotard at foss.st.com>

Thanks
Patrice




More information about the linux-arm-kernel mailing list