of_mdio: use IS_ERR_OR_NULL() and PTR_ERR_OR_ZERO()
Subsystems (3)
v2 cover of_mdio: use IS_ERR_OR_NULL() and PTR_ERR_OR_ZERO()
Hello.
Here's the set of 3 patches against DaveM's 'net-next.git' repo. They deal
with some error checks in the device tree MDIO code...
[1/3] of_mdio: mdio_device_create() never returns NULL [2/3] of_mdio: use IS_ERR_OR_NULL()
[3/3] of_mdio: use PTR_ERR_OR_ZERO()
MBR, Sergei
PATCH v2 1/3 of_mdio: mdio_device_create() never returns NULL
mdio_device_create() never returns NULL, thus checking for it in of_mdiobus_register_device() is pointless...
---
Changes in version 2:
- new patch.
drivers/of/of_mdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/of_mdio.c +1 -1
@@ -98,7 +98,7 @@ static int of_mdiobus_register_device(stint rc; mdiodev =mdio_device_create (mdio, addr); -if (!mdiodev ||IS_ERR (mdiodev)) +if (IS_ERR (mdiodev))return 1 ;/* Associate the OF node with the device structure so it
PATCH v2 2/3 of_mdio: use IS_ERR_OR_NULL()
In reply to Sergei ShtylyovIS_ERR_OR_NULL() is open coded in of_mdiobus_register_phy(), so just call it directly...
---
Changes in version 2:
- removed the of_mdiobus_register_device() hunk;
- added the "Reviewed-by:" tag.
drivers/of/of_mdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/of_mdio.c +1 -1
@@ -56,7 +56,7 @@ static int of_mdiobus_register_phy(struc phy =phy_device_create (mdio, addr, phy_id,0 ,NULL ); else phy =get_phy_device (mdio, addr, is_c45); -if (!phy ||IS_ERR (phy)) +if (IS_ERR_OR_NULL (phy))return 1 ; rc =irq_of_parse_and_map (child,0 );
PATCH v2 3/3 of_mdio: use PTR_ERR_OR_ZERO()
In reply to Sergei ShtylyovPTR_ERR_OR_ZERO() is open coded in of_phy_register_fixed_link(), so just call it directly...
---
Changes in version 2:
- added the "Reviewed-by:" tags.
drivers/of/of_mdio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/of/of_mdio.c +3 -3
@@ -412,7 +412,7 @@ int of_phy_register_fixed_link(struct deif (strcmp (managed,"in-band-status" ) ==0 ) {/* status is zeroed, namely its .link member */ phy =fixed_phy_register (PHY_POLL , &status,-1 , np); -return IS_ERR (phy) ?PTR_ERR (phy) :0 ; +return PTR_ERR_OR_ZERO (phy); } }
@@ -434,7 +434,7 @@ int of_phy_register_fixed_link(struct dereturn -EPROBE_DEFER ; phy =fixed_phy_register (PHY_POLL , &status, link_gpio, np); -return IS_ERR (phy) ?PTR_ERR (phy) :0 ; +return PTR_ERR_OR_ZERO (phy); }/* Old binding */
@@ -446,7 +446,7 @@ int of_phy_register_fixed_link(struct de status.pause =be32_to_cpu (fixed_link_prop[3 ]); status.asym_pause =be32_to_cpu (fixed_link_prop[4 ]); phy =fixed_phy_register (PHY_POLL , &status,-1 , np); -return IS_ERR (phy) ?PTR_ERR (phy) :0 ; +return PTR_ERR_OR_ZERO (phy); }return -ENODEV ;
Re: [PATCH v2 2/3] of_mdio: use IS_ERR_OR_NULL()
In reply to a message not in the archiveQuoted 21 lines · On Sunday 13 March 2016 00:34:02 Sergei Shtylyov wrote:
IS_ERR_OR_NULL()is open coded inof_mdiobus_register_phy(), so just call it directly...Reviewed-by Florian Fainelli <[email protected]>---
Changes in version 2:
- removed theof_mdiobus_register_device()hunk;
- added the "Reviewed-by:" tag.drivers/of/of_mdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Index:
net-next/drivers/of/of_mdio.c
===================================================================
drivers/of/of_mdio.c static int of_mdiobus_register_phy(struc · line 62
Quoted 8 lines
drivers/of/of_mdio.c +1
-1@@ -56,7 +56,7 @@ static int of_mdiobus_register_phy(struc phy =phy_device_create (mdio, addr, phy_id,0 ,NULL ); else phy =get_phy_device (mdio, addr, is_c45); -if (!phy ||IS_ERR (phy)) +if (IS_ERR_OR_NULL (phy))return 1 ; rc =irq_of_parse_and_map (child,0 );
IS_ERR_OR_NULL() usually indicates that the code is wrong, or that an API has been misdesigned.
Can you clarify in the changelog which one it is, or (better) change it so that 'phy' in this function is either NULL or IS_ERR() in case of an error but not both?
I think moving the 'if (problem) return 1' into the two if/else is a correct transformation that also makes it very clear what is going on here.
Arnd
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 2/3] of_mdio: use IS_ERR_OR_NULL()
Quoted 26 lines · Arnd Bergmann
Quoted 26 lines
IS_ERR_OR_NULL()is open coded inof_mdiobus_register_phy(), so just call it directly...Signed-off-by Sergei Shtylyov <[email protected]>Reviewed-by Florian Fainelli <[email protected]>---
Changes in version 2:
- removed theof_mdiobus_register_device()hunk;
- added the "Reviewed-by:" tag.drivers/of/of_mdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Index:
net-next/drivers/of/of_mdio.c
===================================================================drivers/of/of_mdio.c +1
-1@@ -56,7 +56,7 @@ static int of_mdiobus_register_phy(struc phy =phy_device_create (mdio, addr, phy_id,0 ,NULL ); else phy =get_phy_device (mdio, addr, is_c45); -if (!phy ||IS_ERR (phy)) +if (IS_ERR_OR_NULL (phy))return 1 ;
Quoted 8 lines
drivers/of/of_mdio.c static int of_mdiobus_register_phy(struc · line 62
Quoted 3 lines
drivers/of/of_mdio.c +0
-0rc =irq_of_parse_and_map (child,0 );
IS_ERR_OR_NULL()usually indicates that the code is wrong, or that an API has been misdesigned.Can you clarify in the changelog which one it is,
The second. :-)
Quoted 3 lines
or (better) change
it so that 'phy' in this function is either NULL orIS_ERR()in case of an error but not both?
I guess you meant to change get_phy_device() to not return NULL (and so
only return the error codes, not both), am I correct?
Quoted 3 lines
I think moving the 'if (problem) return 1' into the two if/else is a correct transformation that also makes it very clear what is going on here.
Can be done too... it's not that I have much time for that many respins
though. It all started with 1 little patch (this one). :-)
Quoted 1 line
Arnd
MBR, Sergei
David Miller
maintainerFrom: Sergei Shtylyov <[email protected]>
Date: Sun, 13 Mar 2016 00:32:13 +0300
Quoted 3 lines
Here's the set of 3 patches against DaveM's 'net-next.git'
repo. They deal with some error checks in the device tree MDIO code...
Series applied, thanks.