Skip to contentSkip to conversation

asm-generic: add unlikely to default BUG_ON(x)

PATCH In review Denis Efremov 3 participants 4 messages Aug 28, 2019 – Aug 30, 2019 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 asm-generic: add unlikely to default BUG_ON(x)

Add unlikely to default BUG_ON(x) in !CONFIG_BUG. It makes the define consistent with BUG_ON(x) in CONFIG_BUG.

---
 include/asm-generic/bug.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/asm-generic/bug.h +1 -1
index aa6c093d9ce9..7357a3c942a0 100644
@@ -185,7 +185,7 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
 #endif
 
 #ifndef HAVE_ARCH_BUG_ON
-#define BUG_ON(condition) do { if (condition) BUG(); } while (0)
+#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
 #endif
 
 #ifndef HAVE_ARCH_WARN_ON
Signature · 1 line
2.21.0
#1 lore raw

Maybe it will be better to move this define out of ifdef, i.e.:

#ifdef CONFIG_BUG
...
-#define BUG_ON()...
...
#else
...
-#define BUG_ON()...
...
#endif

+#define BUG_ON()...

I can prepare a patch if you think it worth it.

Thanks,
Denis

Quoted 24 lines · Denis Efremov

Add unlikely to default BUG_ON(x) in !CONFIG_BUG. It makes the define consistent with BUG_ON(x) in CONFIG_BUG.

---
 include/asm-generic/bug.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/asm-generic/bug.h +1 -1
index aa6c093d9ce9..7357a3c942a0 100644
@@ -185,7 +185,7 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
 #endif
 
 #ifndef HAVE_ARCH_BUG_ON
-#define BUG_ON(condition) do { if (condition) BUG(); } while (0)
+#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
 #endif
 
 #ifndef HAVE_ARCH_WARN_ON
maintainer
#2 lore raw
In reply to Denis Efremov
Quoted 7 lines · Denis Efremov

Add unlikely to default BUG_ON(x) in !CONFIG_BUG. It makes the define consistent with BUG_ON(x) in CONFIG_BUG.

This makes sense, I've applied it to the asm-generic tree for now.

Two concerns though:

- adding unlikely() can cause new (usually false-postive) compile time warnings to show up in random configurations, so we'll have to see what the build bots think

- Kees Cook has recently sent a series for asm/bug.h that was merged by Andrew Morton. If there are is a conflict with your patch, it may be better to merge both through the same tree, either linux-mm or asm-generic.

Arnd

Reviewed-by
#3 lore raw
Quoted 13 lines · Arnd Bergmann
Quoted 7 lines · Denis Efremov

Add unlikely to default BUG_ON(x) in !CONFIG_BUG. It makes the define consistent with BUG_ON(x) in CONFIG_BUG.

This makes sense, I've applied it to the asm-generic tree for now.

Two concerns though:

Quoted 7 lines

- adding unlikely() can cause new (usually false-postive) compile time warnings to show up in random configurations, so we'll have to see what the build bots think

- Kees Cook has recently sent a series for asm/bug.h that was merged by Andrew Morton. If there are is a conflict with your patch, it may be better to merge both through the same tree, either linux-mm or asm-generic.

FWIW, this patch looks sensible to me. :)

Signature · 1 line
Kees Cook