]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
spi: sun4i: switch to managed controller allocation
authorJohan Hovold <johan@kernel.org>
Tue, 5 May 2026 07:29:01 +0000 (09:29 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 11 May 2026 00:55:48 +0000 (09:55 +0900)
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>
Link: https://patch.msgid.link/20260505072909.618363-13-johan@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-sun4i.c

index b7fbb5270edbc7c1bd89aaaf69284bdbc783ecc8..d5c16392cd4d7ab84de49e1b36d88016153435ea 100644 (file)
@@ -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[] = {