]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
spi: atcspi200: fix mutex initialization order
authorPei Xiao <xiaopei01@kylinos.cn>
Thu, 12 Mar 2026 02:47:55 +0000 (10:47 +0800)
committerMark Brown <broonie@kernel.org>
Thu, 12 Mar 2026 11:28:31 +0000 (11:28 +0000)
The atcspi_exec_mem_op() function may call mutex_lock() on the
driver's mutex before it is properly initialized if a SPI memory
operation is initiated immediately after devm_spi_register_controller()
is called. The mutex initialization currently occurs after the
controller registration, which leaves a window where the mutex could
be used uninitialized.

Move the mutex initialization to the beginning of the probe function,
before any registration or resource allocation.

Fixes: 34e3815ea459 ("spi: atcspi200: Add ATCSPI200 SPI controller driver")
Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
Link: https://patch.msgid.link/15a71241affc25108a97d40d9d3dd1bc3d2d69ed.1773282905.git.xiaopei01@kylinos.cn
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-atcspi200.c

index 257db4e529e279d486e8715b29378d803990f393..8f283dffe3cafec102ead6fac1fb2c4a14592824 100644 (file)
@@ -565,6 +565,8 @@ static int atcspi_probe(struct platform_device *pdev)
        spi->dev = &pdev->dev;
        dev_set_drvdata(&pdev->dev, host);
 
+       mutex_init(&spi->mutex_lock);
+
        ret = atcspi_init_resources(pdev, spi, &mem_res);
        if (ret)
                goto free_controller;
@@ -594,11 +596,11 @@ static int atcspi_probe(struct platform_device *pdev)
                else
                        spi->use_dma = true;
        }
-       mutex_init(&spi->mutex_lock);
 
        return 0;
 
 free_controller:
+       mutex_destroy(&spi->mutex_lock);
        spi_controller_put(host);
        return ret;
 }