Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: e75a6b00ad79 ("spi: axiado: Add driver for Axiado SPI DB controller")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
Link: https://patch.msgid.link/20260302-axiado-v1-1-1132819f1cb7@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Felix Gu and committed by
Mark Brown
7fc5e2f5 b8db9552

+11 -20
+11 -20
drivers/spi/spi-axiado.c
··· 765 765 platform_set_drvdata(pdev, ctlr); 766 766 767 767 xspi->regs = devm_platform_ioremap_resource(pdev, 0); 768 - if (IS_ERR(xspi->regs)) { 769 - ret = PTR_ERR(xspi->regs); 770 - goto remove_ctlr; 771 - } 768 + if (IS_ERR(xspi->regs)) 769 + return PTR_ERR(xspi->regs); 772 770 773 771 xspi->pclk = devm_clk_get(&pdev->dev, "pclk"); 774 - if (IS_ERR(xspi->pclk)) { 775 - dev_err(&pdev->dev, "pclk clock not found.\n"); 776 - ret = PTR_ERR(xspi->pclk); 777 - goto remove_ctlr; 778 - } 772 + if (IS_ERR(xspi->pclk)) 773 + return dev_err_probe(&pdev->dev, PTR_ERR(xspi->pclk), 774 + "pclk clock not found.\n"); 779 775 780 776 xspi->ref_clk = devm_clk_get(&pdev->dev, "ref"); 781 - if (IS_ERR(xspi->ref_clk)) { 782 - dev_err(&pdev->dev, "ref clock not found.\n"); 783 - ret = PTR_ERR(xspi->ref_clk); 784 - goto remove_ctlr; 785 - } 777 + if (IS_ERR(xspi->ref_clk)) 778 + return dev_err_probe(&pdev->dev, PTR_ERR(xspi->ref_clk), 779 + "ref clock not found.\n"); 786 780 787 781 ret = clk_prepare_enable(xspi->pclk); 788 - if (ret) { 789 - dev_err(&pdev->dev, "Unable to enable APB clock.\n"); 790 - goto remove_ctlr; 791 - } 782 + if (ret) 783 + return dev_err_probe(&pdev->dev, ret, "Unable to enable APB clock.\n"); 792 784 793 785 ret = clk_prepare_enable(xspi->ref_clk); 794 786 if (ret) { ··· 861 869 clk_disable_unprepare(xspi->ref_clk); 862 870 clk_dis_apb: 863 871 clk_disable_unprepare(xspi->pclk); 864 - remove_ctlr: 865 - spi_controller_put(ctlr); 872 + 866 873 return ret; 867 874 } 868 875