[v2] spi: gpio: prevent memory leak in spi_gpio_probe
diff mbox series

Message ID 20190930205241.5483-1-navid.emamdoost@gmail.com
State Accepted
Headers show
Series
  • [v2] spi: gpio: prevent memory leak in spi_gpio_probe
Related show

Commit Message

Navid Emamdoost Sept. 30, 2019, 8:52 p.m. UTC
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")
Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
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(-)

Comments

Markus Elfring Oct. 1, 2019, 9:11 a.m. UTC | #1
> … 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?


> 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
Navid Emamdoost Oct. 1, 2019, 5:32 p.m. UTC | #2
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.

On Tue, Oct 1, 2019 at 4:11 AM Markus Elfring <Markus.Elfring@web.de> wrote:
>
> > … 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?
>
>
> > 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
Markus Elfring Oct. 2, 2019, 5:07 a.m. UTC | #3
> 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

Patch
diff mbox series

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);