Commit 8b797490 authored by Andrey Smirnov's avatar Andrey Smirnov Committed by Mark Brown

spi: gpio: Make sure spi_master_put() is called in every error path

There's a number of failure paths in spi_gpio_probe() that do not call
spi_master_put() potentially leaking memory. Fix this problem by
registering a cleanup funciont via devm_add_action_or_reset() right
after SPI controller is allocated.
Signed-off-by: default avatarAndrey Smirnov <andrew.smirnov@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Chris Healy <cphealy@gmail.com>
Cc: linux-spi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 8b57b11b
...@@ -362,6 +362,11 @@ static int spi_gpio_probe_pdata(struct platform_device *pdev, ...@@ -362,6 +362,11 @@ static int spi_gpio_probe_pdata(struct platform_device *pdev,
return 0; return 0;
} }
static void spi_gpio_put(void *data)
{
spi_master_put(data);
}
static int spi_gpio_probe(struct platform_device *pdev) static int spi_gpio_probe(struct platform_device *pdev)
{ {
int status; int status;
...@@ -377,6 +382,10 @@ static int spi_gpio_probe(struct platform_device *pdev) ...@@ -377,6 +382,10 @@ static int spi_gpio_probe(struct platform_device *pdev)
if (!master) if (!master)
return -ENOMEM; return -ENOMEM;
status = devm_add_action_or_reset(&pdev->dev, spi_gpio_put, master);
if (status)
return status;
if (of_id) if (of_id)
status = spi_gpio_probe_dt(pdev, master); status = spi_gpio_probe_dt(pdev, master);
else else
...@@ -428,11 +437,7 @@ static int spi_gpio_probe(struct platform_device *pdev) ...@@ -428,11 +437,7 @@ static int spi_gpio_probe(struct platform_device *pdev)
} }
bb->setup_transfer = spi_bitbang_setup_transfer; bb->setup_transfer = spi_bitbang_setup_transfer;
status = spi_bitbang_start(&spi_gpio->bitbang); return spi_bitbang_start(&spi_gpio->bitbang);
if (status)
spi_master_put(master);
return status;
} }
static int spi_gpio_remove(struct platform_device *pdev) static int spi_gpio_remove(struct platform_device *pdev)
...@@ -444,8 +449,6 @@ static int spi_gpio_remove(struct platform_device *pdev) ...@@ -444,8 +449,6 @@ static int spi_gpio_remove(struct platform_device *pdev)
/* stop() unregisters child devices too */ /* stop() unregisters child devices too */
spi_bitbang_stop(&spi_gpio->bitbang); spi_bitbang_stop(&spi_gpio->bitbang);
spi_master_put(spi_gpio->bitbang.master);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment