2020-11-10 08:06:34

by Amelie Delaunay

[permalink] [raw]
Subject: [PATCH 1/1] mfd: stmfx: fix dev_err_probe call in stmfx_chip_init

ret may be 0 so, dev_err_probe should be called only when ret is an error
code.

Fixes: 41c9c06c491a ("mfd: stmfx: Simplify with dev_err_probe()")
Signed-off-by: Amelie Delaunay <[email protected]>
---
drivers/mfd/stmfx.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/stmfx.c b/drivers/mfd/stmfx.c
index 5e680bfdf5c9..360fb4646688 100644
--- a/drivers/mfd/stmfx.c
+++ b/drivers/mfd/stmfx.c
@@ -329,12 +329,11 @@ static int stmfx_chip_init(struct i2c_client *client)

stmfx->vdd = devm_regulator_get_optional(&client->dev, "vdd");
ret = PTR_ERR_OR_ZERO(stmfx->vdd);
- if (ret == -ENODEV) {
+ if (ret == -ENODEV)
stmfx->vdd = NULL;
- } else {
+ else if (ret)
return dev_err_probe(&client->dev, ret,
"Failed to get VDD regulator\n");
- }

if (stmfx->vdd) {
ret = regulator_enable(stmfx->vdd);
--
2.17.1


2020-11-13 10:11:49

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH 1/1] mfd: stmfx: fix dev_err_probe call in stmfx_chip_init

On Tue, 10 Nov 2020, Amelie Delaunay wrote:

> ret may be 0 so, dev_err_probe should be called only when ret is an error
> code.
>
> Fixes: 41c9c06c491a ("mfd: stmfx: Simplify with dev_err_probe()")
> Signed-off-by: Amelie Delaunay <[email protected]>
> ---
> drivers/mfd/stmfx.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mfd/stmfx.c b/drivers/mfd/stmfx.c
> index 5e680bfdf5c9..360fb4646688 100644
> --- a/drivers/mfd/stmfx.c
> +++ b/drivers/mfd/stmfx.c
> @@ -329,12 +329,11 @@ static int stmfx_chip_init(struct i2c_client *client)
>
> stmfx->vdd = devm_regulator_get_optional(&client->dev, "vdd");
> ret = PTR_ERR_OR_ZERO(stmfx->vdd);
> - if (ret == -ENODEV) {
> + if (ret == -ENODEV)
> stmfx->vdd = NULL;
> - } else {
> + else if (ret)
> return dev_err_probe(&client->dev, ret,
> "Failed to get VDD regulator\n");
> - }

Probably nicer to keep all of the error handing in one area, like:

if (ret) {
if (ret == -ENODEV)
stmfx->vdd = NULL;
else
return dev_err_probe(&client->dev, ret,
"Failed to get VDD regulator\n");
}

I'll let you make the call though.

--
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

2020-11-13 12:32:01

by Amelie Delaunay

[permalink] [raw]
Subject: Re: [PATCH 1/1] mfd: stmfx: fix dev_err_probe call in stmfx_chip_init

On 11/13/20 11:09 AM, Lee Jones wrote:
> On Tue, 10 Nov 2020, Amelie Delaunay wrote:
>
>> ret may be 0 so, dev_err_probe should be called only when ret is an error
>> code.
>>
>> Fixes: 41c9c06c491a ("mfd: stmfx: Simplify with dev_err_probe()")
>> Signed-off-by: Amelie Delaunay <[email protected]>
>> ---
>> drivers/mfd/stmfx.c | 5 ++---
>> 1 file changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/mfd/stmfx.c b/drivers/mfd/stmfx.c
>> index 5e680bfdf5c9..360fb4646688 100644
>> --- a/drivers/mfd/stmfx.c
>> +++ b/drivers/mfd/stmfx.c
>> @@ -329,12 +329,11 @@ static int stmfx_chip_init(struct i2c_client *client)
>>
>> stmfx->vdd = devm_regulator_get_optional(&client->dev, "vdd");
>> ret = PTR_ERR_OR_ZERO(stmfx->vdd);
>> - if (ret == -ENODEV) {
>> + if (ret == -ENODEV)
>> stmfx->vdd = NULL;
>> - } else {
>> + else if (ret)
>> return dev_err_probe(&client->dev, ret,
>> "Failed to get VDD regulator\n");
>> - }
>
> Probably nicer to keep all of the error handing in one area, like:
>
> if (ret) {
> if (ret == -ENODEV)
> stmfx->vdd = NULL;
> else
> return dev_err_probe(&client->dev, ret,
> "Failed to get VDD regulator\n");
> }
>
> I'll let you make the call though.
>

Thanks for the review. I agree. Fixed in v2.

Regards,
Amelie