All of lore.kernel.org
 help / color / mirror / Atom feed
From: Naohiro Aota <naohiro.aota@wdc.com>
To: David Sterba <dsterba@suse.com>
Cc: linux-btrfs@vger.kernel.org, Naohiro Aota <naohiro.aota@wdc.com>
Subject: [PATCH] btrfs-progs: mark BUG() as unreachable
Date: Thu,  1 Apr 2021 17:41:00 +0900	[thread overview]
Message-ID: <5c7b703beca572514a28677df0caaafab28bfff8.1617265419.git.naohiro.aota@wdc.com> (raw)

Marking BUG() unreachable helps us silence unnecessary warnings e.g.
"warning: control reaches end of non-void function [-Wreturn-type]" like
the code below.

   int foo()
   {
   ...
   	if (XXX)
   		return 0;
	else if (YYY)
		return 1;
   	else
   		BUG();
   }

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 kerncompat.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kerncompat.h b/kerncompat.h
index 01fd93a7b540..7060326fe4f4 100644
--- a/kerncompat.h
+++ b/kerncompat.h
@@ -333,7 +333,11 @@ static inline void assert_trace(const char *assertion, const char *filename,
 #endif
 
 #define BUG_ON(c) bugon_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
-#define BUG() BUG_ON(1)
+#define BUG()				\
+do {					\
+	BUG_ON(1);			\
+	__builtin_unreachable();	\
+} while (0)
 #define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
 
 #define container_of(ptr, type, member) ({                      \
-- 
2.31.1


             reply	other threads:[~2021-04-01  8:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-01  8:41 Naohiro Aota [this message]
2021-04-16 17:35 ` [PATCH] btrfs-progs: mark BUG() as unreachable David Sterba

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=5c7b703beca572514a28677df0caaafab28bfff8.1617265419.git.naohiro.aota@wdc.com \
    --to=naohiro.aota@wdc.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.