On Mon, Dec 28, 2020 at 11:59:19AM +0100, gregkh@linuxfoundation.org wrote:
The patch below does not apply to the 4.19-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to stable@vger.kernel.org.
Here's the backport of 7174dc655ef0 to v4.19.192:
-- >8 -- From: Lukas Wunner lukas@wunner.de Date: Mon, 7 Dec 2020 09:17:09 +0100 Subject: [PATCH] spi: gpio: Don't leak SPI master in probe error path
commit 7174dc655ef0578877b0b4598e69619d2be28b4d upstream.
If the calls to devm_kcalloc() or spi_gpio_request() fail on probe of the GPIO SPI driver, the spi_master struct is erroneously not freed because the required calls to spi_master_put() are missing.
Fix by switching over to the new devm_spi_alloc_master() helper.
Fixes: 9b00bc7b901f ("spi: spi-gpio: Rewrite to use GPIO descriptors") Signed-off-by: Lukas Wunner lukas@wunner.de Reviewed-by: Linus Walleij linus.walleij@linaro.org Cc: stable@vger.kernel.org # v4.17+: 5e844cc37a5c: spi: Introduce device-managed SPI controller allocation Cc: stable@vger.kernel.org # v4.17+ Cc: Navid Emamdoost navid.emamdoost@gmail.com Cc: Andrey Smirnov andrew.smirnov@gmail.com Link: https://lore.kernel.org/r/86eaed27431c3d709e3748eb76ceecbfc790dd37.160728688... Signed-off-by: Mark Brown broonie@kernel.org [lukas: backport to v4.19.192] Signed-off-by: Lukas Wunner lukas@wunner.de --- drivers/spi/spi-gpio.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 77838d8fd9bb..341d2953d7fc 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -382,7 +382,7 @@ static int spi_gpio_probe(struct platform_device *pdev) return -ENODEV; #endif
- master = spi_alloc_master(&pdev->dev, sizeof(*spi_gpio)); + master = devm_spi_alloc_master(&pdev->dev, sizeof(*spi_gpio)); if (!master) return -ENOMEM;
@@ -438,11 +438,7 @@ static int spi_gpio_probe(struct platform_device *pdev) } spi_gpio->bitbang.setup_transfer = spi_bitbang_setup_transfer;
- status = spi_bitbang_start(&spi_gpio->bitbang); - if (status) - spi_master_put(master); - - return status; + return spi_bitbang_start(&spi_gpio->bitbang); }
static int spi_gpio_remove(struct platform_device *pdev)