Unverified Commit 7fc5e2f5 authored by Felix Gu's avatar Felix Gu Committed by Mark Brown
Browse files

spi: axiado: Fix double-free in ax_spi_probe()



ctlr is allocated using devm_spi_alloc_host(), which automatically
handles reference counting via the devm framework.

Calling spi_controller_put() manually in the probe error path is
redundant and results in a double-free.

Fixes: e75a6b00 ("spi: axiado: Add driver for Axiado SPI DB controller")
Signed-off-by: default avatarFelix Gu <ustc.gu@gmail.com>
Link: https://patch.msgid.link/20260302-axiado-v1-1-1132819f1cb7@gmail.com


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent b8db9552
Loading
Loading
Loading
Loading
+11 −20
Original line number Diff line number Diff line
@@ -765,30 +765,22 @@ static int ax_spi_probe(struct platform_device *pdev)
	platform_set_drvdata(pdev, ctlr);

	xspi->regs = devm_platform_ioremap_resource(pdev, 0);
	if (IS_ERR(xspi->regs)) {
		ret = PTR_ERR(xspi->regs);
		goto remove_ctlr;
	}
	if (IS_ERR(xspi->regs))
		return PTR_ERR(xspi->regs);

	xspi->pclk = devm_clk_get(&pdev->dev, "pclk");
	if (IS_ERR(xspi->pclk)) {
		dev_err(&pdev->dev, "pclk clock not found.\n");
		ret = PTR_ERR(xspi->pclk);
		goto remove_ctlr;
	}
	if (IS_ERR(xspi->pclk))
		return dev_err_probe(&pdev->dev, PTR_ERR(xspi->pclk),
				     "pclk clock not found.\n");

	xspi->ref_clk = devm_clk_get(&pdev->dev, "ref");
	if (IS_ERR(xspi->ref_clk)) {
		dev_err(&pdev->dev, "ref clock not found.\n");
		ret = PTR_ERR(xspi->ref_clk);
		goto remove_ctlr;
	}
	if (IS_ERR(xspi->ref_clk))
		return dev_err_probe(&pdev->dev, PTR_ERR(xspi->ref_clk),
				     "ref clock not found.\n");

	ret = clk_prepare_enable(xspi->pclk);
	if (ret) {
		dev_err(&pdev->dev, "Unable to enable APB clock.\n");
		goto remove_ctlr;
	}
	if (ret)
		return dev_err_probe(&pdev->dev, ret, "Unable to enable APB clock.\n");

	ret = clk_prepare_enable(xspi->ref_clk);
	if (ret) {
@@ -869,8 +861,7 @@ static int ax_spi_probe(struct platform_device *pdev)
	clk_disable_unprepare(xspi->ref_clk);
clk_dis_apb:
	clk_disable_unprepare(xspi->pclk);
remove_ctlr:
	spi_controller_put(ctlr);

	return ret;
}