Commit c0368e4d authored by Florian Fainelli's avatar Florian Fainelli Committed by Mark Brown

spi: bcm-qspi: Fix use after free in bcm_qspi_probe() in error path

There was an inversion in how the error path in bcm_qspi_probe() is done
which would make us trip over a KASAN use-after-free report. Turns out
that qspi->dev_ids does not get allocated until later in the probe
process. Fix this by introducing a new lable: qspi_resource_err which
takes care of cleaning up the SPI master instance.

Fixes: fa236a7e ("spi: bcm-qspi: Add Broadcom MSPI driver")
Signed-off-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
Cc: stable@vger.kernel.org
parent 2bd6bf03
...@@ -1250,7 +1250,7 @@ int bcm_qspi_probe(struct platform_device *pdev, ...@@ -1250,7 +1250,7 @@ int bcm_qspi_probe(struct platform_device *pdev,
goto qspi_probe_err; goto qspi_probe_err;
} }
} else { } else {
goto qspi_probe_err; goto qspi_resource_err;
} }
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "bspi"); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "bspi");
...@@ -1272,7 +1272,7 @@ int bcm_qspi_probe(struct platform_device *pdev, ...@@ -1272,7 +1272,7 @@ int bcm_qspi_probe(struct platform_device *pdev,
qspi->base[CHIP_SELECT] = devm_ioremap_resource(dev, res); qspi->base[CHIP_SELECT] = devm_ioremap_resource(dev, res);
if (IS_ERR(qspi->base[CHIP_SELECT])) { if (IS_ERR(qspi->base[CHIP_SELECT])) {
ret = PTR_ERR(qspi->base[CHIP_SELECT]); ret = PTR_ERR(qspi->base[CHIP_SELECT]);
goto qspi_probe_err; goto qspi_resource_err;
} }
} }
...@@ -1280,7 +1280,7 @@ int bcm_qspi_probe(struct platform_device *pdev, ...@@ -1280,7 +1280,7 @@ int bcm_qspi_probe(struct platform_device *pdev,
GFP_KERNEL); GFP_KERNEL);
if (!qspi->dev_ids) { if (!qspi->dev_ids) {
ret = -ENOMEM; ret = -ENOMEM;
goto qspi_probe_err; goto qspi_resource_err;
} }
for (val = 0; val < num_irqs; val++) { for (val = 0; val < num_irqs; val++) {
...@@ -1369,8 +1369,9 @@ int bcm_qspi_probe(struct platform_device *pdev, ...@@ -1369,8 +1369,9 @@ int bcm_qspi_probe(struct platform_device *pdev,
bcm_qspi_hw_uninit(qspi); bcm_qspi_hw_uninit(qspi);
clk_disable_unprepare(qspi->clk); clk_disable_unprepare(qspi->clk);
qspi_probe_err: qspi_probe_err:
spi_master_put(master);
kfree(qspi->dev_ids); kfree(qspi->dev_ids);
qspi_resource_err:
spi_master_put(master);
return ret; return ret;
} }
/* probe function to be called by SoC specific platform driver probe */ /* probe function to be called by SoC specific platform driver probe */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment