Skip to contentSkip to conversation

spi: gpio: prevent memroy leak in spi_gpio_probe

PATCH Superseded Navid Emamdoost 3 participants 8 messages Sep 30, 2019 – Oct 2, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: gpio: prevent memroy leak in spi_gpio_probe

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")
---
 drivers/spi/spi-gpio.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/spi/spi-gpio.c +3 -1
index 1d3e23ec20a6..f9c5bbb74714 100644
@@ -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);
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 1/1 spi: gpio: prevent memory leak in spi_gpio_probe

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. In order to avoid leak spi_contriller_put must be called 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")

---
Changes in v2:
-- fix a typo in title and update the description

---
 drivers/spi/spi-gpio.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/spi/spi-gpio.c +3 -1
index 1d3e23ec20a6..f9c5bbb74714 100644
@@ -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);
Signature · 1 line
2.17.1
#3 lore raw

Re: [PATCH v2] spi: gpio: prevent memory leak in spi_gpio_probe

Quoted 2 lines

… In order to avoid leak spi_contriller_put must be called in case of failure for devm_add_action_or_reset.

How does this wording fit to the diff display that you would like to add the function call “spi_master_put(master)” in one if branch?

Quoted 1 line
Fixes 8b797490b4db ("spi: gpio: Make sure spi_master_put() is called in every error path")

Is there a need to complete the corresponding exception handling at any more source code places?

Regards,
Markus

#4 lore raw

Re: [PATCH v2] spi: gpio: prevent memory leak in spi_gpio_probe

Hi Markus, thanks for your suggestions for improving the quality of the patch. At the moment I prefer first get a confirmation from contributors about the leak and then work on any possible improvements for the patch.

Thanks,
Navid.

Quoted 16 lines · Markus Elfring
Quoted 3 lines

… In order to avoid leak spi_contriller_put must be called in case of failure for devm_add_action_or_reset.

How does this wording fit to the diff display that you would like to add the function call “spi_master_put(master)” in one if branch?

Quoted 1 line
Fixes 8b797490b4db ("spi: gpio: Make sure spi_master_put() is called in every error path")

Is there a need to complete the corresponding exception handling at any more source code places?

Regards,
Markus

Signature · 1 line
Navid.
#5 lore raw

Re: [v2] spi: gpio: prevent memory leak in spi_gpio_probe

Quoted 4 lines

Hi Markus, thanks for your suggestions for improving the quality of the patch. At the moment I prefer first get a confirmation from contributors about the leak and then work on any possible improvements for the patch.

Please fix this patch as soon as possible if you care for the correctness of the provided information.

Regards,
Markus

maintainer
#6 lore raw

Applied "spi: gpio: prevent memory leak in spi_gpio_probe" to the spi tree

In reply to Navid Emamdoost

The patch

spi: gpio: prevent memory leak in spi_gpio_probe

has been applied to the spi tree at

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-5.4

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From d3b0ffa1d75d5305ebe34735598993afbb8a869d Mon Sep 17 00:00:00 2001

From: Navid Emamdoost <[email protected]>
Date: Mon, 30 Sep 2019 15:52:40 -0500
Subject: [PATCH] spi: gpio: prevent memory leak in spi_gpio_probe

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. In order to avoid leak spi_contriller_put must be called 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")
---
 drivers/spi/spi-gpio.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/spi/spi-gpio.c +3 -1
index 1d3e23ec20a6..f9c5bbb74714 100644
@@ -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);
Signature · 1 line
2.20.1
#7 lore raw

Re: [PATCH] spi: gpio: prevent memory leak in spi_gpio_probe

In reply to Markus Elfring

Fixed the issues in v2.

Thanks,
Navid.

Quoted 9 lines · Markus Elfring

* Please avoid typos in the commit message.

* I would prefer an other wording for the change description.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id—f9a3c4eee55b0178b518ae7114a6a53372913d#n151

Regards,
Markus

Signature · 1 line
Navid.