Skip to contentSkip to conversation

bug: Add unreachable() to generic BUG() to silence warnings

PATCH In review Nick Krause 2 participants 2 messages Aug 7, 2014 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bug: Add unreachable() to generic BUG() to silence warnings

Architectures which use generic BUG() have warnings like

kernel/sched/core.c:2692:1: warning: control reaches end of non-void function [-Wreturn-type] net/core/ethtool.c:236:1: warning: control reaches end of non-void function [-Wreturn-type]

Other BUG() implementations
have added unreachable() at end but generic does not. I guess that is why
it showing these errors. We can silence them using unreachable().

---
 include/asm-generic/bug.h | 1 +
 1 file changed, 1 insertion(+)
include/asm-generic/bug.h +1 -0
index 630dd23..effcc82 100644
@@ -48,6 +48,7 @@ struct bug_entry {
 #define BUG() do { \
 	printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
 	panic("BUG!"); \
+	unreachable(); \
 } while (0)
 #endif
 
Signature · 1 line
2.0.1
#1 lore raw
Quoted 11 lines · Nick Krause

Architectures which use generic BUG() have warnings like

kernel/sched/core.c:2692:1: warning: control reaches end of non-void function [-Wreturn-type] net/core/ethtool.c:236:1: warning: control reaches end of non-void function [-Wreturn-type]

Other BUG() implementations
have added unreachable() at end but generic does not. I guess that is why
it showing these errors. We can silence them using unreachable().

You shouldn't see those warnings. panic() has __noreturn set, which should have exactly the same effect.

Quoted 18 lines
 include/asm-generic/bug.h | 1 +
 1 file changed, 1 insertion(+)
include/asm-generic/bug.h +1 -0
index 630dd23..effcc82 100644
@@ -48,6 +48,7 @@ struct bug_entry {
 #define BUG() do { \
 	printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
 	panic("BUG!"); \
+	unreachable(); \
 } while (0)
 #endif
 
Signature · 1 line
2.0.1