Skip to contentSkip to conversation

stmmac: fix check for phydev being open

PATCH Superseded Alexey Brodkin 2 participants 5 messages Sep 7, 2015

Subsystems (5)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 stmmac: fix check for phydev being open

Current implementation via IS_ERR(phydev) may make no sense because of_phy_attach() returns NULL on failure instead of error value.

Still for checking result of phy_connect() IS_ERR() is useful.

To address both situations we use combined IS_ERR_OR_NULL() check.

---

Changes compared to v1:
* Use IS_ERR_OR_NULL() instead of discrete checks for null and err

 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 864b476..7985d8a 100644
@@ -837,7 +837,7 @@ static int stmmac_init_phy(struct net_device *dev)
 				     interface);
 	}
 
-	if (IS_ERR(phydev)) {
+	if (IS_ERR_OR_NULL(phydev)) {
 		pr_err("%s: Could not attach to PHY\n", dev->name);
 		return PTR_ERR(phydev);
 	}
Signature · 1 line
2.4.3
#1 lore raw
Quoted 26 lines · Alexey Brodkin

Current implementation via IS_ERR(phydev) may make no sense because of_phy_attach() returns NULL on failure instead of error value.

Still for checking result of phy_connect() IS_ERR() is useful.

To address both situations we use combined IS_ERR_OR_NULL() check.

---

Changes compared to v1:
* Use IS_ERR_OR_NULL() instead of discrete checks for null and err

  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
index 864b476..7985d8a 100644

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_init_phy(struct net_device *dev) · line 842

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
@@ -837,7 +837,7 @@ static int stmmac_init_phy(struct net_device *dev)
  				     interface);
  	}
 
-	if (IS_ERR(phydev)) {
+	if (IS_ERR_OR_NULL(phydev)) {
  		pr_err("%s: Could not attach to PHY\n", dev->name);
  		return PTR_ERR(phydev);

Hm, in case of phydev == NULL, you're going to return 0 here... is that
what you want?

MBR, Sergei

#2 lore raw

Hi Sergei,

Quoted 31 lines · Sergei Shtylyov
Quoted 29 lines · Alexey Brodkin

Current implementation via IS_ERR(phydev) may make no sense because of_phy_attach() returns NULL on failure instead of error value.

Still for checking result of phy_connect() IS_ERR() is useful.

To address both situations we use combined IS_ERR_OR_NULL() check.

---

Changes compared to v1:
* Use IS_ERR_OR_NULL() instead of discrete checks for null and err

  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +--
  1 file changed, 1 insertion(+-), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 864b476..7985d8a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+-+-+- b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

@@ -837,7 +-837,7 @@ static int stmmac_init_phy(struct net_device *dev)
interface);
}

Quoted 7 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_init_phy(struct net_device *dev) · line 842

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
-	if (IS_ERR(phydev)) {
+-	if (IS_ERR_OR_NULL(phydev)) {
  		pr_err("%s: Could not attach to PHY\n", dev->name);
  		return PTR_ERR(phydev);
    Hm, in case of phydev == NULL, you're going to return 0 here... is that 

what you want?

Ah, right.

So then the question would be what's a proper error code for !phydev:
-ENOENT or -ENODEV?

-Alexey

#3 lore raw
In reply to Alexey Brodkin
Quoted 2 lines · Alexey Brodkin

Current implementation via IS_ERR(phydev) may make no sense because of_phy_attach() returns NULL on failure instead of error value.

Not of_phy_connect()?

Quoted 10 lines

Still for checking result of phy_connect() IS_ERR() is useful.

To address both situations we use combined IS_ERR_OR_NULL() check.

MBR, Sergei

#4 lore raw

Hi Sergei,

Quoted 6 lines · Sergei Shtylyov
Quoted 2 lines · Alexey Brodkin

Current implementation via IS_ERR(phydev) may make no sense because of_phy_attach() returns NULL on failure instead of error value.

Not of_phy_connect()?

I already noticed this misspelling - it came from my exploration of what happens inside of_phy_connect(). So sort of braindump.

I will fix in v3 re-spin.

-Alexey