Skip to content

Commit

Permalink
spi: mxic: Don't leak SPI master in probe error path
Browse files Browse the repository at this point in the history
commit cc53711 upstream.

If the calls to devm_clk_get() or devm_ioremap_resource() fail on probe
of the Macronix SPI driver, the spi_master struct is erroneously not freed.

Fix by switching over to the new devm_spi_alloc_master() helper.

Fixes: b942d80 ("spi: Add MXIC controller driver")
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Cc: <stable@vger.kernel.org> # v5.0+: 5e844cc: spi: Introduce device-managed SPI controller allocation
Cc: <stable@vger.kernel.org> # v5.0+
Cc: Mason Yang <masonccyang@mxic.com.tw>
Link: https://lore.kernel.org/r/4fa6857806e7e75741c05d057ac9df3564460114.1607286887.git.lukas@wunner.de
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
l1k authored and gregkh committed Dec 30, 2020
1 parent 0c2867d commit 3bf639f
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions drivers/spi/spi-mxic.c
Expand Up @@ -529,7 +529,7 @@ static int mxic_spi_probe(struct platform_device *pdev)
struct mxic_spi *mxic;
int ret;

master = spi_alloc_master(&pdev->dev, sizeof(struct mxic_spi));
master = devm_spi_alloc_master(&pdev->dev, sizeof(struct mxic_spi));
if (!master)
return -ENOMEM;

Expand Down Expand Up @@ -574,15 +574,9 @@ static int mxic_spi_probe(struct platform_device *pdev)
ret = spi_register_master(master);
if (ret) {
dev_err(&pdev->dev, "spi_register_master failed\n");
goto err_put_master;
pm_runtime_disable(&pdev->dev);
}

return 0;

err_put_master:
spi_master_put(master);
pm_runtime_disable(&pdev->dev);

return ret;
}

Expand Down

0 comments on commit 3bf639f

Please sign in to comment.