[PATCH v5 03/17] spi: bcmbca-hsspi: Simplify clock handling with devm_clk_get_enabled()

Pei Xiao
2026-03-19T22:48:36Z

devm_clk_get_enabled() for both the "hsspi" and "pll" clocks. This
reduces boilerplate code and error handling, as the managed API
automatically disables the clocks when the device is removed or if
probe fails.

Remove the now-unnecessary clk_disable_unprepare() calls from the
probe error paths and the remove callback. Simplify the error handling
by converting to direct returns with dev_err_probe() where appropriate.

Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
---
drivers/spi/spi-bcmbca-hsspi.c | 49 +++++++++++-----------------------
1 file changed, 16 insertions(+), 33 deletions(-)

diff --git a/drivers/spi/spi-bcmbca-hsspi.c b/drivers/spi/spi-bcmbca-hsspi.c
index ece22260f570..2e22345115fd 100644
--- a/drivers/spi/spi-bcmbca-hsspi.c
+++ b/drivers/spi/spi-bcmbca-hsspi.c
@@ -452,39 +452,30 @@ static int bcmbca_hsspi_probe(struct platform_device *pdev)
if (IS_ERR(spim_ctrl))
return PTR_ERR(spim_ctrl);

- clk = devm_clk_get(dev, "hsspi");
+ clk = devm_clk_get_enabled(dev, "hsspi");
if (IS_ERR(clk))
- return PTR_ERR(clk);
-
- ret = clk_prepare_enable(clk);
- if (ret)
- return ret;
+ return dev_err_probe(dev, PTR_ERR(clk),
+ "Failed to get hsspi clock\n");

rate = clk_get_rate(clk);
if (!rate) {
- pll_clk = devm_clk_get(dev, "pll");
+ pll_clk = devm_clk_get_enabled(dev, "pll");

if (IS_ERR(pll_clk)) {
- ret = PTR_ERR(pll_clk);
- goto out_disable_clk;
+ return dev_err_probe(dev, PTR_ERR(pll_clk),
+ "Failed to get pll clock\n");
}

- ret = clk_prepare_enable(pll_clk);
- if (ret)
- goto out_disable_clk;
-
rate = clk_get_rate(pll_clk);
- if (!rate) {
- ret = -EINVAL;
- goto out_disable_pll_clk;
- }
+ if (!rate)
+ return dev_err_probe(dev, -EINVAL,
+ "Failed to get pll clock rate\n");
}

host = devm_spi_alloc_host(&pdev->dev, sizeof(*bs));
- if (!host) {
- ret = -ENOMEM;
- goto out_disable_pll_clk;
- }
+ if (!host)
+ return dev_err_probe(dev, -ENOMEM,
+ "Failed alloc spi host\n");

bs = spi_controller_get_devdata(host);
bs->pdev = pdev;
@@ -535,18 +526,16 @@ static int bcmbca_hsspi_probe(struct platform_device *pdev)
ret = devm_request_irq(dev, irq, bcmbca_hsspi_interrupt, IRQF_SHARED,
pdev->name, bs);
if (ret)
- goto out_disable_pll_clk;
+ return dev_err_probe(dev, ret, "Failed request irq\n");
}

ret = devm_pm_runtime_enable(&pdev->dev);
if (ret)
- goto out_disable_pll_clk;
+ return dev_err_probe(dev, ret, "Failed pm runtime enable\n");

ret = sysfs_create_group(&pdev->dev.kobj, &bcmbca_hsspi_group);
- if (ret) {
- dev_err(&pdev->dev, "couldn't register sysfs group\n");
- goto out_disable_pll_clk;
- }
+ if (ret)
+ return dev_err_probe(dev, ret, "couldn't register sysfs group\n");

/* register and we are done */
ret = devm_spi_register_controller(dev, host);
@@ -559,10 +548,6 @@ static int bcmbca_hsspi_probe(struct platform_device *pdev)

out_sysgroup_disable:
sysfs_remove_group(&pdev->dev.kobj, &bcmbca_hsspi_group);
-out_disable_pll_clk:
- clk_disable_unprepare(pll_clk);
-out_disable_clk:
- clk_disable_unprepare(clk);
return ret;
}

@@ -573,8 +558,6 @@ static void bcmbca_hsspi_remove(struct platform_device *pdev)

/* reset the hardware and block queue progress */
__raw_writel(0, bs->regs + HSSPI_INT_MASK_REG);
- clk_disable_unprepare(bs->pll_clk);
- clk_disable_unprepare(bs->clk);
sysfs_remove_group(&pdev->dev.kobj, &bcmbca_hsspi_group);
}

--
2.25.1