]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
spi: sifive: Simplify clock handling with devm_clk_get_enabled()
authorPei Xiao <xiaopei01@kylinos.cn>
Thu, 19 Mar 2026 02:04:05 +0000 (10:04 +0800)
committerMark Brown <broonie@kernel.org>
Mon, 23 Mar 2026 19:47:41 +0000 (19:47 +0000)
Replace devm_clk_get() followed by clk_prepare_enable() with
devm_clk_get_enabled() for the bus clock. This reduces boilerplate code
and error handling, as the managed API automatically disables the clock
when the device is removed or if probe fails.

Remove the now-unnecessary clk_disable_unprepare() calls from the probe
error path and the remove callback. Adjust the error handling to use the
existing put_host label.

Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
Link: https://patch.msgid.link/73d0d8ecb4e1af5a558d6a7866c0f886d94fe3d1.1773885292.git.xiaopei01@kylinos.cn
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-sifive.c

index 6c7aba8befa07d1be3bf4ec244f7a2561879ba89..54adbc057af62bd6374e15346296cc2826133733 100644 (file)
@@ -312,7 +312,8 @@ static int sifive_spi_probe(struct platform_device *pdev)
                goto put_host;
        }
 
-       spi->clk = devm_clk_get(&pdev->dev, NULL);
+       /* Spin up the bus clock before hitting registers */
+       spi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
        if (IS_ERR(spi->clk)) {
                dev_err(&pdev->dev, "Unable to find bus clock\n");
                ret = PTR_ERR(spi->clk);
@@ -342,13 +343,6 @@ static int sifive_spi_probe(struct platform_device *pdev)
                goto put_host;
        }
 
-       /* Spin up the bus clock before hitting registers */
-       ret = clk_prepare_enable(spi->clk);
-       if (ret) {
-               dev_err(&pdev->dev, "Unable to enable bus clock\n");
-               goto put_host;
-       }
-
        /* probe the number of CS lines */
        spi->cs_inactive = sifive_spi_read(spi, SIFIVE_SPI_REG_CSDEF);
        sifive_spi_write(spi, SIFIVE_SPI_REG_CSDEF, 0xffffffffU);
@@ -357,14 +351,14 @@ static int sifive_spi_probe(struct platform_device *pdev)
        if (!cs_bits) {
                dev_err(&pdev->dev, "Could not auto probe CS lines\n");
                ret = -EINVAL;
-               goto disable_clk;
+               goto put_host;
        }
 
        num_cs = ilog2(cs_bits) + 1;
        if (num_cs > SIFIVE_SPI_MAX_CS) {
                dev_err(&pdev->dev, "Invalid number of spi targets\n");
                ret = -EINVAL;
-               goto disable_clk;
+               goto put_host;
        }
 
        /* Define our host */
@@ -392,7 +386,7 @@ static int sifive_spi_probe(struct platform_device *pdev)
                               dev_name(&pdev->dev), spi);
        if (ret) {
                dev_err(&pdev->dev, "Unable to bind to interrupt\n");
-               goto disable_clk;
+               goto put_host;
        }
 
        dev_info(&pdev->dev, "mapped; irq=%d, cs=%d\n",
@@ -401,13 +395,11 @@ static int sifive_spi_probe(struct platform_device *pdev)
        ret = devm_spi_register_controller(&pdev->dev, host);
        if (ret < 0) {
                dev_err(&pdev->dev, "spi_register_host failed\n");
-               goto disable_clk;
+               goto put_host;
        }
 
        return 0;
 
-disable_clk:
-       clk_disable_unprepare(spi->clk);
 put_host:
        spi_controller_put(host);
 
@@ -421,7 +413,6 @@ static void sifive_spi_remove(struct platform_device *pdev)
 
        /* Disable all the interrupts just in case */
        sifive_spi_write(spi, SIFIVE_SPI_REG_IE, 0);
-       clk_disable_unprepare(spi->clk);
 }
 
 static int sifive_spi_suspend(struct device *dev)