linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] iio: adc: stm32: Simplify with dev_err_probe()
@ 2020-08-26 16:18 Krzysztof Kozlowski
  2020-08-27  8:27 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Krzysztof Kozlowski @ 2020-08-26 16:18 UTC (permalink / raw)
  To: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Maxime Coquelin, Alexandre Torgue,
	Fabrice Gasnier, Etienne Carriere, Krzysztof Kozlowski,
	Alexandru Ardelean, linux-iio, linux-stm32, linux-arm-kernel,
	linux-kernel

Common pattern of handling deferred probe can be simplified with
dev_err_probe().  Less code and also it prints the error value.

Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>

---

Changes since v1:
1. Update also stm32-dfsdm-core and stm32-dac-core.
2. Wrap around 100 characters (accepted by checkpatch).
---
 drivers/iio/adc/stm32-adc-core.c   | 57 ++++++++++--------------------
 drivers/iio/adc/stm32-adc.c        |  9 ++---
 drivers/iio/adc/stm32-dfsdm-adc.c  |  9 ++---
 drivers/iio/adc/stm32-dfsdm-core.c |  8 ++---
 drivers/iio/dac/stm32-dac-core.c   |  5 +--
 5 files changed, 26 insertions(+), 62 deletions(-)

diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c
index 0e2068ec068b..d7bd4e28966c 100644
--- a/drivers/iio/adc/stm32-adc-core.c
+++ b/drivers/iio/adc/stm32-adc-core.c
@@ -582,11 +582,9 @@ static int stm32_adc_core_switches_probe(struct device *dev,
 	priv->syscfg = syscon_regmap_lookup_by_phandle(np, "st,syscfg");
 	if (IS_ERR(priv->syscfg)) {
 		ret = PTR_ERR(priv->syscfg);
-		if (ret != -ENODEV) {
-			if (ret != -EPROBE_DEFER)
-				dev_err(dev, "Can't probe syscfg: %d\n", ret);
-			return ret;
-		}
+		if (ret != -ENODEV)
+			return dev_err_probe(dev, ret, "Can't probe syscfg\n");
+
 		priv->syscfg = NULL;
 	}
 
@@ -596,12 +594,9 @@ static int stm32_adc_core_switches_probe(struct device *dev,
 		priv->booster = devm_regulator_get_optional(dev, "booster");
 		if (IS_ERR(priv->booster)) {
 			ret = PTR_ERR(priv->booster);
-			if (ret != -ENODEV) {
-				if (ret != -EPROBE_DEFER)
-					dev_err(dev, "can't get booster %d\n",
-						ret);
-				return ret;
-			}
+			if (ret != -ENODEV)
+				dev_err_probe(dev, ret, "can't get booster\n");
+
 			priv->booster = NULL;
 		}
 	}
@@ -612,11 +607,9 @@ static int stm32_adc_core_switches_probe(struct device *dev,
 		priv->vdd = devm_regulator_get_optional(dev, "vdd");
 		if (IS_ERR(priv->vdd)) {
 			ret = PTR_ERR(priv->vdd);
-			if (ret != -ENODEV) {
-				if (ret != -EPROBE_DEFER)
-					dev_err(dev, "can't get vdd %d\n", ret);
-				return ret;
-			}
+			if (ret != -ENODEV)
+				return dev_err_probe(dev, ret, "can't get vdd\n");
+
 			priv->vdd = NULL;
 		}
 	}
@@ -669,40 +662,28 @@ static int stm32_adc_probe(struct platform_device *pdev)
 	priv->common.phys_base = res->start;
 
 	priv->vdda = devm_regulator_get(&pdev->dev, "vdda");
-	if (IS_ERR(priv->vdda)) {
-		ret = PTR_ERR(priv->vdda);
-		if (ret != -EPROBE_DEFER)
-			dev_err(&pdev->dev, "vdda get failed, %d\n", ret);
-		return ret;
-	}
+	if (IS_ERR(priv->vdda))
+		return dev_err_probe(&pdev->dev, PTR_ERR(priv->vdda), "vdda get failed\n");
 
 	priv->vref = devm_regulator_get(&pdev->dev, "vref");
-	if (IS_ERR(priv->vref)) {
-		ret = PTR_ERR(priv->vref);
-		if (ret != -EPROBE_DEFER)
-			dev_err(&pdev->dev, "vref get failed, %d\n", ret);
-		return ret;
-	}
+	if (IS_ERR(priv->vref))
+		return dev_err_probe(&pdev->dev, PTR_ERR(priv->vref), "vref get failed\n");
 
 	priv->aclk = devm_clk_get(&pdev->dev, "adc");
 	if (IS_ERR(priv->aclk)) {
 		ret = PTR_ERR(priv->aclk);
-		if (ret != -ENOENT) {
-			if (ret != -EPROBE_DEFER)
-				dev_err(&pdev->dev, "Can't get 'adc' clock\n");
-			return ret;
-		}
+		if (ret != -ENOENT)
+			return dev_err_probe(&pdev->dev, ret, "Can't get 'adc' clock\n");
+
 		priv->aclk = NULL;
 	}
 
 	priv->bclk = devm_clk_get(&pdev->dev, "bus");
 	if (IS_ERR(priv->bclk)) {
 		ret = PTR_ERR(priv->bclk);
-		if (ret != -ENOENT) {
-			if (ret != -EPROBE_DEFER)
-				dev_err(&pdev->dev, "Can't get 'bus' clock\n");
-			return ret;
-		}
+		if (ret != -ENOENT)
+			return dev_err_probe(&pdev->dev, ret, "Can't get 'bus' clock\n");
+
 		priv->bclk = NULL;
 	}
 
diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
index 3eb9ebe8372f..b8e764ca54a6 100644
--- a/drivers/iio/adc/stm32-adc.c
+++ b/drivers/iio/adc/stm32-adc.c
@@ -1805,13 +1805,8 @@ static int stm32_adc_dma_request(struct device *dev, struct iio_dev *indio_dev)
 	adc->dma_chan = dma_request_chan(dev, "rx");
 	if (IS_ERR(adc->dma_chan)) {
 		ret = PTR_ERR(adc->dma_chan);
-		if (ret != -ENODEV) {
-			if (ret != -EPROBE_DEFER)
-				dev_err(dev,
-					"DMA channel request failed with %d\n",
-					ret);
-			return ret;
-		}
+		if (ret != -ENODEV)
+			return dev_err_probe(dev, ret, "DMA channel request failed with\n");
 
 		/* DMA is optional: fall back to IRQ mode */
 		adc->dma_chan = NULL;
diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c
index 5e10fb4f3704..12c951078c1f 100644
--- a/drivers/iio/adc/stm32-dfsdm-adc.c
+++ b/drivers/iio/adc/stm32-dfsdm-adc.c
@@ -1473,13 +1473,8 @@ static int stm32_dfsdm_adc_init(struct device *dev, struct iio_dev *indio_dev)
 	/* Optionally request DMA */
 	ret = stm32_dfsdm_dma_request(dev, indio_dev);
 	if (ret) {
-		if (ret != -ENODEV) {
-			if (ret != -EPROBE_DEFER)
-				dev_err(dev,
-					"DMA channel request failed with %d\n",
-					ret);
-			return ret;
-		}
+		if (ret != -ENODEV)
+			return dev_err_probe(dev, ret, "DMA channel request failed with\n");
 
 		dev_dbg(dev, "No DMA support\n");
 		return 0;
diff --git a/drivers/iio/adc/stm32-dfsdm-core.c b/drivers/iio/adc/stm32-dfsdm-core.c
index 26e2011c5868..34e4e6e59acf 100644
--- a/drivers/iio/adc/stm32-dfsdm-core.c
+++ b/drivers/iio/adc/stm32-dfsdm-core.c
@@ -243,12 +243,8 @@ static int stm32_dfsdm_parse_of(struct platform_device *pdev,
 	 * on use case.
 	 */
 	priv->clk = devm_clk_get(&pdev->dev, "dfsdm");
-	if (IS_ERR(priv->clk)) {
-		ret = PTR_ERR(priv->clk);
-		if (ret != -EPROBE_DEFER)
-			dev_err(&pdev->dev, "Failed to get clock (%d)\n", ret);
-		return ret;
-	}
+	if (IS_ERR(priv->clk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(priv->clk), "Failed to get clock\n");
 
 	priv->aclk = devm_clk_get(&pdev->dev, "audio");
 	if (IS_ERR(priv->aclk))
diff --git a/drivers/iio/dac/stm32-dac-core.c b/drivers/iio/dac/stm32-dac-core.c
index 7e5809ba0dee..906436780347 100644
--- a/drivers/iio/dac/stm32-dac-core.c
+++ b/drivers/iio/dac/stm32-dac-core.c
@@ -150,10 +150,7 @@ static int stm32_dac_probe(struct platform_device *pdev)
 	rst = devm_reset_control_get_optional_exclusive(dev, NULL);
 	if (rst) {
 		if (IS_ERR(rst)) {
-			ret = PTR_ERR(rst);
-			if (ret != -EPROBE_DEFER)
-				dev_err(dev, "reset get failed, %d\n", ret);
-
+			ret = dev_err_probe(dev, PTR_ERR(rst), "reset get failed\n");
 			goto err_hw_stop;
 		}
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] iio: adc: stm32: Simplify with dev_err_probe()
  2020-08-26 16:18 [PATCH v2] iio: adc: stm32: Simplify with dev_err_probe() Krzysztof Kozlowski
@ 2020-08-27  8:27 ` Andy Shevchenko
  2020-08-27 19:06   ` Krzysztof Kozlowski
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2020-08-27  8:27 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Maxime Coquelin, Alexandre Torgue,
	Fabrice Gasnier, Etienne Carriere, Alexandru Ardelean, linux-iio,
	linux-stm32, linux-arm Mailing List, Linux Kernel Mailing List

On Wed, Aug 26, 2020 at 7:19 PM Krzysztof Kozlowski <krzk@kernel.org> wrote:
>
> Common pattern of handling deferred probe can be simplified with
> dev_err_probe().  Less code and also it prints the error value.






>         priv->aclk = devm_clk_get(&pdev->dev, "adc");
>         if (IS_ERR(priv->aclk)) {
>                 ret = PTR_ERR(priv->aclk);
> -               if (ret != -ENOENT) {
> -                       if (ret != -EPROBE_DEFER)
> -                               dev_err(&pdev->dev, "Can't get 'adc' clock\n");
> -                       return ret;
> -               }
> +               if (ret != -ENOENT)
> +                       return dev_err_probe(&pdev->dev, ret, "Can't get 'adc' clock\n");
> +
>                 priv->aclk = NULL;
>         }
>
>         priv->bclk = devm_clk_get(&pdev->dev, "bus");
>         if (IS_ERR(priv->bclk)) {
>                 ret = PTR_ERR(priv->bclk);
> -               if (ret != -ENOENT) {
> -                       if (ret != -EPROBE_DEFER)
> -                               dev_err(&pdev->dev, "Can't get 'bus' clock\n");
> -                       return ret;
> -               }
> +               if (ret != -ENOENT)
> +                       return dev_err_probe(&pdev->dev, ret, "Can't get 'bus' clock\n");
> +
>                 priv->bclk = NULL;
>         }

Again, devm_clk_get_optional() and even, if it exists,
devm_clk_bulk_get_optional().

Please, revisit all patches on this topic.

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] iio: adc: stm32: Simplify with dev_err_probe()
  2020-08-27  8:27 ` Andy Shevchenko
@ 2020-08-27 19:06   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2020-08-27 19:06 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Maxime Coquelin, Alexandre Torgue,
	Fabrice Gasnier, Etienne Carriere, Alexandru Ardelean, linux-iio,
	linux-stm32, linux-arm Mailing List, Linux Kernel Mailing List

On Thu, Aug 27, 2020 at 11:27:12AM +0300, Andy Shevchenko wrote:
> On Wed, Aug 26, 2020 at 7:19 PM Krzysztof Kozlowski <krzk@kernel.org> wrote:
> >
> > Common pattern of handling deferred probe can be simplified with
> > dev_err_probe().  Less code and also it prints the error value.
> 
> 
> 
> 
> 
> 
> >         priv->aclk = devm_clk_get(&pdev->dev, "adc");
> >         if (IS_ERR(priv->aclk)) {
> >                 ret = PTR_ERR(priv->aclk);
> > -               if (ret != -ENOENT) {
> > -                       if (ret != -EPROBE_DEFER)
> > -                               dev_err(&pdev->dev, "Can't get 'adc' clock\n");
> > -                       return ret;
> > -               }
> > +               if (ret != -ENOENT)
> > +                       return dev_err_probe(&pdev->dev, ret, "Can't get 'adc' clock\n");
> > +
> >                 priv->aclk = NULL;
> >         }
> >
> >         priv->bclk = devm_clk_get(&pdev->dev, "bus");
> >         if (IS_ERR(priv->bclk)) {
> >                 ret = PTR_ERR(priv->bclk);
> > -               if (ret != -ENOENT) {
> > -                       if (ret != -EPROBE_DEFER)
> > -                               dev_err(&pdev->dev, "Can't get 'bus' clock\n");
> > -                       return ret;
> > -               }
> > +               if (ret != -ENOENT)
> > +                       return dev_err_probe(&pdev->dev, ret, "Can't get 'bus' clock\n");
> > +
> >                 priv->bclk = NULL;
> >         }
> 
> Again, devm_clk_get_optional() and even, if it exists,
> devm_clk_bulk_get_optional().

Sure.

> 
> Please, revisit all patches on this topic.

I'll check them.


Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-08-27 19:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-26 16:18 [PATCH v2] iio: adc: stm32: Simplify with dev_err_probe() Krzysztof Kozlowski
2020-08-27  8:27 ` Andy Shevchenko
2020-08-27 19:06   ` Krzysztof Kozlowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).