From patchwork Thu Jan 19 04:00:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9525151 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 58EA16020B for ; Thu, 19 Jan 2017 04:01:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3735F2818B for ; Thu, 19 Jan 2017 04:01:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 295E228650; Thu, 19 Jan 2017 04:01:11 +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 9A4D52861C for ; Thu, 19 Jan 2017 04:01:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752020AbdASEBI (ORCPT ); Wed, 18 Jan 2017 23:01:08 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:6982 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751656AbdASEBH (ORCPT ); Wed, 18 Jan 2017 23:01:07 -0500 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="14900427" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 19 Jan 2017 12:00:14 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 40D8747B0CB2; Thu, 19 Jan 2017 12:00:11 +0800 (CST) Received: from localhost.localdomain (10.167.226.34) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 19 Jan 2017 12:00:11 +0800 From: Qu Wenruo To: CC: , Goldwyn Rodrigues Subject: [PATCH v4] btrfs-progs: Fix disable backtrace assert error Date: Thu, 19 Jan 2017 12:00:03 +0800 Message-ID: <20170119040003.22773-1-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-Originating-IP: [10.167.226.34] X-yoursite-MailScanner-ID: 40D8747B0CB2.AE549 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 ASSERT() to implement the resting ASSERT/WARN_ON/BUG() for disable backtrace case, and use assert_trace() to implement ASSERT() and BUG_ON(), to allow them to print correct value. 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 --- v2: Keep ASSERT() outputing meaningful error string, use ASSERT() to implement BUG_ON() so only the abused BUG_ON() output is affected. Suggested by David. v3: Update commit message, since we use ASSERT() instead of BUG_ON() as main assert function now. v4: Make BUG_ON() to print correct condition. --- kerncompat.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/kerncompat.h b/kerncompat.h index 19ed3fc0..b4070dac 100644 --- a/kerncompat.h +++ b/kerncompat.h @@ -291,18 +291,16 @@ static inline void assert_trace(const char *assertion, const char *filename, abort(); 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) assert_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) +#define ASSERT(c) assert(c) +#define BUG_ON(c) ASSERT(!(c)) #endif +#define BUG() BUG_ON(1) +#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c)) + #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );})