spi: Handle SPI device setup callback failure.
authorJoe Burmeister <joe.burmeister@devtank.co.uk>
Mon, 19 Apr 2021 13:06:31 +0000 (14:06 +0100)
committerMark Brown <broonie@kernel.org>
Mon, 19 Apr 2021 13:18:46 +0000 (14:18 +0100)
If the setup callback failed, but the controller has auto_runtime_pm
and set_cs, the setup failure could be missed.

Signed-off-by: Joe Burmeister <joe.burmeister@devtank.co.uk>
Link: https://lore.kernel.org/r/20210419130631.4586-1-joe.burmeister@devtank.co.uk
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi.c

index cf231ff..cc6d43d 100644 (file)
@@ -3378,8 +3378,15 @@ int spi_setup(struct spi_device *spi)
 
        mutex_lock(&spi->controller->io_mutex);
 
-       if (spi->controller->setup)
+       if (spi->controller->setup) {
                status = spi->controller->setup(spi);
+               if (status) {
+                       mutex_unlock(&spi->controller->io_mutex);
+                       dev_err(&spi->controller->dev, "Failed to setup device: %d\n",
+                               status);
+                       return status;
+               }
+       }
 
        if (spi->controller->auto_runtime_pm && spi->controller->set_cs) {
                status = pm_runtime_get_sync(spi->controller->dev.parent);