2019-10-31 14:16:00

by zhong jiang

[permalink] [raw]
Subject: [PATCH] ASoC: sun4i: Use PTR_ERR_OR_ZERO to simplify the code

It is better to use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR.

Signed-off-by: zhong jiang <[email protected]>
---
sound/soc/sunxi/sun4i-i2s.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c
index d0a8d58..72012a6 100644
--- a/sound/soc/sunxi/sun4i-i2s.c
+++ b/sound/soc/sunxi/sun4i-i2s.c
@@ -1174,10 +1174,8 @@ static int sun4i_i2s_init_regmap_fields(struct device *dev,
i2s->field_fmt_sr =
devm_regmap_field_alloc(dev, i2s->regmap,
i2s->variant->field_fmt_sr);
- if (IS_ERR(i2s->field_fmt_sr))
- return PTR_ERR(i2s->field_fmt_sr);

- return 0;
+ return PTR_ERR_OR_ZERO(i2s->field_fmt_sr);
}

static int sun4i_i2s_probe(struct platform_device *pdev)
--
1.7.12.4


2019-11-01 09:53:47

by Maxime Ripard

[permalink] [raw]
Subject: Re: [PATCH] ASoC: sun4i: Use PTR_ERR_OR_ZERO to simplify the code

On Thu, Oct 31, 2019 at 10:09:39PM +0800, zhong jiang wrote:
> It is better to use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR.
>
> Signed-off-by: zhong jiang <[email protected]>
> ---
> sound/soc/sunxi/sun4i-i2s.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c
> index d0a8d58..72012a6 100644
> --- a/sound/soc/sunxi/sun4i-i2s.c
> +++ b/sound/soc/sunxi/sun4i-i2s.c
> @@ -1174,10 +1174,8 @@ static int sun4i_i2s_init_regmap_fields(struct device *dev,
> i2s->field_fmt_sr =
> devm_regmap_field_alloc(dev, i2s->regmap,
> i2s->variant->field_fmt_sr);
> - if (IS_ERR(i2s->field_fmt_sr))
> - return PTR_ERR(i2s->field_fmt_sr);
>
> - return 0;
> + return PTR_ERR_OR_ZERO(i2s->field_fmt_sr);

I don't find it "better". This couples the error handling and the
success case, and it makes it harder to extend in the future.

Maxime


Attachments:
(No filename) (964.00 B)
signature.asc (235.00 B)
Download all attachments

2019-11-01 11:57:33

by zhong jiang

[permalink] [raw]
Subject: Re: [PATCH] ASoC: sun4i: Use PTR_ERR_OR_ZERO to simplify the code

On 2019/11/1 17:13, Maxime Ripard wrote:
> On Thu, Oct 31, 2019 at 10:09:39PM +0800, zhong jiang wrote:
>> It is better to use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR.
>>
>> Signed-off-by: zhong jiang <[email protected]>
>> ---
>> sound/soc/sunxi/sun4i-i2s.c | 4 +---
>> 1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c
>> index d0a8d58..72012a6 100644
>> --- a/sound/soc/sunxi/sun4i-i2s.c
>> +++ b/sound/soc/sunxi/sun4i-i2s.c
>> @@ -1174,10 +1174,8 @@ static int sun4i_i2s_init_regmap_fields(struct device *dev,
>> i2s->field_fmt_sr =
>> devm_regmap_field_alloc(dev, i2s->regmap,
>> i2s->variant->field_fmt_sr);
>> - if (IS_ERR(i2s->field_fmt_sr))
>> - return PTR_ERR(i2s->field_fmt_sr);
>>
>> - return 0;
>> + return PTR_ERR_OR_ZERO(i2s->field_fmt_sr);
> I don't find it "better". This couples the error handling and the
> success case, and it makes it harder to extend in the future.
PTR_ERR_OR_ZERO has implemented the if(IS_ERR(...)) + PTR_ERR. It is
feasible to replace it and more readable at least now.

As you said, PTR_ERR_OR_ZERO should be removed ? :-(

Thanks,
zhong jiang


> Maxime


2019-11-01 16:03:05

by Maxime Ripard

[permalink] [raw]
Subject: Re: [PATCH] ASoC: sun4i: Use PTR_ERR_OR_ZERO to simplify the code

On Fri, Nov 01, 2019 at 07:55:42PM +0800, zhong jiang wrote:
> On 2019/11/1 17:13, Maxime Ripard wrote:
> > On Thu, Oct 31, 2019 at 10:09:39PM +0800, zhong jiang wrote:
> >> It is better to use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR.
> >>
> >> Signed-off-by: zhong jiang <[email protected]>
> >> ---
> >> sound/soc/sunxi/sun4i-i2s.c | 4 +---
> >> 1 file changed, 1 insertion(+), 3 deletions(-)
> >>
> >> diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c
> >> index d0a8d58..72012a6 100644
> >> --- a/sound/soc/sunxi/sun4i-i2s.c
> >> +++ b/sound/soc/sunxi/sun4i-i2s.c
> >> @@ -1174,10 +1174,8 @@ static int sun4i_i2s_init_regmap_fields(struct device *dev,
> >> i2s->field_fmt_sr =
> >> devm_regmap_field_alloc(dev, i2s->regmap,
> >> i2s->variant->field_fmt_sr);
> >> - if (IS_ERR(i2s->field_fmt_sr))
> >> - return PTR_ERR(i2s->field_fmt_sr);
> >>
> >> - return 0;
> >> + return PTR_ERR_OR_ZERO(i2s->field_fmt_sr);
> > I don't find it "better". This couples the error handling and the
> > success case, and it makes it harder to extend in the future.
>
> PTR_ERR_OR_ZERO has implemented the if(IS_ERR(...)) + PTR_ERR. It is
> feasible to replace it and more readable at least now.
>
> As you said, PTR_ERR_OR_ZERO should be removed ? :-(

No, I'm saying that in this context, this change isn't necessary.

Maxime


Attachments:
(No filename) (1.37 kB)
signature.asc (235.00 B)
Download all attachments

2019-11-02 14:47:02

by zhong jiang

[permalink] [raw]
Subject: Re: [PATCH] ASoC: sun4i: Use PTR_ERR_OR_ZERO to simplify the code

On 2019/11/1 22:53, Maxime Ripard wrote:
> On Fri, Nov 01, 2019 at 07:55:42PM +0800, zhong jiang wrote:
>> On 2019/11/1 17:13, Maxime Ripard wrote:
>>> On Thu, Oct 31, 2019 at 10:09:39PM +0800, zhong jiang wrote:
>>>> It is better to use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR.
>>>>
>>>> Signed-off-by: zhong jiang <[email protected]>
>>>> ---
>>>> sound/soc/sunxi/sun4i-i2s.c | 4 +---
>>>> 1 file changed, 1 insertion(+), 3 deletions(-)
>>>>
>>>> diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c
>>>> index d0a8d58..72012a6 100644
>>>> --- a/sound/soc/sunxi/sun4i-i2s.c
>>>> +++ b/sound/soc/sunxi/sun4i-i2s.c
>>>> @@ -1174,10 +1174,8 @@ static int sun4i_i2s_init_regmap_fields(struct device *dev,
>>>> i2s->field_fmt_sr =
>>>> devm_regmap_field_alloc(dev, i2s->regmap,
>>>> i2s->variant->field_fmt_sr);
>>>> - if (IS_ERR(i2s->field_fmt_sr))
>>>> - return PTR_ERR(i2s->field_fmt_sr);
>>>>
>>>> - return 0;
>>>> + return PTR_ERR_OR_ZERO(i2s->field_fmt_sr);
>>> I don't find it "better". This couples the error handling and the
>>> success case, and it makes it harder to extend in the future.
>> PTR_ERR_OR_ZERO has implemented the if(IS_ERR(...)) + PTR_ERR. It is
>> feasible to replace it and more readable at least now.
>>
>> As you said, PTR_ERR_OR_ZERO should be removed ? :-(
> No, I'm saying that in this context, this change isn't necessary.
I am not an expert in the field. It depends on you.
> Maxime