Messages in this thread Patch in this message |  | | From | Johan Hovold <> | | Subject | [PATCH 12/20] spi: sun4i: switch to managed controller allocation | | Date | Tue, 5 May 2026 09:29:01 +0200 |
| |
Switch to device managed controller allocation to simplify error handling and to avoid having to take another reference during deregistration.
Signed-off-by: Johan Hovold <johan@kernel.org> --- drivers/spi/spi-sun4i.c | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-)
diff --git a/drivers/spi/spi-sun4i.c b/drivers/spi/spi-sun4i.c index b7fbb5270edb..d5c16392cd4d 100644 --- a/drivers/spi/spi-sun4i.c +++ b/drivers/spi/spi-sun4i.c @@ -434,32 +434,26 @@ static int sun4i_spi_probe(struct platform_device *pdev) struct sun4i_spi *sspi; int ret = 0, irq; - host = spi_alloc_host(&pdev->dev, sizeof(struct sun4i_spi)); - if (!host) { - dev_err(&pdev->dev, "Unable to allocate SPI Host\n"); + host = devm_spi_alloc_host(&pdev->dev, sizeof(struct sun4i_spi)); + if (!host) return -ENOMEM; - } platform_set_drvdata(pdev, host); sspi = spi_controller_get_devdata(host); sspi->base_addr = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(sspi->base_addr)) { - ret = PTR_ERR(sspi->base_addr); - goto err_free_host; - } + if (IS_ERR(sspi->base_addr)) + return PTR_ERR(sspi->base_addr); irq = platform_get_irq(pdev, 0); - if (irq < 0) { - ret = -ENXIO; - goto err_free_host; - } + if (irq < 0) + return -ENXIO; ret = devm_request_irq(&pdev->dev, irq, sun4i_spi_handler, 0, "sun4i-spi", sspi); if (ret) { dev_err(&pdev->dev, "Cannot request IRQ\n"); - goto err_free_host; + return ret; } sspi->host = host; @@ -477,15 +471,13 @@ static int sun4i_spi_probe(struct platform_device *pdev) sspi->hclk = devm_clk_get(&pdev->dev, "ahb"); if (IS_ERR(sspi->hclk)) { dev_err(&pdev->dev, "Unable to acquire AHB clock\n"); - ret = PTR_ERR(sspi->hclk); - goto err_free_host; + return PTR_ERR(sspi->hclk); } sspi->mclk = devm_clk_get(&pdev->dev, "mod"); if (IS_ERR(sspi->mclk)) { dev_err(&pdev->dev, "Unable to acquire module clock\n"); - ret = PTR_ERR(sspi->mclk); - goto err_free_host; + return PTR_ERR(sspi->mclk); } init_completion(&sspi->done); @@ -497,7 +489,7 @@ static int sun4i_spi_probe(struct platform_device *pdev) ret = sun4i_spi_runtime_resume(&pdev->dev); if (ret) { dev_err(&pdev->dev, "Couldn't resume the device\n"); - goto err_free_host; + return ret; } pm_runtime_set_active(&pdev->dev); @@ -515,8 +507,7 @@ static int sun4i_spi_probe(struct platform_device *pdev) err_pm_disable: pm_runtime_disable(&pdev->dev); sun4i_spi_runtime_suspend(&pdev->dev); -err_free_host: - spi_controller_put(host); + return ret; } @@ -524,13 +515,9 @@ static void sun4i_spi_remove(struct platform_device *pdev) { struct spi_controller *host = platform_get_drvdata(pdev); - spi_controller_get(host); - spi_unregister_controller(host); pm_runtime_force_suspend(&pdev->dev); - - spi_controller_put(host); } static const struct of_device_id sun4i_spi_match[] = { -- 2.53.0
|  |