Don't return NULL from get_phy_device() anymore
Subsystems (5)
cover Don't return NULL from get_phy_device() anymore
Hello.
Here's the set of 5 patches against DaveM's 'net-next.git' repo. The first
patch makes get_phy_device() return only error values on error, the rest of the patches clean up the callers of that function...
[1/5] phylib-don-t-return-NULL-from-get_phy_device.patch [2/5] xgene-get_phy_device-doesn-t-return-NULL-anymore.patch [3/5] fixed_phy-get_phy_device-doesn-t-return-NULL-anymore.patch [4/5] mdio_bus-get_phy_device-doesn-t-return-NULL-anymore.patch [5/5] of_mdio-get_phy_device-doesn-t-return-NULL-anymore.patch
MBR, Sergei
PATCH 1/5 phylib: don't return NULL from get_phy_device()
Arnd Bergmann asked that get_phy_device() returns either NULL or the error value, not both on error. Do as he said, return ERR_PTR(-ENODEV) instead of NULL when the PHY ID registers read as all ones.
--- drivers/net/phy/phy_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/phy_device.c +1 -1
@@ -529,7 +529,7 @@ struct phy_device *get_phy_device(struct/* If the phy_id is mostly Fs, there is no device there */ if ((phy_id &0x1fffffff ) ==0x1fffffff ) -return NULL ; +return ERR_PTR (-ENODEV );return phy_device_create (bus, addr, phy_id, is_c45, &c45_ids); }
Re: [PATCH 1/5] phylib: don't return NULL from get_phy_device()
Quoted 6 lines · Sergei Shtylyov
Arnd Bergmann asked that
get_phy_device()returns either NULL or the error value, not both on error. Do as he said, returnERR_PTR(-ENODEV)instead of NULL when the PHY ID registers read as all ones.Suggested-by Arnd Bergmann <[email protected]>Signed-off-by Sergei Shtylyov <[email protected]>
Signature · 1 line
Florian
A message that is not in the archive (sent off-list or not yet received): [email protected]
Andrew Lunn
maintainerRe: [PATCH 1/5] phylib: don't return NULL from get_phy_device()
Quoted 21 lines · Vivien Didelot
Hi David, All,
Quoted 17 lines · Sergei Shtylyov
Arnd Bergmann asked that
get_phy_device()returns either NULL or the error value, not both on error. Do as he said, returnERR_PTR(-ENODEV)instead of NULL when the PHY ID registers read as all ones.Suggested-by Arnd Bergmann <[email protected]>Signed-off-by Sergei Shtylyov <[email protected]>--- drivers/net/phy/phy_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Index:
net-next/drivers/net/phy/phy_device.c
===================================================================drivers/net/phy/phy_device.c +0
-0@@ -529,7 +529,7 @@ struct phy_device *get_phy_device(struct
Quoted 7 lines
drivers/net/phy/phy_device.c struct phy_device *get_phy_device(struct · line 535
Quoted 7 lines
drivers/net/phy/phy_device.c +1
-1/* If the phy_id is mostly Fs, there is no device there */ if ((phy_id &0x1fffffff ) ==0x1fffffff ) -return NULL ; +return ERR_PTR (-ENODEV );return phy_device_create (bus, addr, phy_id, is_c45, &c45_ids); }
This change is wrong, it needs reverting, or the call sights need fixing to expect ENODEV.
The point is, the device not being there is not an error, with respect to the code calling this function.
It gets called by mdiobus_scan()
struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)
{
struct phy_device *phydev;
int err;
phydev = get_phy_device(bus, addr, false);
if (IS_ERR(phydev) || phydev == NULL)
return phydev;So before, we return NULL, if the device was not there. Now we return ERR_PTR(-ENODEV).
This is being called by:
int __mdiobus_register(struct mii_bus *bus, struct module *owner)
{
struct mdio_device *mdiodev;
...
for (i = 0; i < PHY_MAX_ADDR; i++) {
if ((bus->phy_mask & (1 << i)) == 0) {
struct phy_device *phydev;
phydev = mdiobus_scan(bus, i);
if (IS_ERR(phydev)) {
err = PTR_ERR(phydev);
goto error;
}
}
}This is treating ERR_PTR(-ENODEV) as a fatal error, where as before IS_ERR(NULL) would be false and it would continue scanning other addresses on the bus.
Please revert this, or fix all the callsites such that ENODEV is not a fatal error.
Andrew
Re: [PATCH 1/5] phylib: don't return NULL from get_phy_device()
Hello.
Quoted 24 lines · Andrew Lunn
Quoted 24 lines
Quoted 22 lines · Sergei Shtylyov
Arnd Bergmann asked that
get_phy_device()returns either NULL or the error value, not both on error. Do as he said, returnERR_PTR(-ENODEV)instead of NULL when the PHY ID registers read as all ones.Suggested-by Arnd Bergmann <[email protected]>Signed-off-by Sergei Shtylyov <[email protected]>--- drivers/net/phy/phy_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Index:
net-next/drivers/net/phy/phy_device.c
===================================================================drivers/net/phy/phy_device.c +1
-1@@ -529,7 +529,7 @@ struct phy_device *get_phy_device(struct/* If the phy_id is mostly Fs, there is no device there */ if ((phy_id &0x1fffffff ) ==0x1fffffff ) -return NULL ; +return ERR_PTR (-ENODEV );
Quoted 5 lines
Quoted 2 lines
drivers/net/phy/phy_device.c struct phy_device *get_phy_device(struct · line 535
Quoted 2 lines
drivers/net/phy/phy_device.c +0
-0return phy_device_create (bus, addr, phy_id, is_c45, &c45_ids); }This change is wrong, it needs reverting, or the call sights need fixing to expect ENODEV.
So this function had a good reason to return NULL, as it turned out... :-(
Quoted 35 lines
The point is, the device not being there is not an error, with respect to the code calling this function.
It gets called by
mdiobus_scan()struct
phy_device*mdiobus_scan(structmii_bus*bus, int addr){ struct phy_device *phydev; int err; phydev = get_phy_device(bus, addr, false); if (IS_ERR(phydev) || phydev == NULL) return phydev;So before, we return NULL, if the device was not there. Now we return
ERR_PTR(-ENODEV).This is being called by:
int
__mdiobus_register(struct mii_bus *bus, struct module *owner){ struct mdio_device *mdiodev; ... for (i = 0; i < PHY_MAX_ADDR; i++) { if ((bus->phy_mask & (1 << i)) == 0) { struct phy_device *phydev; phydev = mdiobus_scan(bus, i); if (IS_ERR(phydev)) { err = PTR_ERR(phydev); goto error; } } }
Quoted 3 lines
This is treating
ERR_PTR(-ENODEV)as a fatal error, where as beforeIS_ERR(NULL)would be false and it would continue scanning other addresses on the bus.
Thank you for the detailed analysis! (And shame on me for the lack of it.)
Quoted 2 lines
Please revert this, or fix all the callsites such that ENODEV is not a fatal error.
OK, I'll do what DaveM decides.
Quoted 1 line
Andrew
MBR, Sergei
David Miller
maintainerRe: [PATCH 1/5] phylib: don't return NULL from get_phy_device()
From: Sergei Shtylyov <[email protected]>
Date: Wed, 27 Apr 2016 23:09:37 +0300
Quoted 6 lines · Andrew Lunn
Quoted 3 lines
Please revert this, or fix all the callsites such that ENODEV is not a fatal error.
OK, I'll do what DaveM decides.
If you feel confident getting all the ENODEV checks right, please just do that.
Thanks.
Re: [PATCH 1/5] phylib: don't return NULL from get_phy_device()
In reply to Sergei ShtylyovQuoted 75 lines · On Wednesday 27 April 2016 23:09:37 Sergei Shtylyov wrote:
Hello.
Quoted 24 lines · Andrew Lunn
Quoted 24 lines
Quoted 22 lines · Sergei Shtylyov
Arnd Bergmann asked that
get_phy_device()returns either NULL or the error value, not both on error. Do as he said, returnERR_PTR(-ENODEV)instead of NULL when the PHY ID registers read as all ones.Suggested-by Arnd Bergmann <[email protected]>Signed-off-by Sergei Shtylyov <[email protected]>--- drivers/net/phy/phy_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Index:
net-next/drivers/net/phy/phy_device.c
===================================================================drivers/net/phy/phy_device.c +1
-1@@ -529,7 +529,7 @@ struct phy_device *get_phy_device(struct/* If the phy_id is mostly Fs, there is no device there */ if ((phy_id &0x1fffffff ) ==0x1fffffff ) -return NULL ; +return ERR_PTR (-ENODEV );Quoted 5 lines
Quoted 2 lines
drivers/net/phy/phy_device.c struct phy_device *get_phy_device(struct · line 535
Quoted 2 lines
drivers/net/phy/phy_device.c +0
-0return phy_device_create (bus, addr, phy_id, is_c45, &c45_ids); }This change is wrong, it needs reverting, or the call sights need fixing to expect ENODEV.
So this function had a good reason to return NULL, as it turned out... :-(Quoted 35 lines
The point is, the device not being there is not an error, with respect to the code calling this function.
It gets called by
mdiobus_scan()struct
phy_device*mdiobus_scan(structmii_bus*bus, int addr){ struct phy_device *phydev; int err; phydev = get_phy_device(bus, addr, false); if (IS_ERR(phydev) || phydev == NULL) return phydev;So before, we return NULL, if the device was not there. Now we return
ERR_PTR(-ENODEV).This is being called by:
int
__mdiobus_register(struct mii_bus *bus, struct module *owner){ struct mdio_device *mdiodev; ... for (i = 0; i < PHY_MAX_ADDR; i++) { if ((bus->phy_mask & (1 << i)) == 0) { struct phy_device *phydev; phydev = mdiobus_scan(bus, i); if (IS_ERR(phydev)) { err = PTR_ERR(phydev); goto error; } } }Quoted 3 lines
This is treating
ERR_PTR(-ENODEV)as a fatal error, where as beforeIS_ERR(NULL)would be false and it would continue scanning other addresses on the bus.
Quoted 6 lines
Thank you for the detailed analysis! (And shame on me for the lack of it.)
Quoted 2 lines
Please revert this, or fix all the callsites such that ENODEV is not a fatal error.
OK, I'll do what DaveM decides.
I found one other user that remains broken: pxa168_init_phy() looks wrong before and after the patch:
pep->phy = mdiobus_scan(pep->smi_bus, pep->phy_addr);
if (!pep->phy)
return -ENODEV;
err = phy_connect_direct(dev, pep->phy, pxa168_eth_adjust_link,
pep->phy_intf);as phy_connect_direct() will go on and dereference an error pointer. This should check for IS_ERR(), and with the patches applied, we can drop the !pep->phy check.
Arnd
Re: [PATCH 1/5] phylib: don't return NULL from get_phy_device()
In reply to Andrew LunnQuoted 68 lines · Andrew Lunn
Quoted 21 lines · Vivien Didelot
Hi David, All,
Quoted 17 lines · Sergei Shtylyov
Arnd Bergmann asked that
get_phy_device()returns either NULL or the error value, not both on error. Do as he said, returnERR_PTR(-ENODEV)instead of NULL when the PHY ID registers read as all ones.Suggested-by Arnd Bergmann <[email protected]>Signed-off-by Sergei Shtylyov <[email protected]>--- drivers/net/phy/phy_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Index:
net-next/drivers/net/phy/phy_device.c
===================================================================drivers/net/phy/phy_device.c +0
-0@@ -529,7 +529,7 @@ struct phy_device *get_phy_device(structQuoted 7 lines
drivers/net/phy/phy_device.c struct phy_device *get_phy_device(struct · line 535
Quoted 7 lines
drivers/net/phy/phy_device.c +1
-1/* If the phy_id is mostly Fs, there is no device there */ if ((phy_id &0x1fffffff ) ==0x1fffffff ) -return NULL ; +return ERR_PTR (-ENODEV );return phy_device_create (bus, addr, phy_id, is_c45, &c45_ids); }This change is wrong, it needs reverting, or the call sights need fixing to expect ENODEV.
The point is, the device not being there is not an error, with respect to the code calling this function.
It gets called by
mdiobus_scan()struct
phy_device*mdiobus_scan(structmii_bus*bus, int addr){ struct phy_device *phydev; int err; phydev = get_phy_device(bus, addr, false); if (IS_ERR(phydev) || phydev == NULL) return phydev;So before, we return NULL, if the device was not there. Now we return
ERR_PTR(-ENODEV).This is being called by:
int
__mdiobus_register(struct mii_bus *bus, struct module *owner){ struct mdio_device *mdiodev; ... for (i = 0; i < PHY_MAX_ADDR; i++) { if ((bus->phy_mask & (1 << i)) == 0) { struct phy_device *phydev; phydev = mdiobus_scan(bus, i); if (IS_ERR(phydev)) { err = PTR_ERR(phydev); goto error; } } }
Quoted 6 lines
This is treating
ERR_PTR(-ENODEV)as a fatal error, where as beforeIS_ERR(NULL)would be false and it would continue scanning other addresses on the bus.Please revert this, or fix all the callsites such that ENODEV is not a fatal error.
So the one you pointed out in __mdiobus_register() is definitively needed, though I did get a different issue than Vivien's (-EBUSY vs. -EINVAL). The get_phy_device() in drivers/of/of_mdio.c probably needs something similar too, here is what I locally have for the moment:
drivers/net/phy/mdio_bus.c +0 -0
@@ -333,7 +333,7 @@ int __mdiobus_register(struct mii_bus *bus, struct
module *owner)
struct phy_device *phydev;
phydev = mdiobus_scan(bus, i);
- if (IS_ERR(phydev)) {
+ if (IS_ERR(phydev) && PTR_ERR(phydev) != -ENODEV) {
err = PTR_ERR(phydev);
goto error;
}Signature · 1 line
Florian
Re: [PATCH 1/5] phylib: don't return NULL from get_phy_device()
Quoted 13 lines · On Wednesday 27 April 2016 14:47:29 Florian Fainelli wrote:
drivers/net/phy/mdio_bus.c +1
-1@@ -333,7 +333,7 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)struct phy_device *phydev; phydev =mdiobus_scan (bus, i); -if (IS_ERR (phydev)) { +if (IS_ERR (phydev) &&PTR_ERR (phydev) != -ENODEV ) { err =PTR_ERR (phydev); goto error;
Quoted 3 lines
}
I think that is an improvement over the original code, and better than reverting the series. Out of the three callers of mdiobus_scan, I already commented on drivers/net/ethernet/marvell/pxa168_eth.c being wrong to start with, and drivers/net/ethernet/cadence/macb.c seems to require the same fix that you did here for mdio_bus.c
Arnd
Re: [PATCH 1/5] phylib: don't return NULL from get_phy_device()
In reply to a message not in the archiveHello.
Quoted 27 lines · Vivien Didelot
Quoted 16 lines
Arnd Bergmann asked that
get_phy_device()returns either NULL or the error value, not both on error. Do as he said, returnERR_PTR(-ENODEV)instead of NULL when the PHY ID registers read as all ones.Suggested-by Arnd Bergmann <[email protected]>Signed-off-by Sergei Shtylyov <[email protected]>--- drivers/net/phy/phy_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Index:
net-next/drivers/net/phy/phy_device.c
===================================================================drivers/net/phy/phy_device.c struct phy_device *get_phy_device(struct · line 535
Quoted 8 lines
drivers/net/phy/phy_device.c +1
-1@@ -529,7 +529,7 @@ struct phy_device *get_phy_device(struct/* If the phy_id is mostly Fs, there is no device there */ if ((phy_id &0x1fffffff ) ==0x1fffffff ) -return NULL ; +return ERR_PTR (-ENODEV );return phy_device_create (bus, addr, phy_id, is_c45, &c45_ids); }This particular commit, merged as:
Quoted 8 lines
b74766a0a0fe ("phylib: don't return NULL from get_phy_device()")breaks my 3-switch DSA setup with the following error:
fec: probe of 400d1000.ethernet failed with error -22
Reverting
c971c0e580a6("Merge branch 'get_phy_device-retval'") restores a working setup.
I think I was able to follow this to the get_phy_device() call infixed_phy_register() but I'm unable to see why it fails now and didn't before. Are you using fixed_phy.c at all?
Quoted 3 lines
Thanks,
Vivien
MBR, Sergei
Re: [PATCH 1/5] phylib: don't return NULL from get_phy_device()
Quoted 37 lines · Sergei Shtylyov
Hello.
Quoted 33 lines · Vivien Didelot
Quoted 18 lines
Arnd Bergmann asked that
get_phy_device()returns either NULL or the error
value, not both on error. Do as he said, returnERR_PTR(-ENODEV)instead
of NULL when the PHY ID registers read as all ones.Suggested-by Arnd Bergmann <[email protected]>Signed-off-by Sergei Shtylyov <[email protected]>--- drivers/net/phy/phy_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Index:
net-next/drivers/net/phy/phy_device.c
===================================================================drivers/net/phy/phy_device.c struct phy_device *get_phy_device(struct · line 535
Quoted 8 lines
drivers/net/phy/phy_device.c +1
-1@@ -529,7 +529,7 @@ struct phy_device *get_phy_device(struct/* If the phy_id is mostly Fs, there is no device there */ if ((phy_id &0x1fffffff ) ==0x1fffffff ) -return NULL ; +return ERR_PTR (-ENODEV );return phy_device_create (bus, addr, phy_id, is_c45, &c45_ids); }This particular commit, merged as:
b74766a0a0fe ("phylib: don't return NULL from get_phy_device()")breaks my 3-switch DSA setup with the following error:
Quoted 8 lines
Quoted 4 lines
fec: probe of 400d1000.ethernet failed with error -22
Reverting
c971c0e580a6("Merge branch 'get_phy_device-retval'") restores a working setup.I think I was able to follow this to the
get_phy_device()call infixed_phy_register()but I'm unable to see why it fails now and didn't before. Are you usingfixed_phy.cat all?
I am using fixed_phy.c and yes, this fails for me too, sorry for not catching that when you posted the patches :/
Signature · 1 line
Florian
PATCH 2/5 xgene: get_phy_device() doesn't return NULL anymore
In reply to Sergei ShtylyovNow that get_phy_device() no longer returns NULL on error, we don't need to check for it...
--- drivers/net/ethernet/apm/xgene/xgene_enet_hw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/apm/xgene/xgene_enet_hw.c +1 -1
@@ -824,7 +824,7 @@ static int xgene_mdiobus_register(structreturn -EINVAL ; phy =get_phy_device (mdio, phy_id, false); -if (!phy ||IS_ERR (phy)) +if (IS_ERR (phy))return -EIO ; ret =phy_device_register (phy);
Re: [PATCH 2/5] xgene: get_phy_device() doesn't return NULL anymore
Quoted 4 lines · Sergei Shtylyov
Now that
get_phy_device()no longer returns NULL on error, we don't need to check for it...Signed-off-by Sergei Shtylyov <[email protected]>
Signature · 1 line
Florian
PATCH 3/5 fixed_phy: get_phy_device() doesn't return NULL anymore
In reply to Sergei ShtylyovNow that get_phy_device() no longer returns NULL on error, we don't need to check for it...
--- drivers/net/phy/fixed_phy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/fixed_phy.c +1 -1
@@ -328,7 +328,7 @@ struct phy_device *fixed_phy_register(unreturn ERR_PTR (ret); phy =get_phy_device (fmb->mii_bus, phy_addr, false); -if (!phy ||IS_ERR (phy)) { +if (IS_ERR (phy)) {fixed_phy_del (phy_addr);return ERR_PTR (-EINVAL ); }
Re: [PATCH 3/5] fixed_phy: get_phy_device() doesn't return NULL anymore
Quoted 4 lines · Sergei Shtylyov
Now that
get_phy_device()no longer returns NULL on error, we don't need to check for it...Signed-off-by Sergei Shtylyov <[email protected]>
Signature · 1 line
Florian
PATCH 4/5 mdio_bus: get_phy_device() doesn't return NULL anymore
In reply to Sergei ShtylyovNow that get_phy_device() no longer returns NULL on error, we don't need to check for it...
--- drivers/net/phy/mdio_bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/mdio_bus.c +1 -1
@@ -419,7 +419,7 @@ struct phy_device *mdiobus_scan(struct mint err; phydev =get_phy_device (bus, addr, false); -if (IS_ERR (phydev) || phydev ==NULL ) +if (IS_ERR (phydev))return phydev;/*
Re: [PATCH 4/5] mdio_bus: get_phy_device() doesn't return NULL anymore
Quoted 4 lines · Sergei Shtylyov
Now that
get_phy_device()no longer returns NULL on error, we don't need to check for it...Signed-off-by Sergei Shtylyov <[email protected]>
Signature · 1 line
Florian
PATCH 5/5 of_mdio: get_phy_device() doesn't return NULL anymore
In reply to Sergei ShtylyovNow that get_phy_device() no longer returns NULL on error, we don't need to check for it...
--- 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 void of_mdiobus_register_phy(stru phy =phy_device_create (mdio, addr, phy_id,0 ,NULL ); else phy =get_phy_device (mdio, addr, is_c45); -if (IS_ERR_OR_NULL (phy)) +if (IS_ERR (phy))return ; rc =irq_of_parse_and_map (child,0 );
Re: [PATCH 5/5] of_mdio: get_phy_device() doesn't return NULL anymore
Quoted 5 lines · Sergei Shtylyov
Now that
get_phy_device()no longer returns NULL on error, we don't need to check for it...Signed-off-by Sergei Shtylyov <[email protected]>
Oops, forgot to CC: the DT people, doing that now...
Quoted 17 lines
--- 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 void of_mdiobus_register_phy(stru phy =phy_device_create (mdio, addr, phy_id,0 ,NULL ); else phy =get_phy_device (mdio, addr, is_c45); -if (IS_ERR_OR_NULL (phy)) +if (IS_ERR (phy))return ; rc =irq_of_parse_and_map (child,0 );
Re: [PATCH 5/5] of_mdio: get_phy_device() doesn't return NULL anymore
In reply to Sergei ShtylyovQuoted 4 lines · Sergei Shtylyov
Now that
get_phy_device()no longer returns NULL on error, we don't need to check for it...Signed-off-by Sergei Shtylyov <[email protected]>
Signature · 1 line
Florian
David Miller
maintainerFrom: Sergei Shtylyov <[email protected]>
Date: Sun, 24 Apr 2016 20:23:03 +0300
Quoted 3 lines
Here's the set of 5 patches against DaveM's 'net-next.git' repo. The first
patch makesget_phy_device()return only error values on error, the rest of the patches clean up the callers of that function...
Series applied, thanks.