[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sat, 11 Dec 2021 18:42:19 -0800
From: Joe Perches <joe@...ches.com>
To: Miaoqian Lin <linmq006@...il.com>,
Dan Carpenter <error27@...il.com>
Cc: Doug Berger <opendmb@...il.com>,
Florian Fainelli <f.fainelli@...il.com>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
bcm-kernel-feedback-list@...adcom.com, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] net: bcmgenet: Fix NULL vs IS_ERR() checking
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
Powered by blists - more mailing lists