Skip to content

Commit

Permalink
spi: gpio: prevent memory leak in spi_gpio_probe
Browse files Browse the repository at this point in the history
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: 8b79749 ("spi: gpio: Make sure spi_master_put() is called in every error path")
Signed-off-by: Navid Emamdoost <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
Navidem authored and broonie committed Oct 1, 2019
1 parent 6b04e47 commit d3b0ffa
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/spi/spi-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d3b0ffa

Please sign in to comment.