diff mbox series

[v2,02/15] iio: adc: rzg2l_adc: Convert dev_err() to dev_err_probe()

Message ID 20241206111337.726244-3-claudiu.beznea.uj@bp.renesas.com (mailing list archive)
State Accepted
Headers show
Series iio: adc: rzg2l_adc: Add support for RZ/G3S | expand

Commit Message

Claudiu Beznea Dec. 6, 2024, 11:13 a.m. UTC
From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

Convert all occurrences of dev_err() in the probe path to dev_err_probe().
This improves readability and simplifies the code.

Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
---

Changes in v2:
- none, this patch is new

 drivers/iio/adc/rzg2l_adc.c | 64 +++++++++++++------------------------
 1 file changed, 22 insertions(+), 42 deletions(-)

Comments

Jonathan Cameron Dec. 7, 2024, 6:10 p.m. UTC | #1
On Fri,  6 Dec 2024 13:13:24 +0200
Claudiu <claudiu.beznea@tuxon.dev> wrote:

> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> 
> Convert all occurrences of dev_err() in the probe path to dev_err_probe().
> This improves readability and simplifies the code.
> 
> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

Hi Claudiu,

> +	if (IS_ERR(adc->presetn))
> +		return dev_err_probe(dev, PTR_ERR(adc->presetn), "failed to get presetn\n");
>  
>  	ret = reset_control_deassert(adc->adrstn);
> -	if (ret) {
> -		dev_err(&pdev->dev, "failed to deassert adrstn pin, %d\n", ret);
> -		return ret;
> -	}
> +	if (ret)
> +		return dev_err_probe(&pdev->dev, ret, "failed to deassert adrstn pin, %d\n", ret);

Take a closer look at the implementation of dev_err_probe().
It already prints the return code (where appropriate) and in a pretty text form
which is easier to read.  So we should not print it again.

I'd also prefer wrapping some of the longer lines in here a little earlier.  For IIO
I still prefer to stay under 80 chars or only a little over it where it doesn't
hurt readability.

Jonathan
Lad, Prabhakar Dec. 8, 2024, 7:43 p.m. UTC | #2
On Fri, Dec 6, 2024 at 11:14 AM Claudiu <claudiu.beznea@tuxon.dev> wrote:
>
> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
>
> Convert all occurrences of dev_err() in the probe path to dev_err_probe().
> This improves readability and simplifies the code.
>
> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> ---
>
> Changes in v2:
> - none, this patch is new
>
>  drivers/iio/adc/rzg2l_adc.c | 64 +++++++++++++------------------------
>  1 file changed, 22 insertions(+), 42 deletions(-)
>
With comments fixed from Jonathan,

Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Cheers,
Prabhakar

> diff --git a/drivers/iio/adc/rzg2l_adc.c b/drivers/iio/adc/rzg2l_adc.c
> index cd3a7e46ea53..8a804f81c04b 100644
> --- a/drivers/iio/adc/rzg2l_adc.c
> +++ b/drivers/iio/adc/rzg2l_adc.c
> @@ -313,15 +313,11 @@ static int rzg2l_adc_parse_properties(struct platform_device *pdev, struct rzg2l
>                 return -ENOMEM;
>
>         num_channels = device_get_child_node_count(&pdev->dev);
> -       if (!num_channels) {
> -               dev_err(&pdev->dev, "no channel children\n");
> -               return -ENODEV;
> -       }
> +       if (!num_channels)
> +               return dev_err_probe(&pdev->dev, -ENODEV, "no channel children\n");
>
> -       if (num_channels > RZG2L_ADC_MAX_CHANNELS) {
> -               dev_err(&pdev->dev, "num of channel children out of range\n");
> -               return -EINVAL;
> -       }
> +       if (num_channels > RZG2L_ADC_MAX_CHANNELS)
> +               return dev_err_probe(&pdev->dev, -EINVAL, "num of channel children out of range\n");
>
>         chan_array = devm_kcalloc(&pdev->dev, num_channels, sizeof(*chan_array),
>                                   GFP_KERNEL);
> @@ -445,62 +441,46 @@ static int rzg2l_adc_probe(struct platform_device *pdev)
>                 return PTR_ERR(adc->base);
>
>         adc->pclk = devm_clk_get(dev, "pclk");
> -       if (IS_ERR(adc->pclk)) {
> -               dev_err(dev, "Failed to get pclk");
> -               return PTR_ERR(adc->pclk);
> -       }
> +       if (IS_ERR(adc->pclk))
> +               return dev_err_probe(dev, PTR_ERR(adc->pclk), "Failed to get pclk");
>
>         adc->adclk = devm_clk_get(dev, "adclk");
> -       if (IS_ERR(adc->adclk)) {
> -               dev_err(dev, "Failed to get adclk");
> -               return PTR_ERR(adc->adclk);
> -       }
> +       if (IS_ERR(adc->adclk))
> +               return dev_err_probe(dev, PTR_ERR(adc->adclk), "Failed to get adclk");
>
>         adc->adrstn = devm_reset_control_get_exclusive(dev, "adrst-n");
> -       if (IS_ERR(adc->adrstn)) {
> -               dev_err(dev, "failed to get adrstn\n");
> -               return PTR_ERR(adc->adrstn);
> -       }
> +       if (IS_ERR(adc->adrstn))
> +               return dev_err_probe(dev, PTR_ERR(adc->adrstn), "failed to get adrstn\n");
>
>         adc->presetn = devm_reset_control_get_exclusive(dev, "presetn");
> -       if (IS_ERR(adc->presetn)) {
> -               dev_err(dev, "failed to get presetn\n");
> -               return PTR_ERR(adc->presetn);
> -       }
> +       if (IS_ERR(adc->presetn))
> +               return dev_err_probe(dev, PTR_ERR(adc->presetn), "failed to get presetn\n");
>
>         ret = reset_control_deassert(adc->adrstn);
> -       if (ret) {
> -               dev_err(&pdev->dev, "failed to deassert adrstn pin, %d\n", ret);
> -               return ret;
> -       }
> +       if (ret)
> +               return dev_err_probe(&pdev->dev, ret, "failed to deassert adrstn pin, %d\n", ret);
>
>         ret = devm_add_action_or_reset(&pdev->dev,
>                                        rzg2l_adc_reset_assert, adc->adrstn);
>         if (ret) {
> -               dev_err(&pdev->dev, "failed to register adrstn assert devm action, %d\n",
> -                       ret);
> -               return ret;
> +               return dev_err_probe(&pdev->dev, ret,
> +                                    "failed to register adrstn assert devm action, %d\n", ret);
>         }
>
>         ret = reset_control_deassert(adc->presetn);
> -       if (ret) {
> -               dev_err(&pdev->dev, "failed to deassert presetn pin, %d\n", ret);
> -               return ret;
> -       }
> +       if (ret)
> +               return dev_err_probe(&pdev->dev, ret, "failed to deassert presetn pin, %d\n", ret);
>
>         ret = devm_add_action_or_reset(&pdev->dev,
>                                        rzg2l_adc_reset_assert, adc->presetn);
>         if (ret) {
> -               dev_err(&pdev->dev, "failed to register presetn assert devm action, %d\n",
> -                       ret);
> -               return ret;
> +               return dev_err_probe(&pdev->dev, ret,
> +                                    "failed to register presetn assert devm action, %d\n", ret);
>         }
>
>         ret = rzg2l_adc_hw_init(adc);
> -       if (ret) {
> -               dev_err(&pdev->dev, "failed to initialize ADC HW, %d\n", ret);
> -               return ret;
> -       }
> +       if (ret)
> +               return dev_err_probe(&pdev->dev, ret, "failed to initialize ADC HW, %d\n", ret);
>
>         irq = platform_get_irq(pdev, 0);
>         if (irq < 0)
> --
> 2.39.2
>
>
diff mbox series

Patch

diff --git a/drivers/iio/adc/rzg2l_adc.c b/drivers/iio/adc/rzg2l_adc.c
index cd3a7e46ea53..8a804f81c04b 100644
--- a/drivers/iio/adc/rzg2l_adc.c
+++ b/drivers/iio/adc/rzg2l_adc.c
@@ -313,15 +313,11 @@  static int rzg2l_adc_parse_properties(struct platform_device *pdev, struct rzg2l
 		return -ENOMEM;
 
 	num_channels = device_get_child_node_count(&pdev->dev);
-	if (!num_channels) {
-		dev_err(&pdev->dev, "no channel children\n");
-		return -ENODEV;
-	}
+	if (!num_channels)
+		return dev_err_probe(&pdev->dev, -ENODEV, "no channel children\n");
 
-	if (num_channels > RZG2L_ADC_MAX_CHANNELS) {
-		dev_err(&pdev->dev, "num of channel children out of range\n");
-		return -EINVAL;
-	}
+	if (num_channels > RZG2L_ADC_MAX_CHANNELS)
+		return dev_err_probe(&pdev->dev, -EINVAL, "num of channel children out of range\n");
 
 	chan_array = devm_kcalloc(&pdev->dev, num_channels, sizeof(*chan_array),
 				  GFP_KERNEL);
@@ -445,62 +441,46 @@  static int rzg2l_adc_probe(struct platform_device *pdev)
 		return PTR_ERR(adc->base);
 
 	adc->pclk = devm_clk_get(dev, "pclk");
-	if (IS_ERR(adc->pclk)) {
-		dev_err(dev, "Failed to get pclk");
-		return PTR_ERR(adc->pclk);
-	}
+	if (IS_ERR(adc->pclk))
+		return dev_err_probe(dev, PTR_ERR(adc->pclk), "Failed to get pclk");
 
 	adc->adclk = devm_clk_get(dev, "adclk");
-	if (IS_ERR(adc->adclk)) {
-		dev_err(dev, "Failed to get adclk");
-		return PTR_ERR(adc->adclk);
-	}
+	if (IS_ERR(adc->adclk))
+		return dev_err_probe(dev, PTR_ERR(adc->adclk), "Failed to get adclk");
 
 	adc->adrstn = devm_reset_control_get_exclusive(dev, "adrst-n");
-	if (IS_ERR(adc->adrstn)) {
-		dev_err(dev, "failed to get adrstn\n");
-		return PTR_ERR(adc->adrstn);
-	}
+	if (IS_ERR(adc->adrstn))
+		return dev_err_probe(dev, PTR_ERR(adc->adrstn), "failed to get adrstn\n");
 
 	adc->presetn = devm_reset_control_get_exclusive(dev, "presetn");
-	if (IS_ERR(adc->presetn)) {
-		dev_err(dev, "failed to get presetn\n");
-		return PTR_ERR(adc->presetn);
-	}
+	if (IS_ERR(adc->presetn))
+		return dev_err_probe(dev, PTR_ERR(adc->presetn), "failed to get presetn\n");
 
 	ret = reset_control_deassert(adc->adrstn);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to deassert adrstn pin, %d\n", ret);
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret, "failed to deassert adrstn pin, %d\n", ret);
 
 	ret = devm_add_action_or_reset(&pdev->dev,
 				       rzg2l_adc_reset_assert, adc->adrstn);
 	if (ret) {
-		dev_err(&pdev->dev, "failed to register adrstn assert devm action, %d\n",
-			ret);
-		return ret;
+		return dev_err_probe(&pdev->dev, ret,
+				     "failed to register adrstn assert devm action, %d\n", ret);
 	}
 
 	ret = reset_control_deassert(adc->presetn);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to deassert presetn pin, %d\n", ret);
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret, "failed to deassert presetn pin, %d\n", ret);
 
 	ret = devm_add_action_or_reset(&pdev->dev,
 				       rzg2l_adc_reset_assert, adc->presetn);
 	if (ret) {
-		dev_err(&pdev->dev, "failed to register presetn assert devm action, %d\n",
-			ret);
-		return ret;
+		return dev_err_probe(&pdev->dev, ret,
+				     "failed to register presetn assert devm action, %d\n", ret);
 	}
 
 	ret = rzg2l_adc_hw_init(adc);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to initialize ADC HW, %d\n", ret);
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret, "failed to initialize ADC HW, %d\n", ret);
 
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0)