[2/3] mmc: sunlpus: Fix a memory leak in case of error in spmmc_drv_probe()
Commit Message
If an error occurs after a successful mmc_alloc_host() call in the probe,
the error handling path should be executed in order to call
mmc_free_host().
Fixes: 4e268fed8b18 ("mmc: Add mmc driver for Sunplus SP7021")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/mmc/host/sunplus-mmc.c | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
@@ -875,26 +875,34 @@ static int spmmc_drv_probe(struct platform_device *pdev)
host->dma_int_threshold = 1024;
host->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
- if (IS_ERR(host->base))
- return PTR_ERR(host->base);
+ if (IS_ERR(host->base)) {
+ ret = PTR_ERR(host->base);
+ goto probe_free_host;
+ }
host->clk = devm_clk_get_enabled(&pdev->dev, NULL);
- if (IS_ERR(host->clk))
- return dev_err_probe(&pdev->dev, PTR_ERR(host->clk), "clk get fail\n");
+ if (IS_ERR(host->clk)) {
+ ret = dev_err_probe(&pdev->dev, PTR_ERR(host->clk), "clk get fail\n");
+ goto probe_free_host;
+ }
host->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
- if (IS_ERR(host->rstc))
- return dev_err_probe(&pdev->dev, PTR_ERR(host->rstc), "rst get fail\n");
+ if (IS_ERR(host->rstc)) {
+ ret = dev_err_probe(&pdev->dev, PTR_ERR(host->rstc), "rst get fail\n");
+ goto probe_free_host;
+ }
host->irq = platform_get_irq(pdev, 0);
- if (host->irq <= 0)
- return host->irq;
+ if (host->irq <= 0) {
+ ret = host->irq;
+ goto probe_free_host;
+ }
ret = devm_request_threaded_irq(&pdev->dev, host->irq,
spmmc_irq, spmmc_func_finish_req, IRQF_SHARED,
NULL, host);
if (ret)
- return ret;
+ goto probe_free_host;
ret = mmc_of_parse(mmc);
if (ret)