diff mbox series

media: i2c: max9286: Use dev_err_probe() helper

Message ID 20211208121756.3051565-1-niklas.soderlund+renesas@ragnatech.se
State Accepted
Commit df78b858e773967112b4444400fb7bb5bd7a9d8a
Headers show
Series media: i2c: max9286: Use dev_err_probe() helper | expand

Commit Message

Niklas Söderlund Dec. 8, 2021, 12:17 p.m. UTC
Use the dev_err_probe() helper, instead of open-coding the same
operation. While at it retrieve the error once and use it from
'ret' instead of retrieving it twice.

Suggested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
 drivers/media/i2c/max9286.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Geert Uytterhoeven Dec. 8, 2021, 12:29 p.m. UTC | #1
Hi Niklas,

On Wed, Dec 8, 2021 at 1:18 PM Niklas Söderlund
<niklas.soderlund+renesas@ragnatech.se> wrote:
> Use the dev_err_probe() helper, instead of open-coding the same
> operation. While at it retrieve the error once and use it from
> 'ret' instead of retrieving it twice.
>
> Suggested-by: Geert Uytterhoeven <geert+renesas@glider.be>

I guess that's too much credit for me ;-)

> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

> --- a/drivers/media/i2c/max9286.c
> +++ b/drivers/media/i2c/max9286.c
> @@ -1295,11 +1295,9 @@ static int max9286_probe(struct i2c_client *client)
>
>         priv->regulator = devm_regulator_get(&client->dev, "poc");
>         if (IS_ERR(priv->regulator)) {
> -               if (PTR_ERR(priv->regulator) != -EPROBE_DEFER)
> -                       dev_err(&client->dev,
> -                               "Unable to get PoC regulator (%ld)\n",
> -                               PTR_ERR(priv->regulator));
>                 ret = PTR_ERR(priv->regulator);
> +               dev_err_probe(&client->dev, ret,
> +                             "Unable to get PoC regulator\n");

You can even combine these two, as dev_err_probe() was designed
to streamline error handling, and thus returns the error again:

    ret = dev_err_probe(&client->dev, PTR_ERR(priv->regulator),
                        "Unable to get PoC regulator\n");

>                 goto err_powerdown;
>         }

Regardless:
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
diff mbox series

Patch

diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c
index 7c663fd587bbeefa..16aa7e5b0e81c210 100644
--- a/drivers/media/i2c/max9286.c
+++ b/drivers/media/i2c/max9286.c
@@ -1295,11 +1295,9 @@  static int max9286_probe(struct i2c_client *client)
 
 	priv->regulator = devm_regulator_get(&client->dev, "poc");
 	if (IS_ERR(priv->regulator)) {
-		if (PTR_ERR(priv->regulator) != -EPROBE_DEFER)
-			dev_err(&client->dev,
-				"Unable to get PoC regulator (%ld)\n",
-				PTR_ERR(priv->regulator));
 		ret = PTR_ERR(priv->regulator);
+		dev_err_probe(&client->dev, ret,
+			      "Unable to get PoC regulator\n");
 		goto err_powerdown;
 	}