Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

btrfs: separate definition of assertion failure handlers

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>

+12 -8
+12 -8
fs/btrfs/ctree.h
··· 3157 3157 rcu_read_unlock(); \ 3158 3158 } while (0) 3159 3159 3160 - __cold 3161 - static inline void assfail(const char *expr, const char *file, int line) 3160 + #ifdef CONFIG_BTRFS_ASSERT 3161 + __cold __noreturn 3162 + static inline void assertfail(const char *expr, const char *file, int line) 3162 3163 { 3163 - if (IS_ENABLED(CONFIG_BTRFS_ASSERT)) { 3164 - pr_err("assertion failed: %s, in %s:%d\n", expr, file, line); 3165 - BUG(); 3166 - } 3164 + pr_err("assertion failed: %s, in %s:%d\n", expr, file, line); 3165 + BUG(); 3167 3166 } 3168 3167 3169 - #define ASSERT(expr) \ 3170 - (likely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__)) 3168 + #define ASSERT(expr) \ 3169 + (likely(expr) ? (void)0 : assertfail(#expr, __FILE__, __LINE__)) 3170 + 3171 + #else 3172 + static inline void assertfail(const char *expr, const char* file, int line) { } 3173 + #define ASSERT(expr) (void)(expr) 3174 + #endif 3171 3175 3172 3176 /* 3173 3177 * Use that for functions that are conditionally exported for sanity tests but