Re: [PATCH] spi: atcspi200: fix mutex initialization order
From: Mark Brown
Date: Tue Mar 10 2026 - 13:45:04 EST
On Tue, Mar 10, 2026 at 05:55:47PM +0800, Pei Xiao wrote:
> Move the mutex initialization to the beginning of the probe function,
> before any registration or resource allocation. Also replace the
> plain mutex_init() with devm_mutex_init() to benefit from automatic
> cleanup on driver unbind, preventing potential resource leaks.
> +++ b/drivers/spi/spi-atcspi200.c
> @@ -567,6 +567,10 @@ static int atcspi_probe(struct platform_device *pdev)
> spi->dev = &pdev->dev;
> dev_set_drvdata(&pdev->dev, host);
>
> + ret = devm_mutex_init(spi->dev, &spi->mutex_lock);
> + if (ret)
> + return ret;
> +
> ret = atcspi_init_resources(pdev, spi, &mem_res);
> if (ret)
> goto free_controller;
Shouldn't we be using free_controller if the mutex allocation fails too?
We'll leak the controller struct if that happens.
Attachment:
signature.asc
Description: PGP signature