diff mbox series

spi: gpio: prevent memroy leak in spi_gpio_probe

Message ID 20190930033928.32312-1-navid.emamdoost@gmail.com (mailing list archive)
State Accepted
Commit d3b0ffa1d75d5305ebe34735598993afbb8a869d
Headers show
Series spi: gpio: prevent memroy leak in spi_gpio_probe | expand

Commit Message

Navid Emamdoost Sept. 30, 2019, 3:39 a.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. 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(-)

Comments

Markus Elfring Sept. 30, 2019, 6:24 a.m. UTC | #1
* 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=97f9a3c4eee55b0178b518ae7114a6a53372913d#n151


Regards,
Markus
Navid Emamdoost Sept. 30, 2019, 8:54 p.m. UTC | #2
Fixed the issues in v2.

Thanks,
Navid.

On Mon, Sep 30, 2019 at 1:24 AM Markus Elfring <Markus.Elfring@web.de> wrote:
>
> * 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=97f9a3c4eee55b0178b518ae7114a6a53372913d#n151
>
>
> Regards,
> Markus
patchwork-bot+linux-spi@kernel.org Oct. 1, 2019, 6 p.m. UTC | #3
Hello:

The following patches were marked "accepted", because they were applied to
broonie/spi.git (refs/heads/for-next):

Patch: spi: gpio: prevent memroy leak in spi_gpio_probe
  Submitter: Navid Emamdoost <navid.emamdoost@gmail.com>
  Patchwork: https://patchwork.kernel.org/project/spi-devel-general/list/?series=180171

Total patches: 1
diff mbox series

Patch

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