From patchwork Wed Dec 7 01:29:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9463719 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C9BB26022E for ; Wed, 7 Dec 2016 01:30:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7E96284FA for ; Wed, 7 Dec 2016 01:30:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8DD0284FC; Wed, 7 Dec 2016 01:30:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 049D6284FA for ; Wed, 7 Dec 2016 01:30:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752103AbcLGBab (ORCPT ); Tue, 6 Dec 2016 20:30:31 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:4637 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751786AbcLGBaa (ORCPT ); Tue, 6 Dec 2016 20:30:30 -0500 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="1007516" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 07 Dec 2016 09:30:08 +0800 Received: from localhost.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 09CB041B4BDA; Wed, 7 Dec 2016 09:30:03 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, Goldwyn Rodrigues Subject: [PATCH] btrfs-progs: Fix disable backtrace assert error Date: Wed, 7 Dec 2016 09:29:44 +0800 Message-Id: <20161207012944.10545-1-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.10.2 MIME-Version: 1.0 X-yoursite-MailScanner-ID: 09CB041B4BDA.ACCC8 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Due to commit 00e769d04c2c83029d6c71(btrfs-progs: Correct value printed by assertions/BUG_ON/WARN_ON), which changed the assert_trace() parameter, the condition passed to assert/WARN_ON/BUG_ON are logical notted for backtrace enabled and disabled case. Such behavior makes us easier to pass value wrong, and in fact it did cause us to pass wrong condition for ASSERT(). Instead of passing different conditions for ASSERT/WARN_ON/BUG_ON() manually, this patch will use BUG_ON() to implement the resting ASSERT/WARN_ON/BUG(), so we don't need to pass 3 different conditions but only one. And to further info the review for the fact that the condition should be different, rename "assert_trace" to "bugon_trace", as unlike assert, we will only trigger the bug when condition is true. Also, move WARN_ON() out of the ifdef branch, as it's completely the same for both branches. Cc: Goldwyn Rodrigues Signed-off-by: Qu Wenruo --- kerncompat.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/kerncompat.h b/kerncompat.h index e374614..be77608 100644 --- a/kerncompat.h +++ b/kerncompat.h @@ -277,7 +277,7 @@ static inline long IS_ERR(const void *ptr) #define vfree(x) free(x) #ifndef BTRFS_DISABLE_BACKTRACE -static inline void assert_trace(const char *assertion, const char *filename, +static inline void bugon_trace(const char *assertion, const char *filename, const char *func, unsigned line, long val) { if (!val) @@ -287,17 +287,20 @@ static inline void assert_trace(const char *assertion, const char *filename, exit(1); } -#define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)(c)) -#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c)) -#define ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)!(c)) -#define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 1) +#define BUG_ON(c) bugon_trace(#c, __FILE__, __func__, __LINE__, (long)(c)) #else #define BUG_ON(c) assert(!(c)) -#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c)) -#define ASSERT(c) assert(!(c)) -#define BUG() assert(0) #endif +#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c)) +/* + * TODO: ASSERT() should be depercated. In case like ASSERT(ret == 0), it + * won't output any useful value for ret. + * Should be replaced by BUG_ON(ret); + */ +#define ASSERT(c) BUG_ON(!(c)) +#define BUG() BUG_ON(1) + #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );})