asm-generic: bug: add unlikely() to BUG_ON()
PATCH 1/1 asm-generic: bug: add unlikely() to BUG_ON()
Add a hint to the compiler.
If BUG_ON() is used instead of BUG(), it means that probably the preferred outcome is to not BUG().
The optimization is disabled, in case CONFIG_PROFILE_ANNOTATED_BRANCHES is turned on.
--- include/asm-generic/bug.h | 4 ++++ 1 file changed, 4 insertions(+)
include/asm-generic/bug.h +4 -0
@@ -183,7 +183,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
Arnd Bergmann
maintainerQuoted 7 lines · Igor Stoppa
Add a hint to the compiler.
IfBUG_ON()is used instead ofBUG(), it means that probably the preferred outcome is to notBUG().The optimization is disabled, in case
CONFIG_PROFILE_ANNOTATED_BRANCHESis turned on.
This sounds like a good idea, as this is one of the more likely causes of false-positive -Wmaybe-uninitialized warnings with CONFIG_PROFILE_ANNOTATED_BRANCHES
Could you add a comment about -Wmaybe-uninitialized next to the definition? Otherwise that is easily lost.
Also, I see that the file has two separate definitions of BUG_ON(), and the other one does have an unlikely() in it already. Can you change both to do the same thing with unlikely() or not unlikely()?
Arnd
Quoted 6 lines · Arnd Bergmann
Could you add a comment about -Wmaybe-uninitialized next to the definition? Otherwise that is easily lost.
Also, I see that the file has two separate definitions of
BUG_ON(), and the other one does have anunlikely()in it already. Can you change both to do the same thing withunlikely()or notunlikely()?
ack
--
igor