public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Miaoqian Lin <linmq006@gmail.com>, Dan Carpenter <error27@gmail.com>
Cc: Doug Berger <opendmb@gmail.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	bcm-kernel-feedback-list@broadcom.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: bcmgenet: Fix NULL vs IS_ERR() checking
Date: Sat, 11 Dec 2021 18:42:19 -0800	[thread overview]
Message-ID: <e7eeecfb1c967336944f0941900a9052bcce279e.camel@perches.com> (raw)
In-Reply-To: <20211211140154.23613-1-linmq006@gmail.com>

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



  reply	other threads:[~2021-12-12  2:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-11 14:01 [PATCH] net: bcmgenet: Fix NULL vs IS_ERR() checking Miaoqian Lin
2021-12-12  2:42 ` Joe Perches [this message]
2021-12-12  3:58 ` Florian Fainelli
2021-12-13 14:40 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e7eeecfb1c967336944f0941900a9052bcce279e.camel@perches.com \
    --to=joe@perches.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=davem@davemloft.net \
    --cc=error27@gmail.com \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linmq006@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=opendmb@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox