linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: gpio: prevent memroy leak in spi_gpio_probe
@ 2019-09-30  3:39 Navid Emamdoost
  2019-09-30  6:24 ` [PATCH] spi: gpio: prevent memory " Markus Elfring
  0 siblings, 1 reply; 8+ messages in thread
From: Navid Emamdoost @ 2019-09-30  3:39 UTC (permalink / raw)
  Cc: emamd001, kjlu, smccaman, Navid Emamdoost, Mark Brown, linux-spi,
	linux-kernel

In spi_gpio_probe an SPI master is allocated via spi_alloc_master, but
this controller should be released if devm_add_action_or_reset fails,
otherwise memory leaks. This commit adds Fixes: spi_contriller_put in
case of failure for devm_add_action_or_reset.

Fixes: 8b797490b4db ("spi: gpio: Make sure spi_master_put() is called in every error path")
Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
 drivers/spi/spi-gpio.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c
index 1d3e23ec20a6..f9c5bbb74714 100644
--- a/drivers/spi/spi-gpio.c
+++ b/drivers/spi/spi-gpio.c
@@ -371,8 +371,10 @@ static int spi_gpio_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	status = devm_add_action_or_reset(&pdev->dev, spi_gpio_put, master);
-	if (status)
+	if (status) {
+		spi_master_put(master);
 		return status;
+	}
 
 	if (of_id)
 		status = spi_gpio_probe_dt(pdev, master);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-10-02  5:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-30  3:39 [PATCH] spi: gpio: prevent memroy leak in spi_gpio_probe Navid Emamdoost
2019-09-30  6:24 ` [PATCH] spi: gpio: prevent memory " Markus Elfring
2019-09-30 20:52   ` [PATCH v2] " Navid Emamdoost
2019-10-01  9:11     ` Markus Elfring
2019-10-01 17:32       ` Navid Emamdoost
2019-10-02  5:07         ` [v2] " Markus Elfring
2019-10-01 17:57     ` Applied "spi: gpio: prevent memory leak in spi_gpio_probe" to the spi tree Mark Brown
2019-09-30 20:54   ` [PATCH] spi: gpio: prevent memory leak in spi_gpio_probe Navid Emamdoost

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).