Messages in this thread Patch in this message | | | Date | Sat, 26 Dec 2009 19:47:22 +0100 | From | Sam Ravnborg <> | Subject | [PATCH] BUG(): CONFIG_BUG=n version of BUG() should be unreachable() |
| |
Previouss definition of BUG() as 'do {} while(0)' produced compilation warnings when BUG() was used in default branch of switch() statement (control reaches end of non-void function).
Example: unsigned long function() { switch() { case 1: return 1; case 2: return 2; default: BUG(); }
Using unreachable() fixes the problem.
Signed-off-by: Alexander Beregalov <a.beregalov@gmail.com> [sam: add "for(;;) ;" so code indeed does not return] Signed-off-by: Sam Ravnborg <sam@ravnborg.org> Cc: David Daney <ddaney@caviumnetworks.com> ---
The patch I had in mind was this. We introduce an endless loop and just to be sure we tell gcc that we never get past this. This also address the concerns rasied by David.
Arnd - this is asm-generic stuff. If you agree (and Alexander can confirm that it works for him) then I expect you to take it.
Sam
diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h index 18c435d..f540529 100644 --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -89,7 +89,12 @@ extern void warn_slowpath_null(const char *file, const int line); #else /* !CONFIG_BUG */ #ifndef HAVE_ARCH_BUG -#define BUG() do {} while(0) +/* We do not want to return from here */ +#define BUG() do { \ + for (;;) \ + /* endless loop*/; \ + unreachable(); \ +} while(0) #endif #ifndef HAVE_ARCH_BUG_ON
| |