diff mbox series

[05/24] Input: pwm-beeper - Simplify with dev_err_probe()

Message ID 20200826181706.11098-5-krzk@kernel.org (mailing list archive)
State Superseded
Headers show
Series [01/24] Input: bcm-keypad - Simplify with dev_err_probe() | expand

Commit Message

Krzysztof Kozlowski Aug. 26, 2020, 6:16 p.m. UTC
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>
---
 drivers/input/misc/pwm-beeper.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

Comments

Andy Shevchenko Aug. 27, 2020, 9:07 a.m. UTC | #1
On Wed, Aug 26, 2020 at 9:18 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.
>

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
> ---
>  drivers/input/misc/pwm-beeper.c | 19 +++++--------------
>  1 file changed, 5 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c
> index d6b12477748a..8c0085e8c552 100644
> --- a/drivers/input/misc/pwm-beeper.c
> +++ b/drivers/input/misc/pwm-beeper.c
> @@ -132,13 +132,8 @@ static int pwm_beeper_probe(struct platform_device *pdev)
>                 return -ENOMEM;
>
>         beeper->pwm = devm_pwm_get(dev, NULL);
> -       if (IS_ERR(beeper->pwm)) {
> -               error = PTR_ERR(beeper->pwm);
> -               if (error != -EPROBE_DEFER)
> -                       dev_err(dev, "Failed to request PWM device: %d\n",
> -                               error);
> -               return error;
> -       }
> +       if (IS_ERR(beeper->pwm))
> +               return dev_err_probe(dev, PTR_ERR(beeper->pwm), "Failed to request PWM device\n");
>
>         /* Sync up PWM state and ensure it is off. */
>         pwm_init_state(beeper->pwm, &state);
> @@ -151,13 +146,9 @@ static int pwm_beeper_probe(struct platform_device *pdev)
>         }
>
>         beeper->amplifier = devm_regulator_get(dev, "amp");
> -       if (IS_ERR(beeper->amplifier)) {
> -               error = PTR_ERR(beeper->amplifier);
> -               if (error != -EPROBE_DEFER)
> -                       dev_err(dev, "Failed to get 'amp' regulator: %d\n",
> -                               error);
> -               return error;
> -       }
> +       if (IS_ERR(beeper->amplifier))
> +               return dev_err_probe(dev, PTR_ERR(beeper->amplifier),
> +                                    "Failed to get 'amp' regulator\n");
>
>         INIT_WORK(&beeper->work, pwm_beeper_work);
>
> --
> 2.17.1
>
diff mbox series

Patch

diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c
index d6b12477748a..8c0085e8c552 100644
--- a/drivers/input/misc/pwm-beeper.c
+++ b/drivers/input/misc/pwm-beeper.c
@@ -132,13 +132,8 @@  static int pwm_beeper_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	beeper->pwm = devm_pwm_get(dev, NULL);
-	if (IS_ERR(beeper->pwm)) {
-		error = PTR_ERR(beeper->pwm);
-		if (error != -EPROBE_DEFER)
-			dev_err(dev, "Failed to request PWM device: %d\n",
-				error);
-		return error;
-	}
+	if (IS_ERR(beeper->pwm))
+		return dev_err_probe(dev, PTR_ERR(beeper->pwm), "Failed to request PWM device\n");
 
 	/* Sync up PWM state and ensure it is off. */
 	pwm_init_state(beeper->pwm, &state);
@@ -151,13 +146,9 @@  static int pwm_beeper_probe(struct platform_device *pdev)
 	}
 
 	beeper->amplifier = devm_regulator_get(dev, "amp");
-	if (IS_ERR(beeper->amplifier)) {
-		error = PTR_ERR(beeper->amplifier);
-		if (error != -EPROBE_DEFER)
-			dev_err(dev, "Failed to get 'amp' regulator: %d\n",
-				error);
-		return error;
-	}
+	if (IS_ERR(beeper->amplifier))
+		return dev_err_probe(dev, PTR_ERR(beeper->amplifier),
+				     "Failed to get 'amp' regulator\n");
 
 	INIT_WORK(&beeper->work, pwm_beeper_work);