diff mbox series

[04/24] Input: gpio-vibra - Simplify with dev_err_probe()

Message ID 20200826181706.11098-4-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/gpio-vibra.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

Comments

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

>         vibrator->vcc = devm_regulator_get(&pdev->dev, "vcc");
>         err = PTR_ERR_OR_ZERO(vibrator->vcc);
> -       if (err) {
> -               if (err != -EPROBE_DEFER)
> -                       dev_err(&pdev->dev, "Failed to request regulator: %d\n",
> -                               err);
> -               return err;
> -       }
> +       if (err)
> +               return dev_err_probe(&pdev->dev, err, "Failed to request regulator\n");

Can it be rather
  if (IS_ERR())
    return dev_err_probe(dev, PTR_ERR());
w/o err be involved?

>         vibrator->gpio = devm_gpiod_get(&pdev->dev, "enable", GPIOD_OUT_LOW);
>         err = PTR_ERR_OR_ZERO(vibrator->gpio);
> -       if (err) {
> -               if (err != -EPROBE_DEFER)
> -                       dev_err(&pdev->dev, "Failed to request main gpio: %d\n",
> -                               err);
> -               return err;
> -       }
> +       if (err)
> +               return dev_err_probe(&pdev->dev, err, "Failed to request main gpio\n");

Ditto.
Krzysztof Kozlowski Aug. 27, 2020, 6:40 p.m. UTC | #2
On Thu, Aug 27, 2020 at 12:03:52PM +0300, Andy Shevchenko wrote:
> On Wed, Aug 26, 2020 at 9:20 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.
> 
> >         vibrator->vcc = devm_regulator_get(&pdev->dev, "vcc");
> >         err = PTR_ERR_OR_ZERO(vibrator->vcc);
> > -       if (err) {
> > -               if (err != -EPROBE_DEFER)
> > -                       dev_err(&pdev->dev, "Failed to request regulator: %d\n",
> > -                               err);
> > -               return err;
> > -       }
> > +       if (err)
> > +               return dev_err_probe(&pdev->dev, err, "Failed to request regulator\n");
> 
> Can it be rather
>   if (IS_ERR())
>     return dev_err_probe(dev, PTR_ERR());
> w/o err be involved?

Good point.

Best regards,
Krzysztof
diff mbox series

Patch

diff --git a/drivers/input/misc/gpio-vibra.c b/drivers/input/misc/gpio-vibra.c
index f79f75595dd7..53042e0ba9ee 100644
--- a/drivers/input/misc/gpio-vibra.c
+++ b/drivers/input/misc/gpio-vibra.c
@@ -114,21 +114,13 @@  static int gpio_vibrator_probe(struct platform_device *pdev)
 
 	vibrator->vcc = devm_regulator_get(&pdev->dev, "vcc");
 	err = PTR_ERR_OR_ZERO(vibrator->vcc);
-	if (err) {
-		if (err != -EPROBE_DEFER)
-			dev_err(&pdev->dev, "Failed to request regulator: %d\n",
-				err);
-		return err;
-	}
+	if (err)
+		return dev_err_probe(&pdev->dev, err, "Failed to request regulator\n");
 
 	vibrator->gpio = devm_gpiod_get(&pdev->dev, "enable", GPIOD_OUT_LOW);
 	err = PTR_ERR_OR_ZERO(vibrator->gpio);
-	if (err) {
-		if (err != -EPROBE_DEFER)
-			dev_err(&pdev->dev, "Failed to request main gpio: %d\n",
-				err);
-		return err;
-	}
+	if (err)
+		return dev_err_probe(&pdev->dev, err, "Failed to request main gpio\n");
 
 	INIT_WORK(&vibrator->play_work, gpio_vibrator_play_work);