Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753115AbZLZSsc (ORCPT ); Sat, 26 Dec 2009 13:48:32 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752593AbZLZSsb (ORCPT ); Sat, 26 Dec 2009 13:48:31 -0500 Received: from pfepb.post.tele.dk ([195.41.46.236]:36753 "EHLO pfepb.post.tele.dk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751237AbZLZSsa (ORCPT ); Sat, 26 Dec 2009 13:48:30 -0500 Date: Sat, 26 Dec 2009 19:47:22 +0100 From: Sam Ravnborg To: Alexander Beregalov Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, David Miller , dhowells@redhat.com Subject: [PATCH] BUG(): CONFIG_BUG=n version of BUG() should be unreachable() Message-ID: <20091226184722.GA25275@merkur.ravnborg.org> References: <1261531032-15225-1-git-send-email-a.beregalov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1261531032-15225-1-git-send-email-a.beregalov@gmail.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1615 Lines: 58 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 [sam: add "for(;;) ;" so code indeed does not return] Signed-off-by: Sam Ravnborg Cc: David Daney --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/