* [PATCH -next] I2C: Use helper function IS_ERR_OR_NULL()
@ 2023-08-16 9:46 Ruan Jinjie
2023-08-16 9:48 ` Ruan Jinjie
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Ruan Jinjie @ 2023-08-16 9:46 UTC (permalink / raw)
To: linux-i2c, linux-arm-kernel, Codrin Ciubotariu, Andi Shyti,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Oleksij Rempel,
Pengutronix Kernel Team, Shawn Guo, Sascha Hauer, Fabio Estevam,
NXP Linux Team
Cc: ruanjinjie
Use IS_ERR_OR_NULL() instead of open-coding it
to simplify the code.
Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
---
drivers/i2c/busses/i2c-at91-master.c | 2 +-
drivers/i2c/busses/i2c-imx.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/busses/i2c-at91-master.c b/drivers/i2c/busses/i2c-at91-master.c
index 94cff1cd527e..0e454c04a145 100644
--- a/drivers/i2c/busses/i2c-at91-master.c
+++ b/drivers/i2c/busses/i2c-at91-master.c
@@ -831,7 +831,7 @@ static int at91_init_twi_recovery_gpio(struct platform_device *pdev,
struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
rinfo->pinctrl = devm_pinctrl_get(&pdev->dev);
- if (!rinfo->pinctrl || IS_ERR(rinfo->pinctrl)) {
+ if (IS_ERR_OR_NULL(rinfo->pinctrl)) {
dev_info(dev->dev, "can't get pinctrl, bus recovery not supported\n");
return PTR_ERR(rinfo->pinctrl);
}
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 10e89586ca72..8807c90df749 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -1388,7 +1388,7 @@ static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx,
struct i2c_bus_recovery_info *rinfo = &i2c_imx->rinfo;
i2c_imx->pinctrl = devm_pinctrl_get(&pdev->dev);
- if (!i2c_imx->pinctrl || IS_ERR(i2c_imx->pinctrl)) {
+ if (!IS_ERR_OR_NULL(i2c_imx->pinctrl)) {
dev_info(&pdev->dev, "can't get pinctrl, bus recovery not supported\n");
return PTR_ERR(i2c_imx->pinctrl);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH -next] I2C: Use helper function IS_ERR_OR_NULL()
2023-08-16 9:46 [PATCH -next] I2C: Use helper function IS_ERR_OR_NULL() Ruan Jinjie
@ 2023-08-16 9:48 ` Ruan Jinjie
2023-08-16 10:08 ` Russell King (Oracle)
2023-08-16 9:51 ` Yann Sionneau
2023-08-16 10:22 ` Russell King (Oracle)
2 siblings, 1 reply; 8+ messages in thread
From: Ruan Jinjie @ 2023-08-16 9:48 UTC (permalink / raw)
To: linux-i2c, linux-arm-kernel, Codrin Ciubotariu, Andi Shyti,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Oleksij Rempel,
Pengutronix Kernel Team, Shawn Guo, Sascha Hauer, Fabio Estevam,
NXP Linux Team
On 2023/8/16 17:46, Ruan Jinjie wrote:
> Use IS_ERR_OR_NULL() instead of open-coding it
> to simplify the code.
>
> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
> ---
> drivers/i2c/busses/i2c-at91-master.c | 2 +-
> drivers/i2c/busses/i2c-imx.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-at91-master.c b/drivers/i2c/busses/i2c-at91-master.c
> index 94cff1cd527e..0e454c04a145 100644
> --- a/drivers/i2c/busses/i2c-at91-master.c
> +++ b/drivers/i2c/busses/i2c-at91-master.c
> @@ -831,7 +831,7 @@ static int at91_init_twi_recovery_gpio(struct platform_device *pdev,
> struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
>
> rinfo->pinctrl = devm_pinctrl_get(&pdev->dev);
> - if (!rinfo->pinctrl || IS_ERR(rinfo->pinctrl)) {
> + if (IS_ERR_OR_NULL(rinfo->pinctrl)) {
> dev_info(dev->dev, "can't get pinctrl, bus recovery not supported\n");
> return PTR_ERR(rinfo->pinctrl);
> }
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index 10e89586ca72..8807c90df749 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -1388,7 +1388,7 @@ static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx,
> struct i2c_bus_recovery_info *rinfo = &i2c_imx->rinfo;
>
> i2c_imx->pinctrl = devm_pinctrl_get(&pdev->dev);
> - if (!i2c_imx->pinctrl || IS_ERR(i2c_imx->pinctrl)) {
> + if (!IS_ERR_OR_NULL(i2c_imx->pinctrl)) {
Sorry, there is a problem, please ignore it.
> dev_info(&pdev->dev, "can't get pinctrl, bus recovery not supported\n");
> return PTR_ERR(i2c_imx->pinctrl);
> }
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH -next] I2C: Use helper function IS_ERR_OR_NULL()
2023-08-16 9:46 [PATCH -next] I2C: Use helper function IS_ERR_OR_NULL() Ruan Jinjie
2023-08-16 9:48 ` Ruan Jinjie
@ 2023-08-16 9:51 ` Yann Sionneau
2023-08-16 10:22 ` Russell King (Oracle)
2023-08-16 10:22 ` Russell King (Oracle)
2 siblings, 1 reply; 8+ messages in thread
From: Yann Sionneau @ 2023-08-16 9:51 UTC (permalink / raw)
To: Ruan Jinjie, linux-i2c, linux-arm-kernel, Codrin Ciubotariu,
Andi Shyti, Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Oleksij Rempel, Pengutronix Kernel Team, Shawn Guo, Sascha Hauer,
Fabio Estevam, NXP Linux Team
Le 16/08/2023 à 11:46, Ruan Jinjie a écrit :
> Use IS_ERR_OR_NULL() instead of open-coding it
> to simplify the code.
>
> rinfo->pinctrl = devm_pinctrl_get(&pdev->dev);
> - if (!rinfo->pinctrl || IS_ERR(rinfo->pinctrl)) {
> + if (IS_ERR_OR_NULL(rinfo->pinctrl)) {
Can the return of devm_pinctrl_get really be NULL?
Regards,
--
Yann
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH -next] I2C: Use helper function IS_ERR_OR_NULL()
2023-08-16 9:48 ` Ruan Jinjie
@ 2023-08-16 10:08 ` Russell King (Oracle)
2023-08-17 1:38 ` Ruan Jinjie
0 siblings, 1 reply; 8+ messages in thread
From: Russell King (Oracle) @ 2023-08-16 10:08 UTC (permalink / raw)
To: Ruan Jinjie
Cc: linux-i2c, linux-arm-kernel, Codrin Ciubotariu, Andi Shyti,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Oleksij Rempel,
Pengutronix Kernel Team, Shawn Guo, Sascha Hauer, Fabio Estevam,
NXP Linux Team
On Wed, Aug 16, 2023 at 05:48:34PM +0800, Ruan Jinjie wrote:
>
>
> On 2023/8/16 17:46, Ruan Jinjie wrote:
> > Use IS_ERR_OR_NULL() instead of open-coding it
> > to simplify the code.
> >
> > Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
> > ---
> > drivers/i2c/busses/i2c-at91-master.c | 2 +-
> > drivers/i2c/busses/i2c-imx.c | 2 +-
> > 2 files changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/i2c/busses/i2c-at91-master.c b/drivers/i2c/busses/i2c-at91-master.c
> > index 94cff1cd527e..0e454c04a145 100644
> > --- a/drivers/i2c/busses/i2c-at91-master.c
> > +++ b/drivers/i2c/busses/i2c-at91-master.c
> > @@ -831,7 +831,7 @@ static int at91_init_twi_recovery_gpio(struct platform_device *pdev,
> > struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
> >
> > rinfo->pinctrl = devm_pinctrl_get(&pdev->dev);
> > - if (!rinfo->pinctrl || IS_ERR(rinfo->pinctrl)) {
> > + if (IS_ERR_OR_NULL(rinfo->pinctrl)) {
> > dev_info(dev->dev, "can't get pinctrl, bus recovery not supported\n");
> > return PTR_ERR(rinfo->pinctrl);
> > }
> > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> > index 10e89586ca72..8807c90df749 100644
> > --- a/drivers/i2c/busses/i2c-imx.c
> > +++ b/drivers/i2c/busses/i2c-imx.c
> > @@ -1388,7 +1388,7 @@ static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx,
> > struct i2c_bus_recovery_info *rinfo = &i2c_imx->rinfo;
> >
> > i2c_imx->pinctrl = devm_pinctrl_get(&pdev->dev);
> > - if (!i2c_imx->pinctrl || IS_ERR(i2c_imx->pinctrl)) {
> > + if (!IS_ERR_OR_NULL(i2c_imx->pinctrl)) {
>
> Sorry, there is a problem, please ignore it.
I don't think these conversions are appropriate for devm_pinctrl_get().
If one reads the code for devm_pinctrl_get() and pinctrl_get(), then
one finds that it will never return NULL.
So the tests for NULL do not serve any practical purpose than giving
coders a warm fuzzy feeling that they've tested for a NULL pointer.
Practically, they are of no use, so should be removed... thus making
the conversion to IS_ERR_OR_NULL() irrelevant.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH -next] I2C: Use helper function IS_ERR_OR_NULL()
2023-08-16 9:46 [PATCH -next] I2C: Use helper function IS_ERR_OR_NULL() Ruan Jinjie
2023-08-16 9:48 ` Ruan Jinjie
2023-08-16 9:51 ` Yann Sionneau
@ 2023-08-16 10:22 ` Russell King (Oracle)
2023-08-17 1:39 ` Ruan Jinjie
2 siblings, 1 reply; 8+ messages in thread
From: Russell King (Oracle) @ 2023-08-16 10:22 UTC (permalink / raw)
To: Ruan Jinjie
Cc: linux-i2c, linux-arm-kernel, Codrin Ciubotariu, Andi Shyti,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Oleksij Rempel,
Pengutronix Kernel Team, Shawn Guo, Sascha Hauer, Fabio Estevam,
NXP Linux Team
On Wed, Aug 16, 2023 at 05:46:18PM +0800, Ruan Jinjie wrote:
> Use IS_ERR_OR_NULL() instead of open-coding it
> to simplify the code.
>
> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
> ---
> drivers/i2c/busses/i2c-at91-master.c | 2 +-
> drivers/i2c/busses/i2c-imx.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-at91-master.c b/drivers/i2c/busses/i2c-at91-master.c
> index 94cff1cd527e..0e454c04a145 100644
> --- a/drivers/i2c/busses/i2c-at91-master.c
> +++ b/drivers/i2c/busses/i2c-at91-master.c
> @@ -831,7 +831,7 @@ static int at91_init_twi_recovery_gpio(struct platform_device *pdev,
> struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
>
> rinfo->pinctrl = devm_pinctrl_get(&pdev->dev);
> - if (!rinfo->pinctrl || IS_ERR(rinfo->pinctrl)) {
> + if (IS_ERR_OR_NULL(rinfo->pinctrl)) {
> dev_info(dev->dev, "can't get pinctrl, bus recovery not supported\n");
> return PTR_ERR(rinfo->pinctrl);
> }
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index 10e89586ca72..8807c90df749 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -1388,7 +1388,7 @@ static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx,
> struct i2c_bus_recovery_info *rinfo = &i2c_imx->rinfo;
>
> i2c_imx->pinctrl = devm_pinctrl_get(&pdev->dev);
> - if (!i2c_imx->pinctrl || IS_ERR(i2c_imx->pinctrl)) {
> + if (!IS_ERR_OR_NULL(i2c_imx->pinctrl)) {
> dev_info(&pdev->dev, "can't get pinctrl, bus recovery not supported\n");
> return PTR_ERR(i2c_imx->pinctrl);
> }
As stated in my previous reply to a similar patch, devm_pinctrl_get()
can not return NULL, so it makes more sense to remove the test for NULL
rather than "cleaning up" the buggy code, but leaving the bugs behind.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH -next] I2C: Use helper function IS_ERR_OR_NULL()
2023-08-16 9:51 ` Yann Sionneau
@ 2023-08-16 10:22 ` Russell King (Oracle)
0 siblings, 0 replies; 8+ messages in thread
From: Russell King (Oracle) @ 2023-08-16 10:22 UTC (permalink / raw)
To: Yann Sionneau
Cc: Ruan Jinjie, linux-i2c, linux-arm-kernel, Codrin Ciubotariu,
Andi Shyti, Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Oleksij Rempel, Pengutronix Kernel Team, Shawn Guo, Sascha Hauer,
Fabio Estevam, NXP Linux Team
On Wed, Aug 16, 2023 at 11:51:54AM +0200, Yann Sionneau wrote:
> Le 16/08/2023 à 11:46, Ruan Jinjie a écrit :
>
> > Use IS_ERR_OR_NULL() instead of open-coding it
> > to simplify the code.
> > rinfo->pinctrl = devm_pinctrl_get(&pdev->dev);
> > - if (!rinfo->pinctrl || IS_ERR(rinfo->pinctrl)) {
> > + if (IS_ERR_OR_NULL(rinfo->pinctrl)) {
>
> Can the return of devm_pinctrl_get really be NULL?
No.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH -next] I2C: Use helper function IS_ERR_OR_NULL()
2023-08-16 10:08 ` Russell King (Oracle)
@ 2023-08-17 1:38 ` Ruan Jinjie
0 siblings, 0 replies; 8+ messages in thread
From: Ruan Jinjie @ 2023-08-17 1:38 UTC (permalink / raw)
To: Russell King (Oracle)
Cc: linux-i2c, linux-arm-kernel, Codrin Ciubotariu, Andi Shyti,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Oleksij Rempel,
Pengutronix Kernel Team, Shawn Guo, Sascha Hauer, Fabio Estevam,
NXP Linux Team
On 2023/8/16 18:08, Russell King (Oracle) wrote:
> On Wed, Aug 16, 2023 at 05:48:34PM +0800, Ruan Jinjie wrote:
>>
>>
>> On 2023/8/16 17:46, Ruan Jinjie wrote:
>>> Use IS_ERR_OR_NULL() instead of open-coding it
>>> to simplify the code.
>>>
>>> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
>>> ---
>>> drivers/i2c/busses/i2c-at91-master.c | 2 +-
>>> drivers/i2c/busses/i2c-imx.c | 2 +-
>>> 2 files changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/i2c/busses/i2c-at91-master.c b/drivers/i2c/busses/i2c-at91-master.c
>>> index 94cff1cd527e..0e454c04a145 100644
>>> --- a/drivers/i2c/busses/i2c-at91-master.c
>>> +++ b/drivers/i2c/busses/i2c-at91-master.c
>>> @@ -831,7 +831,7 @@ static int at91_init_twi_recovery_gpio(struct platform_device *pdev,
>>> struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
>>>
>>> rinfo->pinctrl = devm_pinctrl_get(&pdev->dev);
>>> - if (!rinfo->pinctrl || IS_ERR(rinfo->pinctrl)) {
>>> + if (IS_ERR_OR_NULL(rinfo->pinctrl)) {
>>> dev_info(dev->dev, "can't get pinctrl, bus recovery not supported\n");
>>> return PTR_ERR(rinfo->pinctrl);
>>> }
>>> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
>>> index 10e89586ca72..8807c90df749 100644
>>> --- a/drivers/i2c/busses/i2c-imx.c
>>> +++ b/drivers/i2c/busses/i2c-imx.c
>>> @@ -1388,7 +1388,7 @@ static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx,
>>> struct i2c_bus_recovery_info *rinfo = &i2c_imx->rinfo;
>>>
>>> i2c_imx->pinctrl = devm_pinctrl_get(&pdev->dev);
>>> - if (!i2c_imx->pinctrl || IS_ERR(i2c_imx->pinctrl)) {
>>> + if (!IS_ERR_OR_NULL(i2c_imx->pinctrl)) {
>>
>> Sorry, there is a problem, please ignore it.
>
> I don't think these conversions are appropriate for devm_pinctrl_get().
> If one reads the code for devm_pinctrl_get() and pinctrl_get(), then
> one finds that it will never return NULL.
Right! devm_pinctrl_get() never return NULL.
>
> So the tests for NULL do not serve any practical purpose than giving
> coders a warm fuzzy feeling that they've tested for a NULL pointer.
> Practically, they are of no use, so should be removed... thus making
> the conversion to IS_ERR_OR_NULL() irrelevant.
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH -next] I2C: Use helper function IS_ERR_OR_NULL()
2023-08-16 10:22 ` Russell King (Oracle)
@ 2023-08-17 1:39 ` Ruan Jinjie
0 siblings, 0 replies; 8+ messages in thread
From: Ruan Jinjie @ 2023-08-17 1:39 UTC (permalink / raw)
To: Russell King (Oracle)
Cc: linux-i2c, linux-arm-kernel, Codrin Ciubotariu, Andi Shyti,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Oleksij Rempel,
Pengutronix Kernel Team, Shawn Guo, Sascha Hauer, Fabio Estevam,
NXP Linux Team
On 2023/8/16 18:22, Russell King (Oracle) wrote:
> On Wed, Aug 16, 2023 at 05:46:18PM +0800, Ruan Jinjie wrote:
>> Use IS_ERR_OR_NULL() instead of open-coding it
>> to simplify the code.
>>
>> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
>> ---
>> drivers/i2c/busses/i2c-at91-master.c | 2 +-
>> drivers/i2c/busses/i2c-imx.c | 2 +-
>> 2 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-at91-master.c b/drivers/i2c/busses/i2c-at91-master.c
>> index 94cff1cd527e..0e454c04a145 100644
>> --- a/drivers/i2c/busses/i2c-at91-master.c
>> +++ b/drivers/i2c/busses/i2c-at91-master.c
>> @@ -831,7 +831,7 @@ static int at91_init_twi_recovery_gpio(struct platform_device *pdev,
>> struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
>>
>> rinfo->pinctrl = devm_pinctrl_get(&pdev->dev);
>> - if (!rinfo->pinctrl || IS_ERR(rinfo->pinctrl)) {
>> + if (IS_ERR_OR_NULL(rinfo->pinctrl)) {
>> dev_info(dev->dev, "can't get pinctrl, bus recovery not supported\n");
>> return PTR_ERR(rinfo->pinctrl);
>> }
>> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
>> index 10e89586ca72..8807c90df749 100644
>> --- a/drivers/i2c/busses/i2c-imx.c
>> +++ b/drivers/i2c/busses/i2c-imx.c
>> @@ -1388,7 +1388,7 @@ static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx,
>> struct i2c_bus_recovery_info *rinfo = &i2c_imx->rinfo;
>>
>> i2c_imx->pinctrl = devm_pinctrl_get(&pdev->dev);
>> - if (!i2c_imx->pinctrl || IS_ERR(i2c_imx->pinctrl)) {
>> + if (!IS_ERR_OR_NULL(i2c_imx->pinctrl)) {
>> dev_info(&pdev->dev, "can't get pinctrl, bus recovery not supported\n");
>> return PTR_ERR(i2c_imx->pinctrl);
>> }
>
> As stated in my previous reply to a similar patch, devm_pinctrl_get()
> can not return NULL, so it makes more sense to remove the test for NULL
> rather than "cleaning up" the buggy code, but leaving the bugs behind.
Right! I'll fix it sooner. Thank you very much.
>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-08-17 1:40 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-16 9:46 [PATCH -next] I2C: Use helper function IS_ERR_OR_NULL() Ruan Jinjie
2023-08-16 9:48 ` Ruan Jinjie
2023-08-16 10:08 ` Russell King (Oracle)
2023-08-17 1:38 ` Ruan Jinjie
2023-08-16 9:51 ` Yann Sionneau
2023-08-16 10:22 ` Russell King (Oracle)
2023-08-16 10:22 ` Russell King (Oracle)
2023-08-17 1:39 ` Ruan Jinjie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox