btrfs: separate definition of assertion failure handlers
authorDavid Sterba <dsterba@suse.com>
Mon, 16 Dec 2019 19:00:48 +0000 (20:00 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 23 Jan 2020 16:24:23 +0000 (17:24 +0100)
There's a report where objtool detects unreachable instructions, eg.:

  fs/btrfs/ctree.o: warning: objtool: btrfs_search_slot()+0x2d4: unreachable instruction

This seems to be a false positive due to compiler version. The cause is
in the ASSERT macro implementation that does the conditional check as
IS_DEFINED(CONFIG_BTRFS_ASSERT) and not an #ifdef.

To avoid that, use the ifdefs directly.

There are still 2 reports that aren't fixed:

  fs/btrfs/extent_io.o: warning: objtool: __set_extent_bit()+0x71f: unreachable instruction
  fs/btrfs/relocation.o: warning: objtool: find_data_references()+0x4e0: unreachable instruction

Co-developed-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Reported-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.h

index 569931dd0ce55bd58655c3121c26924b30cf00cf..f90b82050d2db9256bcaccd16283a7488ed96a96 100644 (file)
@@ -3157,17 +3157,21 @@ do {                                                            \
        rcu_read_unlock();                                      \
 } while (0)
 
-__cold
-static inline void assfail(const char *expr, const char *file, int line)
+#ifdef CONFIG_BTRFS_ASSERT
+__cold __noreturn
+static inline void assertfail(const char *expr, const char *file, int line)
 {
-       if (IS_ENABLED(CONFIG_BTRFS_ASSERT)) {
-               pr_err("assertion failed: %s, in %s:%d\n", expr, file, line);
-               BUG();
-       }
+       pr_err("assertion failed: %s, in %s:%d\n", expr, file, line);
+       BUG();
 }
 
-#define ASSERT(expr)   \
-       (likely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
+#define ASSERT(expr)                                           \
+       (likely(expr) ? (void)0 : assertfail(#expr, __FILE__, __LINE__))
+
+#else
+static inline void assertfail(const char *expr, const char* file, int line) { }
+#define ASSERT(expr)   (void)(expr)
+#endif
 
 /*
  * Use that for functions that are conditionally exported for sanity tests but