2020-08-11 03:50:17

by Anson Huang

[permalink] [raw]
Subject: [PATCH 1/3] iio: accel: mma8452: Use dev_err_probe() to simplify error handling

dev_err_probe() can reduce code size, uniform error handling and record the
defer probe reason etc., use it to simplify the code.

Signed-off-by: Anson Huang <[email protected]>
---
drivers/iio/accel/mma8452.c | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index ba27f86..9b5f23b 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -1538,22 +1538,14 @@ static int mma8452_probe(struct i2c_client *client,
data->chip_info = match->data;

data->vdd_reg = devm_regulator_get(&client->dev, "vdd");
- if (IS_ERR(data->vdd_reg)) {
- if (PTR_ERR(data->vdd_reg) == -EPROBE_DEFER)
- return -EPROBE_DEFER;
-
- dev_err(&client->dev, "failed to get VDD regulator!\n");
- return PTR_ERR(data->vdd_reg);
- }
+ if (IS_ERR(data->vdd_reg))
+ return dev_err_probe(&client->dev, PTR_ERR(data->vdd_reg),
+ "failed to get VDD regulator!\n");

data->vddio_reg = devm_regulator_get(&client->dev, "vddio");
- if (IS_ERR(data->vddio_reg)) {
- if (PTR_ERR(data->vddio_reg) == -EPROBE_DEFER)
- return -EPROBE_DEFER;
-
- dev_err(&client->dev, "failed to get VDDIO regulator!\n");
- return PTR_ERR(data->vddio_reg);
- }
+ if (IS_ERR(data->vddio_reg))
+ return dev_err_probe(&client->dev, PTR_ERR(data->vddio_reg),
+ "failed to get VDDIO regulator!\n");

ret = regulator_enable(data->vdd_reg);
if (ret) {
--
2.7.4


2020-08-16 08:55:09

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 1/3] iio: accel: mma8452: Use dev_err_probe() to simplify error handling

On Tue, 11 Aug 2020 11:43:14 +0800
Anson Huang <[email protected]> wrote:

> dev_err_probe() can reduce code size, uniform error handling and record the
> defer probe reason etc., use it to simplify the code.
>
> Signed-off-by: Anson Huang <[email protected]>
Hi Anson,

All look good, but will have to wait for dev_err_probe to be in my
upstream tree which hasn't quite happened yet. Give me a poke if
I seem to have lost these once that is true!

Thanks,

Jonathan

> ---
> drivers/iio/accel/mma8452.c | 20 ++++++--------------
> 1 file changed, 6 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
> index ba27f86..9b5f23b 100644
> --- a/drivers/iio/accel/mma8452.c
> +++ b/drivers/iio/accel/mma8452.c
> @@ -1538,22 +1538,14 @@ static int mma8452_probe(struct i2c_client *client,
> data->chip_info = match->data;
>
> data->vdd_reg = devm_regulator_get(&client->dev, "vdd");
> - if (IS_ERR(data->vdd_reg)) {
> - if (PTR_ERR(data->vdd_reg) == -EPROBE_DEFER)
> - return -EPROBE_DEFER;
> -
> - dev_err(&client->dev, "failed to get VDD regulator!\n");
> - return PTR_ERR(data->vdd_reg);
> - }
> + if (IS_ERR(data->vdd_reg))
> + return dev_err_probe(&client->dev, PTR_ERR(data->vdd_reg),
> + "failed to get VDD regulator!\n");
>
> data->vddio_reg = devm_regulator_get(&client->dev, "vddio");
> - if (IS_ERR(data->vddio_reg)) {
> - if (PTR_ERR(data->vddio_reg) == -EPROBE_DEFER)
> - return -EPROBE_DEFER;
> -
> - dev_err(&client->dev, "failed to get VDDIO regulator!\n");
> - return PTR_ERR(data->vddio_reg);
> - }
> + if (IS_ERR(data->vddio_reg))
> + return dev_err_probe(&client->dev, PTR_ERR(data->vddio_reg),
> + "failed to get VDDIO regulator!\n");
>
> ret = regulator_enable(data->vdd_reg);
> if (ret) {

2020-08-29 18:05:05

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 1/3] iio: accel: mma8452: Use dev_err_probe() to simplify error handling

On Tue, 11 Aug 2020 11:43:14 +0800
Anson Huang <[email protected]> wrote:

> dev_err_probe() can reduce code size, uniform error handling and record the
> defer probe reason etc., use it to simplify the code.
>
> Signed-off-by: Anson Huang <[email protected]>
Sorry Anson.

You got in first, but I was working backwards through my email today and
picked up Krzysztof Kozlowski's series doing the same thing across a whole
set of drivers.

Sorry about that.

Jonathan


> ---
> drivers/iio/accel/mma8452.c | 20 ++++++--------------
> 1 file changed, 6 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
> index ba27f86..9b5f23b 100644
> --- a/drivers/iio/accel/mma8452.c
> +++ b/drivers/iio/accel/mma8452.c
> @@ -1538,22 +1538,14 @@ static int mma8452_probe(struct i2c_client *client,
> data->chip_info = match->data;
>
> data->vdd_reg = devm_regulator_get(&client->dev, "vdd");
> - if (IS_ERR(data->vdd_reg)) {
> - if (PTR_ERR(data->vdd_reg) == -EPROBE_DEFER)
> - return -EPROBE_DEFER;
> -
> - dev_err(&client->dev, "failed to get VDD regulator!\n");
> - return PTR_ERR(data->vdd_reg);
> - }
> + if (IS_ERR(data->vdd_reg))
> + return dev_err_probe(&client->dev, PTR_ERR(data->vdd_reg),
> + "failed to get VDD regulator!\n");
>
> data->vddio_reg = devm_regulator_get(&client->dev, "vddio");
> - if (IS_ERR(data->vddio_reg)) {
> - if (PTR_ERR(data->vddio_reg) == -EPROBE_DEFER)
> - return -EPROBE_DEFER;
> -
> - dev_err(&client->dev, "failed to get VDDIO regulator!\n");
> - return PTR_ERR(data->vddio_reg);
> - }
> + if (IS_ERR(data->vddio_reg))
> + return dev_err_probe(&client->dev, PTR_ERR(data->vddio_reg),
> + "failed to get VDDIO regulator!\n");
>
> ret = regulator_enable(data->vdd_reg);
> if (ret) {