Skip to contentSkip to conversation

asm-generic: bug: unify hints for BUG_ON()

PATCH Superseded Igor Stoppa 2 participants 3 messages Sep 8, 2018 – Sep 10, 2018 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 asm-generic: bug: unify hints for BUG_ON()

If BUG_ON() is used instead of BUG(), it means that probably the preferred outcome is to not BUG(), therefore the condition tested should be unlikely().

However, when CONFIG_PROFILE_ANNOTATED_BRANCHES is enabled, the hint is disabled, to avoid generating false-positive warnings caused by -Wmaybe-uninitialized.

---
 include/asm-generic/bug.h | 8 ++++++++
 1 file changed, 8 insertions(+)
include/asm-generic/bug.h +8 -0
index 20561a60db9c..b91273c36baf 100644
@@ -58,8 +58,12 @@ struct bug_entry {
 #endif
 
 #ifndef HAVE_ARCH_BUG_ON
+#ifdef CONFIG_PROFILE_ANNOTATED_BRANCHES
+#define BUG_ON(condition) do { if (condition) BUG(); } while (0)
+#else
 #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
 #endif
+#endif
 
 #ifdef __WARN_FLAGS
 #define __WARN_TAINT(taint)		__WARN_FLAGS(BUGFLAG_TAINT(taint))
@@ -183,7 +187,11 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
 #endif
 
 #ifndef HAVE_ARCH_BUG_ON
+#ifdef CONFIG_PROFILE_ANNOTATED_BRANCHES
 #define BUG_ON(condition) do { if (condition) BUG(); } while (0)
+#else
+#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
+#endif
 #endif
 
 #ifndef HAVE_ARCH_WARN_ON
Signature · 1 line
2.17.1
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 9 lines · Igor Stoppa

If BUG_ON() is used instead of BUG(), it means that probably the preferred outcome is to not BUG(), therefore the condition tested should be unlikely().

However, when CONFIG_PROFILE_ANNOTATED_BRANCHES is enabled, the hint is disabled, to avoid generating false-positive warnings caused by -Wmaybe-uninitialized.

Quoted 5 lines

---

I assume this will be included in a longer patch series rather than going through
my asm-generic tree, right?

Arnd

#2 lore raw
Quoted 5 lines · Arnd Bergmann

I assume this will be included in a longer patch series rather than going through
my asm-generic tree, right?

sadly, no: this patch is just for the asm-generic tree
I tried with the longer patch series, but it didn't work out
I'm now submitting individual patches to their respective mailing lists and maintainers. It requires more churning, but at least some patches are going through.

--
thanks, igor