diff mbox series

net: bcmgenet: Fix NULL vs IS_ERR() checking

Message ID 20211211140154.23613-1-linmq006@gmail.com (mailing list archive)
State Accepted
Commit ab8eb798ddabddb2944401bf31ead9671cb97d95
Delegated to: Netdev Maintainers
Headers show
Series net: bcmgenet: Fix NULL vs IS_ERR() checking | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 11 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Miaoqian Lin Dec. 11, 2021, 2:01 p.m. UTC
The phy_attach() function does not return NULL. It returns error pointers.

Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/net/ethernet/broadcom/genet/bcmmii.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Joe Perches Dec. 12, 2021, 2:42 a.m. UTC | #1
On Sat, 2021-12-11 at 14:01 +0000, Miaoqian Lin wrote:
> 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(+)

diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h
index 37e2600202216..e2351a36dda97 100644
--- a/include/linux/compiler_attributes.h
+++ b/include/linux/compiler_attributes.h
@@ -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
Florian Fainelli Dec. 12, 2021, 3:58 a.m. UTC | #2
On 12/11/2021 6:01 AM, Miaoqian Lin wrote:
> The phy_attach() function does not return NULL. It returns error pointers.
> 
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>

Acked-by: Florian Fainelli <f.fainelli@gmail.com>
patchwork-bot+netdevbpf@kernel.org Dec. 13, 2021, 2:40 p.m. UTC | #3
Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

On Sat, 11 Dec 2021 14:01:53 +0000 you wrote:
> The phy_attach() function does not return NULL. It returns error pointers.
> 
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
>  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!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/broadcom/genet/bcmmii.c b/drivers/net/ethernet/broadcom/genet/bcmmii.c
index 5f259641437a..c888ddee1fc4 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmmii.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmmii.c
@@ -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 {
 		/*