[PATCH -next 4/4] iio: frequency: adf4350: Use devm_clk_get_enabled() helper function

Jinjie Ruan ruanjinjie at huawei.com
Fri Aug 25 03:57:46 PDT 2023


The devm_clk_get_enabled() helper:
    - calls devm_clk_get()
    - calls clk_prepare_enable() and registers what is needed in order to
      call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code.

Signed-off-by: Jinjie Ruan <ruanjinjie at huawei.com>
---
 drivers/iio/frequency/adf4350.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/drivers/iio/frequency/adf4350.c b/drivers/iio/frequency/adf4350.c
index 85e289700c3c..22330d1768ff 100644
--- a/drivers/iio/frequency/adf4350.c
+++ b/drivers/iio/frequency/adf4350.c
@@ -491,20 +491,14 @@ static int adf4350_probe(struct spi_device *spi)
 	}
 
 	if (!pdata->clkin) {
-		clk = devm_clk_get(&spi->dev, "clkin");
+		clk = devm_clk_get_enabled(&spi->dev, "clkin");
 		if (IS_ERR(clk))
-			return -EPROBE_DEFER;
-
-		ret = clk_prepare_enable(clk);
-		if (ret < 0)
-			return ret;
+			return PTR_ERR(clk);
 	}
 
 	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
-	if (indio_dev == NULL) {
-		ret =  -ENOMEM;
-		goto error_disable_clk;
-	}
+	if (indio_dev == NULL)
+		return -ENOMEM;
 
 	st = iio_priv(indio_dev);
 
@@ -512,7 +506,7 @@ static int adf4350_probe(struct spi_device *spi)
 	if (!IS_ERR(st->reg)) {
 		ret = regulator_enable(st->reg);
 		if (ret)
-			goto error_disable_clk;
+			return ret;
 	}
 
 	spi_set_drvdata(spi, indio_dev);
@@ -564,8 +558,6 @@ static int adf4350_probe(struct spi_device *spi)
 error_disable_reg:
 	if (!IS_ERR(st->reg))
 		regulator_disable(st->reg);
-error_disable_clk:
-	clk_disable_unprepare(clk);
 
 	return ret;
 }
@@ -581,8 +573,6 @@ static void adf4350_remove(struct spi_device *spi)
 
 	iio_device_unregister(indio_dev);
 
-	clk_disable_unprepare(st->clk);
-
 	if (!IS_ERR(reg))
 		regulator_disable(reg);
 }
-- 
2.34.1




More information about the Linux-mediatek mailing list