diff mbox series

[v2,3/3] iio: imu: adis16480: Improve getting the optional clocks

Message ID 20220414131559.24694-3-andriy.shevchenko@linux.intel.com (mailing list archive)
State Accepted
Headers show
Series [v2,1/3] iio: imu: adis16480: Make use of device properties | expand

Commit Message

Andy Shevchenko April 14, 2022, 1:15 p.m. UTC
The extended clocks are optional and may not be present for some
configurations supported by this driver. Nevertheless, in case
the clock is provided but some error happens during its getting,
that error handling should be done properly.

Use devm_clk_get_optional() API and report possible errors using
dev_err_probe() to handle properly -EPROBE_DEFER error.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
---
v2: added tag (Nuno), massaged commit message (Nuno)
 drivers/iio/imu/adis16480.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

Comments

Jonathan Cameron April 27, 2022, 6:37 p.m. UTC | #1
On Thu, 14 Apr 2022 16:15:59 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> The extended clocks are optional and may not be present for some
> configurations supported by this driver. Nevertheless, in case
> the clock is provided but some error happens during its getting,
> that error handling should be done properly.
> 
> Use devm_clk_get_optional() API and report possible errors using
> dev_err_probe() to handle properly -EPROBE_DEFER error.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Series applied with Nuno's Tested-by as sent to v1.

Thanks,

Jonathan

> ---
> v2: added tag (Nuno), massaged commit message (Nuno)
>  drivers/iio/imu/adis16480.c | 26 ++++++++++----------------
>  1 file changed, 10 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
> index 287914016f28..fe520194a837 100644
> --- a/drivers/iio/imu/adis16480.c
> +++ b/drivers/iio/imu/adis16480.c
> @@ -1362,31 +1362,25 @@ static int adis16480_get_ext_clocks(struct adis16480 *st)
>  {
>  	struct device *dev = &st->adis.spi->dev;
>  
> -	st->clk_mode = ADIS16480_CLK_INT;
> -	st->ext_clk = devm_clk_get(dev, "sync");
> -	if (!IS_ERR_OR_NULL(st->ext_clk)) {
> +	st->ext_clk = devm_clk_get_optional(dev, "sync");
> +	if (IS_ERR(st->ext_clk))
> +		return dev_err_probe(dev, PTR_ERR(st->ext_clk), "failed to get ext clk\n");
> +	if (st->ext_clk) {
>  		st->clk_mode = ADIS16480_CLK_SYNC;
>  		return 0;
>  	}
>  
> -	if (PTR_ERR(st->ext_clk) != -ENOENT) {
> -		dev_err(dev, "failed to get ext clk\n");
> -		return PTR_ERR(st->ext_clk);
> -	}
> -
>  	if (st->chip_info->has_pps_clk_mode) {
> -		st->ext_clk = devm_clk_get(dev, "pps");
> -		if (!IS_ERR_OR_NULL(st->ext_clk)) {
> +		st->ext_clk = devm_clk_get_optional(dev, "pps");
> +		if (IS_ERR(st->ext_clk))
> +			return dev_err_probe(dev, PTR_ERR(st->ext_clk), "failed to get ext clk\n");
> +		if (st->ext_clk) {
>  			st->clk_mode = ADIS16480_CLK_PPS;
>  			return 0;
>  		}
> -
> -		if (PTR_ERR(st->ext_clk) != -ENOENT) {
> -			dev_err(dev, "failed to get ext clk\n");
> -			return PTR_ERR(st->ext_clk);
> -		}
>  	}
>  
> +	st->clk_mode = ADIS16480_CLK_INT;
>  	return 0;
>  }
>  
> @@ -1447,7 +1441,7 @@ static int adis16480_probe(struct spi_device *spi)
>  	if (ret)
>  		return ret;
>  
> -	if (!IS_ERR_OR_NULL(st->ext_clk)) {
> +	if (st->ext_clk) {
>  		ret = adis16480_ext_clk_config(st, true);
>  		if (ret)
>  			return ret;
diff mbox series

Patch

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index 287914016f28..fe520194a837 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -1362,31 +1362,25 @@  static int adis16480_get_ext_clocks(struct adis16480 *st)
 {
 	struct device *dev = &st->adis.spi->dev;
 
-	st->clk_mode = ADIS16480_CLK_INT;
-	st->ext_clk = devm_clk_get(dev, "sync");
-	if (!IS_ERR_OR_NULL(st->ext_clk)) {
+	st->ext_clk = devm_clk_get_optional(dev, "sync");
+	if (IS_ERR(st->ext_clk))
+		return dev_err_probe(dev, PTR_ERR(st->ext_clk), "failed to get ext clk\n");
+	if (st->ext_clk) {
 		st->clk_mode = ADIS16480_CLK_SYNC;
 		return 0;
 	}
 
-	if (PTR_ERR(st->ext_clk) != -ENOENT) {
-		dev_err(dev, "failed to get ext clk\n");
-		return PTR_ERR(st->ext_clk);
-	}
-
 	if (st->chip_info->has_pps_clk_mode) {
-		st->ext_clk = devm_clk_get(dev, "pps");
-		if (!IS_ERR_OR_NULL(st->ext_clk)) {
+		st->ext_clk = devm_clk_get_optional(dev, "pps");
+		if (IS_ERR(st->ext_clk))
+			return dev_err_probe(dev, PTR_ERR(st->ext_clk), "failed to get ext clk\n");
+		if (st->ext_clk) {
 			st->clk_mode = ADIS16480_CLK_PPS;
 			return 0;
 		}
-
-		if (PTR_ERR(st->ext_clk) != -ENOENT) {
-			dev_err(dev, "failed to get ext clk\n");
-			return PTR_ERR(st->ext_clk);
-		}
 	}
 
+	st->clk_mode = ADIS16480_CLK_INT;
 	return 0;
 }
 
@@ -1447,7 +1441,7 @@  static int adis16480_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	if (!IS_ERR_OR_NULL(st->ext_clk)) {
+	if (st->ext_clk) {
 		ret = adis16480_ext_clk_config(st, true);
 		if (ret)
 			return ret;