2018-08-13 13:02:58

by zhong jiang

[permalink] [raw]
Subject: [PATCH 0/2] rtc: Use PTR_ERR_OR_ZERO to replace the open code

The issue is detected with the help of Coccinelle.

zhong jiang (2):
rtc:rtc-digicolor: Use PTR_ERR_OR_ZERO to replace the open code
rtc:rtc-ds1347: Use PTR_ERR_OR_ZERO to replace the open code

drivers/rtc/rtc-digicolor.c | 4 +---
drivers/rtc/rtc-ds1347.c | 5 +----
2 files changed, 2 insertions(+), 7 deletions(-)

--
1.7.12.4



2018-08-13 13:02:55

by zhong jiang

[permalink] [raw]
Subject: [PATCH 1/2] rtc:rtc-digicolor: Use PTR_ERR_OR_ZERO to replace the open code

PTR_ERR_OR_ZERO has implemented the if(IS_ERR(...)) + PTR_ERR, So
just replace them rather than duplicating its implement.

Signed-off-by: zhong jiang <[email protected]>
---
drivers/rtc/rtc-digicolor.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/rtc/rtc-digicolor.c b/drivers/rtc/rtc-digicolor.c
index b253bf1..fd6850c 100644
--- a/drivers/rtc/rtc-digicolor.c
+++ b/drivers/rtc/rtc-digicolor.c
@@ -202,10 +202,8 @@ static int __init dc_rtc_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, rtc);
rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name,
&dc_rtc_ops, THIS_MODULE);
- if (IS_ERR(rtc->rtc_dev))
- return PTR_ERR(rtc->rtc_dev);

- return 0;
+ return PTR_ERR_OR_ZERO(rtc->rtc_dev);
}

static const struct of_device_id dc_dt_ids[] = {
--
1.7.12.4


2018-08-13 13:03:17

by zhong jiang

[permalink] [raw]
Subject: [PATCH 2/2] rtc:rtc-ds1347: Use PTR_ERR_OR_ZERO to replace the open code

PTR_ERR_OR_ZERO has implemented the if(IS_ERR(...)) + PTR_ERR, So
just replace them rather than duplicating its implement.

Signed-off-by: zhong jiang <[email protected]>
---
drivers/rtc/rtc-ds1347.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/rtc/rtc-ds1347.c b/drivers/rtc/rtc-ds1347.c
index 938512c..b97b67f 100644
--- a/drivers/rtc/rtc-ds1347.c
+++ b/drivers/rtc/rtc-ds1347.c
@@ -155,10 +155,7 @@ static int ds1347_probe(struct spi_device *spi)
rtc = devm_rtc_device_register(&spi->dev, "ds1347",
&ds1347_rtc_ops, THIS_MODULE);

- if (IS_ERR(rtc))
- return PTR_ERR(rtc);
-
- return 0;
+ return PTR_ERR_OR_ZERO(rtc);
}

static struct spi_driver ds1347_driver = {
--
1.7.12.4


2018-08-14 04:19:11

by Baruch Siach

[permalink] [raw]
Subject: Re: [PATCH 1/2] rtc:rtc-digicolor: Use PTR_ERR_OR_ZERO to replace the open code

Hi zhong,

On Mon, Aug 13, 2018 at 07:31:24PM +0800, zhong jiang wrote:
> PTR_ERR_OR_ZERO has implemented the if(IS_ERR(...)) + PTR_ERR, So
> just replace them rather than duplicating its implement.
>
> Signed-off-by: zhong jiang <[email protected]>

Acked-by: Baruch Siach <[email protected]>

Thanks,
baruch

> ---
> drivers/rtc/rtc-digicolor.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/rtc/rtc-digicolor.c b/drivers/rtc/rtc-digicolor.c
> index b253bf1..fd6850c 100644
> --- a/drivers/rtc/rtc-digicolor.c
> +++ b/drivers/rtc/rtc-digicolor.c
> @@ -202,10 +202,8 @@ static int __init dc_rtc_probe(struct platform_device *pdev)
> platform_set_drvdata(pdev, rtc);
> rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name,
> &dc_rtc_ops, THIS_MODULE);
> - if (IS_ERR(rtc->rtc_dev))
> - return PTR_ERR(rtc->rtc_dev);
>
> - return 0;
> + return PTR_ERR_OR_ZERO(rtc->rtc_dev);
> }
>
> static const struct of_device_id dc_dt_ids[] = {

--
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- [email protected] - tel: +972.2.679.5364, http://www.tkos.co.il -

2018-08-14 04:20:15

by Baruch Siach

[permalink] [raw]
Subject: Re: [PATCH 2/2] rtc:rtc-ds1347: Use PTR_ERR_OR_ZERO to replace the open code

Hi zhong,

On Mon, Aug 13, 2018 at 07:31:25PM +0800, zhong jiang wrote:
> PTR_ERR_OR_ZERO has implemented the if(IS_ERR(...)) + PTR_ERR, So
> just replace them rather than duplicating its implement.
>
> Signed-off-by: zhong jiang <[email protected]>

Acked-by: Baruch Siach <[email protected]>

Thanks,
baruch

> ---
> drivers/rtc/rtc-ds1347.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/rtc/rtc-ds1347.c b/drivers/rtc/rtc-ds1347.c
> index 938512c..b97b67f 100644
> --- a/drivers/rtc/rtc-ds1347.c
> +++ b/drivers/rtc/rtc-ds1347.c
> @@ -155,10 +155,7 @@ static int ds1347_probe(struct spi_device *spi)
> rtc = devm_rtc_device_register(&spi->dev, "ds1347",
> &ds1347_rtc_ops, THIS_MODULE);
>
> - if (IS_ERR(rtc))
> - return PTR_ERR(rtc);
> -
> - return 0;
> + return PTR_ERR_OR_ZERO(rtc);
> }
>
> static struct spi_driver ds1347_driver = {

--
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- [email protected] - tel: +972.2.679.5364, http://www.tkos.co.il -

2018-08-14 16:17:35

by Alexandre Belloni

[permalink] [raw]
Subject: Re: [PATCH 1/2] rtc:rtc-digicolor: Use PTR_ERR_OR_ZERO to replace the open code

Hi,

On 13/08/2018 19:31:24+0800, zhong jiang wrote:
> PTR_ERR_OR_ZERO has implemented the if(IS_ERR(...)) + PTR_ERR, So
> just replace them rather than duplicating its implement.
>
> Signed-off-by: zhong jiang <[email protected]>
> ---
> drivers/rtc/rtc-digicolor.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/rtc/rtc-digicolor.c b/drivers/rtc/rtc-digicolor.c
> index b253bf1..fd6850c 100644
> --- a/drivers/rtc/rtc-digicolor.c
> +++ b/drivers/rtc/rtc-digicolor.c
> @@ -202,10 +202,8 @@ static int __init dc_rtc_probe(struct platform_device *pdev)
> platform_set_drvdata(pdev, rtc);
> rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name,
> &dc_rtc_ops, THIS_MODULE);
> - if (IS_ERR(rtc->rtc_dev))
> - return PTR_ERR(rtc->rtc_dev);
>
> - return 0;
> + return PTR_ERR_OR_ZERO(rtc->rtc_dev);

As many other maintainers, I don't find that kind of change useful and
I'm not taking them unless there are other improvements in the driver.


--
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

2018-08-15 07:19:33

by zhong jiang

[permalink] [raw]
Subject: Re: [PATCH 1/2] rtc:rtc-digicolor: Use PTR_ERR_OR_ZERO to replace the open code

On 2018/8/15 0:15, Alexandre Belloni wrote:
> Hi,
>
> On 13/08/2018 19:31:24+0800, zhong jiang wrote:
>> PTR_ERR_OR_ZERO has implemented the if(IS_ERR(...)) + PTR_ERR, So
>> just replace them rather than duplicating its implement.
>>
>> Signed-off-by: zhong jiang <[email protected]>
>> ---
>> drivers/rtc/rtc-digicolor.c | 4 +---
>> 1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/drivers/rtc/rtc-digicolor.c b/drivers/rtc/rtc-digicolor.c
>> index b253bf1..fd6850c 100644
>> --- a/drivers/rtc/rtc-digicolor.c
>> +++ b/drivers/rtc/rtc-digicolor.c
>> @@ -202,10 +202,8 @@ static int __init dc_rtc_probe(struct platform_device *pdev)
>> platform_set_drvdata(pdev, rtc);
>> rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name,
>> &dc_rtc_ops, THIS_MODULE);
>> - if (IS_ERR(rtc->rtc_dev))
>> - return PTR_ERR(rtc->rtc_dev);
>>
>> - return 0;
>> + return PTR_ERR_OR_ZERO(rtc->rtc_dev);
> As many other maintainers, I don't find that kind of change useful and
> I'm not taking them unless there are other improvements in the driver.
>
>
Hi, Alexandre

The issue is detected with the help of Coccinelle. It simplify the code with specific
function rather than duplicating its implementation.

The patch clean up the code. of course, it is not a bug. if you do not care about it.
I am ok with that.

Thanks,
zhong jiang


2018-08-15 08:22:39

by Alexandre Belloni

[permalink] [raw]
Subject: Re: [PATCH 1/2] rtc:rtc-digicolor: Use PTR_ERR_OR_ZERO to replace the open code

On 15/08/2018 15:16:56+0800, zhong jiang wrote:
> On 2018/8/15 0:15, Alexandre Belloni wrote:
> > Hi,
> >
> > On 13/08/2018 19:31:24+0800, zhong jiang wrote:
> >> PTR_ERR_OR_ZERO has implemented the if(IS_ERR(...)) + PTR_ERR, So
> >> just replace them rather than duplicating its implement.
> >>
> >> Signed-off-by: zhong jiang <[email protected]>
> >> ---
> >> drivers/rtc/rtc-digicolor.c | 4 +---
> >> 1 file changed, 1 insertion(+), 3 deletions(-)
> >>
> >> diff --git a/drivers/rtc/rtc-digicolor.c b/drivers/rtc/rtc-digicolor.c
> >> index b253bf1..fd6850c 100644
> >> --- a/drivers/rtc/rtc-digicolor.c
> >> +++ b/drivers/rtc/rtc-digicolor.c
> >> @@ -202,10 +202,8 @@ static int __init dc_rtc_probe(struct platform_device *pdev)
> >> platform_set_drvdata(pdev, rtc);
> >> rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name,
> >> &dc_rtc_ops, THIS_MODULE);
> >> - if (IS_ERR(rtc->rtc_dev))
> >> - return PTR_ERR(rtc->rtc_dev);
> >>
> >> - return 0;
> >> + return PTR_ERR_OR_ZERO(rtc->rtc_dev);
> > As many other maintainers, I don't find that kind of change useful and
> > I'm not taking them unless there are other improvements in the driver.
> >
> >
> Hi, Alexandre
>
> The issue is detected with the help of Coccinelle. It simplify the code with specific
> function rather than duplicating its implementation.
>
> The patch clean up the code. of course, it is not a bug. if you do not care about it.
> I am ok with that.
>

But this does not simplify or make the code clearer and as soon as you
need to add code between the devm_rtc_device_register call and the end
of the function, the patch will need to be undone.

--
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com