Skip to contentSkip to conversation

net: bcmgenet: Fix NULL vs IS_ERR() checking

PATCH Applied Miaoqian Lin 4 participants 4 messages Dec 11, 2021 – Dec 13, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: bcmgenet: Fix NULL vs IS_ERR() checking

The phy_attach() function does not return NULL. It returns error pointers.

---
 drivers/net/ethernet/broadcom/genet/bcmmii.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/broadcom/genet/bcmmii.c +2 -2
index 5f259641437a..c888ddee1fc4 100644
@@ -589,9 +589,9 @@ static int bcmgenet_mii_pd_init(struct bcmgenet_priv *priv)
 		 * Internal or external PHY with MDIO access
 		 */
 		phydev = phy_attach(priv->dev, phy_name, pd->phy_interface);
-		if (!phydev) {
+		if (IS_ERR(phydev)) {
 			dev_err(kdev, "failed to register PHY device\n");
-			return -ENODEV;
+			return PTR_ERR(phydev);
 		}
 	} else {
 		/*
Signature · 1 line
2.17.1
#1 lore raw
Quoted 1 line · Miaoqian Lin

The phy_attach() function does not return NULL. It returns error pointers.

Perhaps all the functions that return error pointers rather than NULL on error should be marked with a special attribute:

Something like:

#define __returns_nonnull __attribute__((__returns_nonnull__))

---

 include/linux/compiler_attributes.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/linux/compiler_attributes.h +12 -0
index 37e2600202216..e2351a36dda97 100644
@@ -250,6 +250,18 @@
 # define __no_profile
 #endif
 
+/*
+ * Optional: only supported since GCC >= 5.x
+ *
+ *      gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-returns_005fnonnull-function-attribute
+ *    clang: https://clang.llvm.org/docs/AttributeReference.html#returns-nonnull
+ */
+#if __has_attribute(__returns_nonnull__)
+# define __returns_nonnull		__attribute__((__returns_nonnull__))
+#else
+# define __returns_nonnull
+#endif
+
 /*
  *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noreturn-function-attribute
  * clang: https://clang.llvm.org/docs/AttributeReference.html#noreturn
#3 lore raw
In reply to Miaoqian Lin
This patch was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <[email protected]>:

Quoted 6 lines · On Sat, 11 Dec 2021 14:01:53 +0000 you wrote:

The phy_attach() function does not return NULL. It returns error pointers.

---
 drivers/net/ethernet/broadcom/genet/bcmmii.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Here is the summary with links:
- net: bcmgenet: Fix NULL vs IS_ERR() checking

    https://git.kernel.org/netdev/net/c/ab8eb798ddab

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html