]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
spi: bcm2835: Do not call gpiod_put() on invalid descriptor
authorFlorian Fainelli <florian.fainelli@broadcom.com>
Tue, 1 Apr 2025 22:42:38 +0000 (15:42 -0700)
committerMark Brown <broonie@kernel.org>
Tue, 1 Apr 2025 23:04:40 +0000 (00:04 +0100)
If we are unable to lookup the chip-select GPIO, the error path will
call bcm2835_spi_cleanup() which unconditionally calls gpiod_put() on
the cs->gpio variable which we just determined was invalid.

Fixes: 21f252cd29f0 ("spi: bcm2835: reduce the abuse of the GPIO API")
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
Link: https://patch.msgid.link/20250401224238.2854256-1-florian.fainelli@broadcom.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-bcm2835.c

index 0d1aa659248460efb5b0b3026c1ecdd06d18b3aa..06a81727d74ddd53ac111e235d0f1c4f30b15419 100644 (file)
@@ -1162,7 +1162,8 @@ static void bcm2835_spi_cleanup(struct spi_device *spi)
                                 sizeof(u32),
                                 DMA_TO_DEVICE);
 
-       gpiod_put(bs->cs_gpio);
+       if (!IS_ERR(bs->cs_gpio))
+               gpiod_put(bs->cs_gpio);
        spi_set_csgpiod(spi, 0, NULL);
 
        kfree(target);