From patchwork Thu Sep 16 04:32:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1528634 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=U/Va5RiM; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=MWGFatFs; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H942b4Zddz9sR4 for ; Thu, 16 Sep 2021 14:33:11 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=L61dW0S6cfpSXgO/fatqJsONyfjTgUcg3ycHgzIwqVs=; b=U/Va5RiMIqBGJ3 Nf2cdgtRj7IGwMUmtoFsM93GlnF77Dw6YY9suONrd9C4UuKt8kh4j9O/BdcYHiuILhdXcQD6tfWUd NJQV3uzYfpxjRT/6OQZ1MBtH8YX5YNPH7m+sNEiUKQ85+qBd/jO7ytPNaAr5OByjebHNeFuwmDjVO I+KRTgHYJl9lIftvQc7rfxB1GtlJ6ZIDJ+mqv71R19C4bkF+ryRPORQyBc7LEzLocNCNImKBJZvnT vj1yZzg8K9zKHHYxB3ZVvbD7yzPF0IZzAepKV8fMBxTwTKkxUBzbdMz3IH846E85ghWYjBSPBxSgK LsIjkz24cNNt5Uu0cZVg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mQj55-00AJD1-4k; Thu, 16 Sep 2021 04:33:03 +0000 Received: from mail-m964.mail.126.com ([123.126.96.4]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mQj51-00AJCH-9D for opensbi@lists.infradead.org; Thu, 16 Sep 2021 04:33:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=/3Ep4 7uE666NZUBq9taVZufKXjBA7/gAybSFwUlDQw8=; b=MWGFatFsKwht/3Z/SmWzX iA5zVBaQl4It5Yo83N2t2Nm2RTr/noQQLXtj+w+lvipH5aUVkyubj1XhcTpGjVGC GpOusi0EA9DH4j3uGhVFnVS2YFQyR+8iKi8jVDfEEhkTnoupiPB688KWkcCq+UdO folq4AOoXr2duWWDaI78tk= Received: from x390.lan (unknown [210.22.74.80]) by smtp9 (Coremail) with SMTP id NeRpCgBHfwf2yEJht_lgcQ--.35428S2; Thu, 16 Sep 2021 12:32:55 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: atish.patra@wdc.com, anup.patel@wdc.com, Xiang W Subject: [PATCH V4 1/2] lib: sbi: add some macros to detect BUG at runtime Date: Thu, 16 Sep 2021 12:32:49 +0800 Message-Id: <20210916043250.8656-1-wxjstz@126.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CM-TRANSID: NeRpCgBHfwf2yEJht_lgcQ--.35428S2 X-Coremail-Antispam: 1Uf129KBjvJXoWrtr18Ar18Jr45uFyDCF4xCrg_yoW8JF1DpF n5AFn8Gr4vvas3Kw13Aa42qF4rGw4kG3WDtFyxW3savan2yrsYkrZFgw4Yv34rWr4fKrW8 XFZ8tF45CF17Xr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07U1CJQUUUUU= X-Originating-IP: [210.22.74.80] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi5BgQOlpEBthi2gAAsu X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210915_213259_750511_13C83D6B X-CRM114-Status: UNSURE ( 6.70 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Three macros are added. One is called BUG, which is used to put in an unreachable branch. One is called BUG_ON, which is used to check bugs and assert conditions are opposite. One is called SBI_ASSERT [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [123.126.96.4 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Three macros are added. One is called BUG, which is used to put in an unreachable branch. One is called BUG_ON, which is used to check bugs and assert conditions are opposite. One is called SBI_ASSERT, used for assertion checking. Signed-off-by: Xiang W Reviewed-by: Anup Patel --- include/sbi/sbi_console.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/sbi/sbi_console.h b/include/sbi/sbi_console.h index e24ba5f..05d2f57 100644 --- a/include/sbi/sbi_console.h +++ b/include/sbi/sbi_console.h @@ -11,6 +11,8 @@ #define __SBI_CONSOLE_H__ #include +#include +#include struct sbi_console_device { /** Name of the console device */ @@ -51,4 +53,21 @@ struct sbi_scratch; int sbi_console_init(struct sbi_scratch *scratch); +#define BUG() do { \ + sbi_printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \ + sbi_hart_hang(); \ +} while (0) + +#define BUG_ON(cond) do { \ + if (cond) \ + BUG(); \ +} while (0) + +#define SBI_ASSERT(cond) do { \ + if (!(cond)) { \ + sbi_printf("ASSERT: %s:%d/%s(): Assertion `%s` failed.\n", __FILE__,__LINE__,__func__, #cond);\ + sbi_hart_hang(); \ + } \ +} while (0) + #endif