Skip to contentSkip to conversation

net: eth-phy: Handle gpio_request_by_name() return value

PATCH In review Marek Vasut 2 participants 5 messages Nov 13, 2021 – Dec 2, 2021 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: eth-phy: Handle gpio_request_by_name() return value

The gpio_request_by_name() returns zero in case of success, however the conditional return value check in gpio_request_by_name() checks only for (ret != -ENOENT) and if the condition is true, returns ret outright.

This leads to a situation where successful gpio_request_by_name() return leads to immediate successful eth_phy_of_to_plat() return as well, and to skipped parsing of "reset-assert-us" and "reset-deassert-us", so the PHY driver operates with valid reset GPIO, but with assert/deassert times set to default, which is 0, instead of the values from DT. This breaks PHY reset.

Fix this by checking if return value is non-zero and then for this one single allowed non-zero return value, -ENOENT.

---
 drivers/net/eth-phy-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/eth-phy-uclass.c +1 -1
index c04bab944d6..a9b358ee234 100644
@@ -138,7 +138,7 @@ static int eth_phy_of_to_plat(struct udevice *dev)
 	ret = gpio_request_by_name(dev, "reset-gpios", 0,
 				   &uc_priv->reset_gpio,
 				   GPIOD_IS_OUT);
-	if (ret != -ENOENT)
+	if (ret && ret != -ENOENT)
 		return ret;
 
 	uc_priv->reset_assert_delay = dev_read_u32_default(dev, "reset-assert-us", 0);
Signature · 1 line
2.33.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 35 lines · Marek Vasut

The gpio_request_by_name() returns zero in case of success, however the conditional return value check in gpio_request_by_name() checks only for (ret != -ENOENT) and if the condition is true, returns ret outright.

This leads to a situation where successful gpio_request_by_name() return leads to immediate successful eth_phy_of_to_plat() return as well, and to skipped parsing of "reset-assert-us" and "reset-deassert-us", so the PHY driver operates with valid reset GPIO, but with assert/deassert times set to default, which is 0, instead of the values from DT. This breaks PHY reset.

Fix this by checking if return value is non-zero and then for this one single allowed non-zero return value, -ENOENT.

---
 drivers/net/eth-phy-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/eth-phy-uclass.c +1 -2
index c04bab944d6..a9b358ee234 100644
@@ -138,7 +138,7 @@ static int eth_phy_of_to_plat(struct udevice *dev)
        ret = gpio_request_by_name(dev, "reset-gpios", 0,
                                   &uc_priv->reset_gpio,
                                   GPIOD_IS_OUT);
-       if (ret != -ENOENT)
+       if (ret && ret != -ENOENT)
                return ret;
 
        uc_priv->reset_assert_delay = dev_read_u32_default(dev, "reset-assert-us", 0);
--
Quoted 2 lines

2.33.0

#2 lore raw
Quoted 35 lines · Ramon Fried
Quoted 33 lines · Marek Vasut

The gpio_request_by_name() returns zero in case of success, however the conditional return value check in gpio_request_by_name() checks only for (ret != -ENOENT) and if the condition is true, returns ret outright.

This leads to a situation where successful gpio_request_by_name() return leads to immediate successful eth_phy_of_to_plat() return as well, and to skipped parsing of "reset-assert-us" and "reset-deassert-us", so the PHY driver operates with valid reset GPIO, but with assert/deassert times set to default, which is 0, instead of the values from DT. This breaks PHY reset.

Fix this by checking if return value is non-zero and then for this one single allowed non-zero return value, -ENOENT.

---
 drivers/net/eth-phy-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/eth-phy-uclass.c +1 -1
index c04bab944d6..a9b358ee234 100644
@@ -138,7 +138,7 @@ static int eth_phy_of_to_plat(struct udevice *dev)
        ret = gpio_request_by_name(dev, "reset-gpios", 0,
                                   &uc_priv->reset_gpio,
                                   GPIOD_IS_OUT);
-       if (ret != -ENOENT)
+       if (ret && ret != -ENOENT)
                return ret;
 
Quoted 5 lines
Quoted 4 lines
drivers/net/eth-phy-uclass.c +0 -1
        uc_priv->reset_assert_delay = dev_read_u32_default(dev, "reset-assert-us", 0);
--

2.33.0

Applied to u-boot-net/next,
Thanks.

#3 lore raw
Quoted 36 lines · Ramon Fried
Quoted 35 lines · Ramon Fried
Quoted 33 lines · Marek Vasut

The gpio_request_by_name() returns zero in case of success, however the conditional return value check in gpio_request_by_name() checks only for (ret != -ENOENT) and if the condition is true, returns ret outright.

This leads to a situation where successful gpio_request_by_name() return leads to immediate successful eth_phy_of_to_plat() return as well, and to skipped parsing of "reset-assert-us" and "reset-deassert-us", so the PHY driver operates with valid reset GPIO, but with assert/deassert times set to default, which is 0, instead of the values from DT. This breaks PHY reset.

Fix this by checking if return value is non-zero and then for this one single allowed non-zero return value, -ENOENT.

---
  drivers/net/eth-phy-uclass.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/eth-phy-uclass.c +1 -1
index c04bab944d6..a9b358ee234 100644
@@ -138,7 +138,7 @@ static int eth_phy_of_to_plat(struct udevice *dev)
         ret = gpio_request_by_name(dev, "reset-gpios", 0,
                                    &uc_priv->reset_gpio,
                                    GPIOD_IS_OUT);
-       if (ret != -ENOENT)
+       if (ret && ret != -ENOENT)
                 return ret;
 
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
drivers/net/eth-phy-uclass.c +0 -1
         uc_priv->reset_assert_delay = dev_read_u32_default(dev, "reset-assert-us", 0);
--

2.33.0

Applied to u-boot-net/next,

Note that this fixes a grave bug in the PHY reset code, so it should go into current release.

#4 lore raw
Quoted 43 lines · Marek Vasut
Quoted 41 lines · Ramon Fried
Quoted 40 lines · Ramon Fried
Quoted 35 lines · Marek Vasut

The gpio_request_by_name() returns zero in case of success, however the conditional return value check in gpio_request_by_name() checks only for (ret != -ENOENT) and if the condition is true, returns ret outright.

This leads to a situation where successful gpio_request_by_name() return leads to immediate successful eth_phy_of_to_plat() return as well, and to skipped parsing of "reset-assert-us" and "reset-deassert-us", so the PHY driver operates with valid reset GPIO, but with assert/deassert times set to default, which is 0, instead of the values from DT. This breaks PHY reset.

Fix this by checking if return value is non-zero and then for this one single allowed non-zero return value, -ENOENT.

---
  drivers/net/eth-phy-uclass.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/eth-phy-uclass.c +1 -2
index c04bab944d6..a9b358ee234 100644
@@ -138,7 +138,7 @@ static int eth_phy_of_to_plat(struct udevice *dev)
         ret = gpio_request_by_name(dev, "reset-gpios", 0,
                                    &uc_priv->reset_gpio,
                                    GPIOD_IS_OUT);
-       if (ret != -ENOENT)
+       if (ret && ret != -ENOENT)
                 return ret;
 
         uc_priv->reset_assert_delay = dev_read_u32_default(dev, "reset-assert-us", 0);
--
Quoted 2 lines

2.33.0

Quoted 4 lines
Quoted 1 line

Applied to u-boot-net/next,

Note that this fixes a grave bug in the PHY reset code, so it should go into current release.

OK.