Skip to contentSkip to conversation

phy: core: Fix error checking in (devm_)phy_optional_get

PATCH Superseded Axel Lin 2 participants 3 messages Apr 7, 2015 Generic PHY framework

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 phy: core: Fix error checking in (devm_)phy_optional_get

Don't pass valid pointer to PTR_ERR, use PTR_ERR(phy) only when IS_ERR(phy) is true.

---
 drivers/phy/phy-core.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/phy/phy-core.c +8 -4
index 3791838f..f112fff 100644
@@ -530,8 +530,10 @@ struct phy *phy_optional_get(struct device *dev, const char *string)
 {
 	struct phy *phy = phy_get(dev, string);
 
-	if (PTR_ERR(phy) == -ENODEV)
-		phy = NULL;
+	if (IS_ERR(phy)) {
+		if (PTR_ERR(phy) == -ENODEV)
+			phy = NULL;
+	}
 
 	return phy;
 }
@@ -584,8 +586,10 @@ struct phy *devm_phy_optional_get(struct device *dev, const char *string)
 {
 	struct phy *phy = devm_phy_get(dev, string);
 
-	if (PTR_ERR(phy) == -ENODEV)
-		phy = NULL;
+	if (IS_ERR(phy)) {
+		if (PTR_ERR(phy) == -ENODEV)
+			phy = NULL;
+	}
 
 	return phy;
 }
Signature · 1 line
1.9.1
#1 lore raw

Hi,

Quoted 13 lines · Axel Lin

Don't pass valid pointer to PTR_ERR, use PTR_ERR(phy) only when IS_ERR(phy) is true.

---
  drivers/phy/phy-core.c | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
drivers/phy/phy-core.c +0 -0
index 3791838f..f112fff 100644

drivers/phy/phy-core.c struct phy *phy_optional_get(struct device *dev, const char *string) · line 534

Quoted 7 lines
drivers/phy/phy-core.c +2 -2
@@ -530,8 +530,10 @@ struct phy *phy_optional_get(struct device *dev, const char *string)
  {
  	struct phy *phy = phy_get(dev, string);
 
-	if (PTR_ERR(phy) == -ENODEV)
-		phy = NULL;
+	if (IS_ERR(phy)) {
+		if (PTR_ERR(phy) == -ENODEV)

This can simply be (IS_ERR(phy) && (PTR_ERR(phy) == -ENODEV)). But I don't see a problem passing a valid pointer to PTR_ERR here.

Thanks
Kishon

author
#2 lore raw

2015-04-07 22:21 GMT+08:00 Kishon Vijay Abraham I <[email protected]>:

Quoted 21 lines

Hi,

Quoted 18 lines · Axel Lin

Don't pass valid pointer to PTR_ERR, use PTR_ERR(phy) only when IS_ERR(phy) is true.

---
  drivers/phy/phy-core.c | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
drivers/phy/phy-core.c +0 -0
index 3791838f..f112fff 100644
@@ -530,8 +530,10 @@ struct phy *phy_optional_get(struct device *dev,
 const char *string)
  {
        struct phy *phy = phy_get(dev, string);
 
Quoted 7 lines

drivers/phy/phy-core.c struct phy *phy_optional_get(struct device *dev, const char *string) · line 534

Quoted 4 lines
drivers/phy/phy-core.c +2 -2
-       if (PTR_ERR(phy) == -ENODEV)
-               phy = NULL;
+       if (IS_ERR(phy)) {
+               if (PTR_ERR(phy) == -ENODEV)

This can simply be (IS_ERR(phy) && (PTR_ERR(phy) == -ENODEV)).

ok, I just sent v2.

Quoted 1 line

But I don't see a problem passing a valid pointer to PTR_ERR here.

I'm not very sure if it's correct to do so.
My understanding is the PTR_ERR is supposed to be used for invalid pointer.

Regards,
Axel