From patchwork Fri Jun 9 03:34:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1792755 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.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=HdziNoeB; 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=AWjciQQF; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QcmtR6GLrz20XF for ; Fri, 9 Jun 2023 13:35: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:References:In-Reply-To: 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: List-Owner; bh=HKdFBfL9G4RY139vhe5l/3LL83Dx+I52VssLyUHr2eQ=; b=HdziNoeBPDqlrk NiKuJcNFZSIk+g405mem/5THLhzZkgZMnW2CUlkxcekEsxj6pVa0J5nrtefQMntH0x4LU8G9pN91U 8V8FT50w0gHh9tdNB0MdVxxGTD64AkUv4XDg2olGTXGauMFhdEBa+SROZBsjwuGxZt/4ERArkeVS+ UI07MRRdxHYwjZ8JIeIZ578IXzUDahHCooDjRbmsBsZLT/1k9zv6WVR3O2iHsGxNDeZ5znIS9Klhy 3y8Rb3w1tt/oRF0ObASCn1AkMt6WXxZsrqbGW1l8hCpT0FXiRM11VjpFbfQWOSvmEeTE2XSvgnv6X e54xu8I7UwJqMEHWq5tg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Str-00BTFx-17; Fri, 09 Jun 2023 03:34:55 +0000 Received: from m126.mail.126.com ([220.181.12.26]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Stl-00BTCW-30 for opensbi@lists.infradead.org; Fri, 09 Jun 2023 03:34:53 +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=tnarT bfafF5JrA4KPr+YCRWarr88Ve/tEWdmt28HynU=; b=AWjciQQFkU0AE8Vvyo33D OKGSQN+gjMT89QoI2+rTm3rVm+KzHr15BPOFLoX0fX40B6w/KtFwzc6Xc4WSHomL KC0asoJ0NcARyie1vnvnW2kGFud/hejPeA1Cgcfibirqm1IZ3JTW6ghDE34Kg/YN WvE5W3bNLnSscCx6EiBJhQ= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g0-1 (Coremail) with SMTP id _____wB3omDKnYJkJuYMAA--.4380S3; Fri, 09 Jun 2023 11:34:36 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v5 01/14] lib: sbi: Fix missing contine in print Date: Fri, 9 Jun 2023 11:34:17 +0800 Message-Id: <20230609033430.84471-2-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609033430.84471-1-wxjstz@126.com> References: <20230609033430.84471-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wB3omDKnYJkJuYMAA--.4380S3 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJcTPDUUUU X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi1w2JOl53bXV4qwAAsL X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230608_203450_366605_BA6A8D59 X-CRM114-Status: UNSURE ( 5.78 ) 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: Missing continue after print %lu %ld %lx ... Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index 168dffd..1f0727c 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -370,6 +370,7 @@ static int print(char **out, u32 *o [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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 Missing continue after print %lu %ld %lx ... Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index 168dffd..1f0727c 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -370,6 +370,7 @@ static int print(char **out, u32 *out_len, const char *format, va_list args) va_arg(args, long), 10, 1, width, flags, '0'); } + continue; } if (*format == 'c') { /* char are converted to int then pushed on the stack */ From patchwork Fri Jun 9 03:34:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1792758 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.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=ZkRIqjZy; 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=Xv464O0O; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QcmvC2qMwz20WP for ; Fri, 9 Jun 2023 13:35:51 +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:References:In-Reply-To: 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: List-Owner; bh=dkMbknnOwpWN4LkQxnxnxvRfTuZv6B496m0JZlRZcsA=; b=ZkRIqjZyUUpurp fE7xoBQgPqDT9Yqf/btO7mi6ivldhmaTUeNYNUKzY0v23R81K0/fUpiat1fg/S9T8VBtme1CWyIy3 qcM5F0F3gwk4D2hbp3TwHWqOQ7m5VnkSZ/T1CYeC832bg6iYCvXjM8FK4wb3E9creq+9EKP6thBf2 /3orfaqi/CFkPbqfap9n7h6k8aLMBwiZ1EsthJ4/o+IE4TEm7w7/82h2msxepTJ3SAkN5urmAkYYL 23qVmcwy4t9YkJPrJVoTh51LWrqaR1OQTg/TLx7GjCgZ8IabQPuBtXIFT5rjfoSOQeOScTxVrzMoX GP7KZ25W7zTTu8/Up++g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Sua-00BTgM-13; Fri, 09 Jun 2023 03:35:40 +0000 Received: from m126.mail.126.com ([220.181.12.27]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7SuW-00BTcl-25 for opensbi@lists.infradead.org; Fri, 09 Jun 2023 03:35:38 +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=FvZNE Y/Hl9kWwTyVHa+sWc2WQCeXkXhgLiIIfoEaJjc=; b=Xv464O0OGMUEKgRo7uB2p c3uUFyhS9imceCsCcgVPWnjGVQqkyFtI3BxysPIsQc8ytwsNyb9HQ0uYuQcjKdWM dKzwYo2pt50NWXGPe7q0Fz/OHPxXoHIBtd1qobygtNiOV9hlDAaQ3qRjKJl7QO/x 19knZPaS+VFHdOMel9V338= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g0-1 (Coremail) with SMTP id _____wB3omDKnYJkJuYMAA--.4380S4; Fri, 09 Jun 2023 11:34:36 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v5 02/14] lib: sbi: Fix how print gets flags Date: Fri, 9 Jun 2023 11:34:18 +0800 Message-Id: <20230609033430.84471-3-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609033430.84471-1-wxjstz@126.com> References: <20230609033430.84471-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wB3omDKnYJkJuYMAA--.4380S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Aw13Cry3tw4DuFWrKFWxJFb_yoW8XF4rpF n5CF9xtF1Fyrn3G3y3Jw4xCFWFy395Gr1jvrZxJw4rWFy5CryFkrykXFyFyrZrGry7Ar15 t3WrJF1jqFWjq3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRyUDJUUUUU= X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbiJg2JOlpD8z50DgAAs2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230608_203537_025121_8E50F5AC X-CRM114-Status: UNSURE ( 8.16 ) 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: The flags for print should be able to appear in any order. The previous code required the order to be fixed. Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 33 +++++++++++++++++++++ 1 file changed, 21 insertions(+), 12 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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 The flags for print should be able to appear in any order. The previous code required the order to be fixed. Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index 1f0727c..97ee328 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -236,6 +236,7 @@ static int printi(char **out, u32 *out_len, long long i, int b, int sg, static int print(char **out, u32 *out_len, const char *format, va_list args) { + bool flags_done; int width, flags, pc = 0; char scr[2], *tout; bool use_tbuf = (!out) ? true : false; @@ -262,25 +263,33 @@ static int print(char **out, u32 *out_len, const char *format, va_list args) if (*format == '%') { ++format; - width = flags = 0; if (*format == '\0') break; if (*format == '%') goto literal; /* Get flags */ - if (*format == '-') { - ++format; - flags = PAD_RIGHT; - } - if (*format == '#') { - ++format; - flags |= PAD_ALTERNATE; - } - while (*format == '0') { - ++format; - flags |= PAD_ZERO; + flags = 0; + flags_done = false; + while (!flags_done) { + switch (*format) { + case '-': + flags |= PAD_RIGHT; + break; + case '#': + flags |= PAD_ALTERNATE; + break; + case '0': + flags |= PAD_ZERO; + break; + default: + flags_done = true; + break; + } + if (!flags_done) + ++format; } /* Get width */ + width = 0; for (; *format >= '0' && *format <= '9'; ++format) { width *= 10; width += *format - '0'; From patchwork Fri Jun 9 03:34:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1792749 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.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=QMnTmUbe; 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=X9u6fRG1; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QcmtR6z3lz214H for ; Fri, 9 Jun 2023 13:35: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:References:In-Reply-To: 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: List-Owner; bh=Vh49twtkQrDLahZfvEzJ2hMPdPQCJ4l7Pau26s1FuCg=; b=QMnTmUbeEN2OQA LuN5lkh4GjnIu4stC2MqDqNLS1DDjbqXHV8DRlYI4tMBgoRcHRKDs+OKO/oo7UNZKHvUFgsKS/1UD sZFuXPRFVSza62+s46K3ZGo+hCa46SzkShGm+bVnVzEt3ixgJ5/TnvlslDtUnWPzkVgSoEVLjZbOA B4G4QfCzV6adgCQXTbWcsTCPKlobxs2qWQyLC2Q67VKYK9CetYr41r7lxU/RrcARXbImJeSCN/IZm o6U7t2/XWy+Gvg5hECdtzEOHTK8Ype0TDYl1Ftbyy01p+3Kb0m97z7BknNlPby9eOvKIn0io/DZjS 00mCgQeNPMi4stOr26/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Stp-00BTF3-2V; Fri, 09 Jun 2023 03:34:53 +0000 Received: from m126.mail.126.com ([220.181.12.26]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Stl-00BTCr-30 for opensbi@lists.infradead.org; Fri, 09 Jun 2023 03:34:52 +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=xcdBY QbpjDfTuptgCLo/ftYrwO5MkTJWts0S0B1dP9o=; b=X9u6fRG1rToyqwMWONKwx fp+hQzB55Jl9+coRsXxThkw+Mw3V5xVe0Kg0se/m9Q8cRlpXptl5WJv/jtD+hy0t 9841ir+u7ujzdMcRPvgSEw+8jueuFhTyXkuHN0sWr2MUWZ0HlKWMH1nh7Q7rgBtv e9H3ncm9qn27IDQqHaQMk8= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g0-1 (Coremail) with SMTP id _____wB3omDKnYJkJuYMAA--.4380S5; Fri, 09 Jun 2023 11:34:37 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v5 03/14] lib: sbi: print not fill '0' when left-aligned Date: Fri, 9 Jun 2023 11:34:19 +0800 Message-Id: <20230609033430.84471-4-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609033430.84471-1-wxjstz@126.com> References: <20230609033430.84471-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wB3omDKnYJkJuYMAA--.4380S5 X-Coremail-Antispam: 1Uf129KBjvdXoWrJFW3uw1rXr4ktF4rGw4kWFg_yoWxWFc_A3 yxA340krZ8Ja9I9w1DtF48Xr4Yq3409rnrW3W7KrZ8A3yfZr45Way0yr9IgF98ZF43uryI krWUJrn8urn0gjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_-Vy7UUUUU== X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi5A2JOlpEGBEaPwAAso X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230608_203450_360527_A10E05EE X-CRM114-Status: UNSURE ( 7.19 ) 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: Left alignment and padding '0' should not exist at the same time, this patch is not padded with 0 when left aligned. Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 2 ++ 1 file changed, 2 insertions(+) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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 Left alignment and padding '0' should not exist at the same time, this patch is not padded with 0 when left aligned. Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index 97ee328..b18f9c5 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -288,6 +288,8 @@ static int print(char **out, u32 *out_len, const char *format, va_list args) if (!flags_done) ++format; } + if (flags & PAD_RIGHT) + flags &= ~PAD_ZERO; /* Get width */ width = 0; for (; *format >= '0' && *format <= '9'; ++format) { From patchwork Fri Jun 9 03:34:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1792750 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.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=OwJlmAaX; 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=AH9RiMco; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QcmtR6TWJz20fS for ; Fri, 9 Jun 2023 13:35: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:References:In-Reply-To: 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: List-Owner; bh=f3UQJdYyj0o6yNaVP4YpJnOAlhqxhIdhy7kio2dgiA0=; b=OwJlmAaXVQnw4t 2/Pcqp6K4gZCI1bQqyNElPbnehBHxJJG2sO1c/mgkfqUoWcyxefocEMj52t/mCdlzD74d51BJM+XT 51ZKBpSmZMcJiWtqgm3KxLvxy8AtcEVdnSUwZdJfR+YkF7fL2id7UFAdiAgXHZmMU+RZpeVjF5ydS ZVasqWhlIU+vJF+CPiWataocfL+yDqiB7wdGpYaxQMwDB0gJ7tXjlmGo8HqQOY0lHUBxqwseuj+Ii qPL6+GON1eYL/1owMfaFv2enSwdjoVDtta6pC06UIaNvA+hlEBcUpqP4vjl/KMFve0712Z90rwB5J z3fX212YrbUZyX53G1sw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Str-00BTGF-2d; Fri, 09 Jun 2023 03:34:55 +0000 Received: from m126.mail.126.com ([220.181.12.26]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Stl-00BTCk-32 for opensbi@lists.infradead.org; Fri, 09 Jun 2023 03:34:53 +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=5BPnc iIPCYzZLQ7Ktm9mmWpOgwz5sHUXINQyG3kWYGU=; b=AH9RiMcoGBoRvcq6zfNll s7wuZz2+YGGgHDHUMLMXmHraXoem8hIuuouOyw6AEFoGNdODK+KyALJz7zSNJlBD mBpw4w3SLnobkcAo+f84fttFgJbZfIR16nd0vufBvFmf7mWa5cdZJwfzcGylcKNs eCUnN76LaoVk4LmS1ZIoaI= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g0-1 (Coremail) with SMTP id _____wB3omDKnYJkJuYMAA--.4380S6; Fri, 09 Jun 2023 11:34:37 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v5 04/14] lib: sbi: Add '+' flags for print Date: Fri, 9 Jun 2023 11:34:20 +0800 Message-Id: <20230609033430.84471-5-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609033430.84471-1-wxjstz@126.com> References: <20230609033430.84471-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wB3omDKnYJkJuYMAA--.4380S6 X-Coremail-Antispam: 1Uf129KBjvJXoW7Kr1ruw15ur4UXFWUZw18Zrb_yoW8Wr4fpF 4fKFsIqrW0qF93WrW5trn8C3WYy34FkF42yrWag3y8ZF1DCa1rtr4UXw15try3u3s5AF45 Aas5ZF4jga1DXw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zMpBTUUUUUU= X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi1w2JOl53bXV4qwABsK X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230608_203450_364785_FD95752A X-CRM114-Status: GOOD ( 10.00 ) 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: Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index b18f9c5..a616316 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -120,6 +120,7 @@ unsigned long sbi_ngets(char *str, [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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 Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index b18f9c5..a616316 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -120,6 +120,7 @@ unsigned long sbi_ngets(char *str, unsigned long len) #define PAD_RIGHT 1 #define PAD_ZERO 2 #define PAD_ALTERNATE 4 +#define PAD_SIGN 8 #define PRINT_BUF_LEN 64 #define va_start(v, l) __builtin_va_start((v), l) @@ -186,15 +187,18 @@ static int prints(char **out, u32 *out_len, const char *string, int width, static int printi(char **out, u32 *out_len, long long i, int b, int sg, int width, int flags, int letbase) { - char print_buf[PRINT_BUF_LEN]; - char *s; - int neg = 0, pc = 0; + char *s, sign, print_buf[PRINT_BUF_LEN]; + int pc = 0; u64 t; unsigned long long u = i; - if (sg && b == 10 && i < 0) { - neg = 1; - u = -i; + if (sg && b == 10) { + if ((flags & PAD_SIGN) && i > 0) + sign = '+'; + if (i < 0) { + sign = '-'; + u = -i; + } } s = print_buf + PRINT_BUF_LEN - 1; @@ -221,13 +225,13 @@ static int printi(char **out, u32 *out_len, long long i, int b, int sg, *--s = '0'; } - if (neg) { + if (sign) { if (width && (flags & PAD_ZERO)) { - printc(out, out_len, '-'); + printc(out, out_len, sign); ++pc; --width; } else { - *--s = '-'; + *--s = sign; } } @@ -275,6 +279,9 @@ static int print(char **out, u32 *out_len, const char *format, va_list args) case '-': flags |= PAD_RIGHT; break; + case '+': + flags |= PAD_SIGN; + break; case '#': flags |= PAD_ALTERNATE; break; From patchwork Fri Jun 9 03:34:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1792747 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.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=ITBQTjgb; 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=j3SbF7Gt; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QcmtR6txYz20fn for ; Fri, 9 Jun 2023 13:35: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:References:In-Reply-To: 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: List-Owner; bh=Fq5IdaAPxgLGTtrauYlOmkIDE5bhWmOWrT3Zhiz4hQ0=; b=ITBQTjgbxF9iTC ygwAXW+GbWo8xmLCfPR/8ow0/4ROIJ2G+DzyRPDsYXgg9CPeS/LsEPSyIfE2ChiYSICOVW17i6UNI fTW2N+MoUItS8frXqc9zlzvFOSxqZYd/cma0LNhUEQTSbXu0OM+6SJIH6kUxy7T3a69CZexTnXHny 7QLQhbAQJu2aNGUQx0U9ksLxWfS0Qt+XNT1e9vSZcZMIkh/6ahMHRpQjsoUkhQNpEIZ+tLs3Wywyw 7hxEZc4cppjnHjSPKL9ifdrd3khHBcGJXdI/I31cHbpFy9In2jnsKmOPDuEvnAv6v+upHzONLNoNb aFiDxwyL+sOLEeIAYh3g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Sts-00BTGU-0q; Fri, 09 Jun 2023 03:34:56 +0000 Received: from m126.mail.126.com ([220.181.12.29]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Stm-00BTCi-0K for opensbi@lists.infradead.org; Fri, 09 Jun 2023 03:34:53 +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=CPMdH NeuU3gxSUcHxAmZN2CphHXKml5L/M3Lynsck5A=; b=j3SbF7GtCEHS+NnX46Zyj eFt4cIfez3Ksn1zXaz3LcwZDQwELxWKlC7s617KUvd88o4D8wiDfor9MpkXZxITx SLfKPi1YSPEY86n6ECc9oyXMaORyirFsD+5MoYhYb8CsBfN8AVRaH9bfbnPLJjv7 hSxNW2bHbps6b6Jx6An6Ao= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g0-1 (Coremail) with SMTP id _____wB3omDKnYJkJuYMAA--.4380S7; Fri, 09 Jun 2023 11:34:37 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v5 05/14] lib: sbi: Add ' ' '\'' flags for print Date: Fri, 9 Jun 2023 11:34:21 +0800 Message-Id: <20230609033430.84471-6-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609033430.84471-1-wxjstz@126.com> References: <20230609033430.84471-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wB3omDKnYJkJuYMAA--.4380S7 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvj4iNtxfDUUUU X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi1w6JOl53bXV4tgAAsV X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230608_203450_470914_298959B0 X-CRM114-Status: UNSURE ( 5.47 ) 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: Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index a616316..7f32f81 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -288,6 +288,10 @@ static int print(char **out, u32 * [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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 Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index a616316..7f32f81 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -288,6 +288,10 @@ static int print(char **out, u32 *out_len, const char *format, va_list args) case '0': flags |= PAD_ZERO; break; + case ' ': + case '\'': + /* Ignored flags, do nothing */ + break; default: flags_done = true; break; From patchwork Fri Jun 9 03:34:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1792754 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.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=CvjZxnLx; 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=dKWbFcC3; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QcmtR3z5Sz20WP for ; Fri, 9 Jun 2023 13:35: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:References:In-Reply-To: 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: List-Owner; bh=tm6aeJZFTDn3137rT3qq9ScjCO8MKJXgr+wV5p4pStg=; b=CvjZxnLxOq4Ggo n+Fhey49X5ee/xVIe40115DDnSrt1L25RaGX3jepckJw+M9l+p6bkoaH1YoFSHYfF+GPFtbUZbGLQ NcoqxPpNGgXQkMHRftSQDLrjnKauMb6SlICdBeiRdJxvb9FeoK0ipquNvdBx2YTkOsn6vZJ4LPMMi jPC//8n3f5olO/5Rg7KHlfQvZt7/HlT9NimhU1dbmMhfAtq1G4F9whaHSIWkf5al1YyN0vpqGee9c spmrrWnKGX/krmGO7ucg/uD/JLx/6Qj9DMxQWpoExcADM1EYGO2TdneeZ6MUu4NMcX4UpGXd7V6ow SS52cRalgm4ZmV3trKBw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Stv-00BTIM-07; Fri, 09 Jun 2023 03:34:59 +0000 Received: from m126.mail.126.com ([220.181.12.37]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Sto-00BTCe-0J for opensbi@lists.infradead.org; Fri, 09 Jun 2023 03:34:55 +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=VLZDP T/ZDnk7td1XtcDoFYN6dNBFdEoJyoIXBeUA6ts=; b=dKWbFcC3N65GIPBVGBu/q vJk+griVv2h+inEQ8cTKG+b6KKRXtG/9rnb+pbPriFuE9AJquj0ge82X5zUqyZPt taCb0u/dcOC6W8kOsmSPnpoYhfJ0OCBy/8WyST9IobuwOLyFSOhfVGygPkynCeBq EBJwLuhzD9TlwzF9AhATiM= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g0-1 (Coremail) with SMTP id _____wB3omDKnYJkJuYMAA--.4380S8; Fri, 09 Jun 2023 11:34:37 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v5 06/14] lib: sbi: implifying the parameters of printi Date: Fri, 9 Jun 2023 11:34:22 +0800 Message-Id: <20230609033430.84471-7-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609033430.84471-1-wxjstz@126.com> References: <20230609033430.84471-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wB3omDKnYJkJuYMAA--.4380S8 X-Coremail-Antispam: 1Uf129KBjvJXoWxXw15AFWkCw1fWw18Cr47XFb_yoWrZFyxp3 WYkrsIqa1Sy347JrWFqay2qFZ8Z3s3JF1j9rsrXrWY9F45CFWFqFy5Gr1YyF1kGrZ8ZFWa kas8Jr4Ykw4jqaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRY0PhUUUUU= X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbiJg6JOlpD8z50FQAAsu X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230608_203452_495620_00FF50B0 X-CRM114-Status: GOOD ( 10.47 ) 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: The information of sg/b/letbase can be obtained by the type character, simplifying the parameter by passing the type directly. Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 126 ++++++++++++++++ 1 file changed, 49 insertions(+), 77 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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 The information of sg/b/letbase can be obtained by the type character, simplifying the parameter by passing the type directly. Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 126 ++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 77 deletions(-) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index 7f32f81..a9a2ed6 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -184,15 +184,26 @@ static int prints(char **out, u32 *out_len, const char *string, int width, return pc; } -static int printi(char **out, u32 *out_len, long long i, int b, int sg, - int width, int flags, int letbase) +static int printi(char **out, u32 *out_len, long long i, + int width, int flags, int type) { - char *s, sign, print_buf[PRINT_BUF_LEN]; int pc = 0; - u64 t; - unsigned long long u = i; + char *s, sign, letbase, print_buf[PRINT_BUF_LEN]; + unsigned long long u, b, t; + + b = 10; + letbase = 'a'; + if (type == 'o') + b = 8; + else if (type == 'x' || type == 'X' || type == 'p' || type == 'P') { + b = 16; + letbase &= ~0x20; + letbase |= type & 0x20; + } - if (sg && b == 10) { + u = i; + sign = 0; + if (type == 'i' || type == 'd') { if ((flags & PAD_SIGN) && i > 0) sign = '+'; if (i < 0) { @@ -242,9 +253,8 @@ static int print(char **out, u32 *out_len, const char *format, va_list args) { bool flags_done; int width, flags, pc = 0; - char scr[2], *tout; + char type, scr[2], *tout; bool use_tbuf = (!out) ? true : false; - unsigned long long tmp; /* * The console_tbuf is protected by console_out_lock and @@ -315,83 +325,45 @@ static int print(char **out, u32 *out_len, const char *format, va_list args) } if ((*format == 'd') || (*format == 'i')) { pc += printi(out, out_len, va_arg(args, int), - 10, 1, width, flags, '0'); - continue; - } - if (*format == 'x') { - pc += printi(out, out_len, - va_arg(args, unsigned int), 16, 0, - width, flags, 'a'); - continue; - } - if (*format == 'X') { - pc += printi(out, out_len, - va_arg(args, unsigned int), 16, 0, - width, flags, 'A'); + width, flags, *format); continue; } - if (*format == 'u') { - pc += printi(out, out_len, - va_arg(args, unsigned int), 10, 0, - width, flags, 'a'); + if ((*format == 'u') || (*format == 'x') || (*format == 'X')) { + pc += printi(out, out_len, va_arg(args, unsigned int), + width, flags, *format); continue; } - if (*format == 'p') { - pc += printi(out, out_len, - va_arg(args, unsigned long), 16, 0, - width, flags, 'a'); + if ((*format == 'p') || (*format == 'P')) { + pc += printi(out, out_len, (uintptr_t)va_arg(args, void*), + width, flags, *format); continue; } - if (*format == 'P') { - pc += printi(out, out_len, - va_arg(args, unsigned long), 16, 0, - width, flags, 'A'); - continue; - } - if (*format == 'l' && *(format + 1) == 'l') { - tmp = va_arg(args, unsigned long long); - if (*(format + 2) == 'u') { - format += 2; - pc += printi(out, out_len, tmp, 10, 0, - width, flags, 'a'); - } else if (*(format + 2) == 'x') { - format += 2; - pc += printi(out, out_len, tmp, 16, 0, - width, flags, 'a'); - } else if (*(format + 2) == 'X') { - format += 2; - pc += printi(out, out_len, tmp, 16, 0, - width, flags, 'A'); - } else { - format += 1; - pc += printi(out, out_len, tmp, 10, 1, - width, flags, '0'); + if (*format == 'l') { + type = 'i'; + if (format[1] == 'l') { + ++format; + if ((format[1] == 'u') + || (format[1] == 'd') || (format[1] == 'i') + || (format[1] == 'x') || (format[1] == 'X')) { + ++format; + type = *format; + } + pc += printi(out, out_len, va_arg(args, long long), + width, flags, type); + continue; } - continue; - } else if (*format == 'l') { - if (*(format + 1) == 'u') { - format += 1; - pc += printi( - out, out_len, - va_arg(args, unsigned long), 10, - 0, width, flags, 'a'); - } else if (*(format + 1) == 'x') { - format += 1; - pc += printi( - out, out_len, - va_arg(args, unsigned long), 16, - 0, width, flags, 'a'); - } else if (*(format + 1) == 'X') { - format += 1; - pc += printi( - out, out_len, - va_arg(args, unsigned long), 16, - 0, width, flags, 'A'); - } else { - pc += printi(out, out_len, - va_arg(args, long), 10, 1, - width, flags, '0'); + if ((format[1] == 'u') + || (format[1] == 'd') || (format[1] == 'i') + || (format[1] == 'x') || (format[1] == 'X')) { + ++format; + type = *format; } + if ((type == 'd') || (type == 'i')) + pc += printi(out, out_len, va_arg(args, long), + width, flags, type); + else + pc += printi(out, out_len, va_arg(args, unsigned long), + width, flags, type); continue; } if (*format == 'c') { From patchwork Fri Jun 9 03:34:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1792748 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.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=xReZWjS7; 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=ZdfCNvBA; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QcmtR6r2jz20fV for ; Fri, 9 Jun 2023 13:35: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:References:In-Reply-To: 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: List-Owner; bh=/+cwdfAohydSWJNbiWmSMGy9jRCuhIRtg4AYudM35WI=; b=xReZWjS7fDJP9N RAqOgAxRJ4hMsdSi8wJ+1ixKhxJ4cmJh3vlfgSxLuaZ73ulc9e0TNBi+URDC0ZuiMysgLrWJ2nrak 5riTCwZ2xN2QvwsNyy+Z1kYrqPhYM1BcuRv/3GNJX+63TtAgDFo6eGxUwjoJKZ+7ZUQROWKL4LDww 2BPbNJPZy6bfUEbGcQ1nTGVrV5cvc7y22x8bXWt/RUURi1q/so9/XxXMP2SmEddnGvU3Ofss8B9wr lhw1GV7rhliuIoNE1hsfTf98/faCpi7ylXt1crDW5UEe9IyfLjdcUc6SqR7+djV5BVcc31U+18W4g 0ps9Gsw6GF9gIityiAEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Stu-00BTHp-1q; Fri, 09 Jun 2023 03:34:58 +0000 Received: from m126.mail.126.com ([220.181.12.36]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Stp-00BTCs-1k for opensbi@lists.infradead.org; Fri, 09 Jun 2023 03:34:55 +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=S0N09 XpQ5SPDJMkwUS4GHGtQtsPC7APlOuuATrbRx2I=; b=ZdfCNvBAXTfvs2fMmo+ne bCtEqmhJ3nJI3oU6pgcjtpav6C4Q+MSCI1MjfLLTXz3V+/+oNcUbeQCofAr113JG mwWzyrSrpfSo6mlTUQazCrwWwnkMs2eMkHlgwgg+eXC96UeCNCgMxx07EmP5NIwl Pk55naG7fsg1oFMXrNkVqE= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g0-1 (Coremail) with SMTP id _____wB3omDKnYJkJuYMAA--.4380S9; Fri, 09 Jun 2023 11:34:38 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v5 07/14] lib: sbi: print add 'o' type Date: Fri, 9 Jun 2023 11:34:23 +0800 Message-Id: <20230609033430.84471-8-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609033430.84471-1-wxjstz@126.com> References: <20230609033430.84471-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wB3omDKnYJkJuYMAA--.4380S9 X-Coremail-Antispam: 1Uf129KBjvJXoW7tF1DKFy8JFyUCFW7JryDtrb_yoW8JFWxpw n0yryDt3WSyry3Jr9Iq3y8JFy5Z3s8Jr1j9rZrGFW5WFn3CFykGr1rGryYyrn7Krn3JFW7 Cw1rJ3W5tFW2gFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zt2NixUUUUU= X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi5A6JOlpEGBEaSAAAsc X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230608_203453_992314_8B3766F1 X-CRM114-Status: UNSURE ( 6.10 ) 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: Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index a9a2ed6..047c51e 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -328,7 +328,8 @@ static int print(char **out, u32 *o [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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 Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index a9a2ed6..047c51e 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -328,7 +328,8 @@ static int print(char **out, u32 *out_len, const char *format, va_list args) width, flags, *format); continue; } - if ((*format == 'u') || (*format == 'x') || (*format == 'X')) { + if ((*format == 'u') || (*format == 'o') + || (*format == 'x') || (*format == 'X')) { pc += printi(out, out_len, va_arg(args, unsigned int), width, flags, *format); continue; @@ -342,7 +343,7 @@ static int print(char **out, u32 *out_len, const char *format, va_list args) type = 'i'; if (format[1] == 'l') { ++format; - if ((format[1] == 'u') + if ((format[1] == 'u') || (format[1] == 'o') || (format[1] == 'd') || (format[1] == 'i') || (format[1] == 'x') || (format[1] == 'X')) { ++format; @@ -352,7 +353,7 @@ static int print(char **out, u32 *out_len, const char *format, va_list args) width, flags, type); continue; } - if ((format[1] == 'u') + if ((format[1] == 'u') || (format[1] == 'o') || (format[1] == 'd') || (format[1] == 'i') || (format[1] == 'x') || (format[1] == 'X')) { ++format; From patchwork Fri Jun 9 03:34:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1792753 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.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=KTirLCrs; 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=lASJeAX6; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QcmtR718Kz214N for ; Fri, 9 Jun 2023 13:35: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:References:In-Reply-To: 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: List-Owner; bh=OEOGOt2oxmlVP+GhqGwiGOWdr9da6YPhjv/MHZJoH8s=; b=KTirLCrsJIOgxt WQu0GYQ8pfsvpfVnvj8rxnPS1JgWlhdsxzsvslkTQGOehQI9+2fM4tSw7I9tQwPGsmBJoPVBiw7P5 1siWevXS1tesLmMSVyKZSlw7qeIbVU9fF9k2PMvJeq4S3qzSQtv887yE06tR6XJFbjotfexj2dm7r qV6ORRhl6dyrTa4oiTmTdw7RwTrMTNU2JJwG/Adm3nBt2ytEbY6ibDfEatF4AEtaoI5WY5Pod1C9D pyehjyjwGSCf8IlcKhm/zuAR9WIZ85OHe9I75D1Woxull6VTB7fPUAKlmPu8+4Rxn4+vn6c/4x60H ZZvPuYjOEoVbAekBE23Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Stp-00BTEp-0o; Fri, 09 Jun 2023 03:34:53 +0000 Received: from m126.mail.126.com ([220.181.12.26]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Stl-00BTCU-31 for opensbi@lists.infradead.org; Fri, 09 Jun 2023 03:34:52 +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=YFkiQ +f3YjD1E48rlXlxkWlV4GEGI0MZJZVmWDK3d/0=; b=lASJeAX6VHhxruMLJB4+r Vu1S1B9wYhQIzcbIViYCuz+8Ai3/55mQzoqU5uqLS3wmB0Jv17kH2TZlRV45j7gO ozxSAIRp5zRnS6jiwjyI6O9UGnkKNKcS8V+fWMbnA9IZdxX7UMdCi7bBOZXmUj0V tcE8ON9GedR2r3OqPGSqbo= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g0-1 (Coremail) with SMTP id _____wB3omDKnYJkJuYMAA--.4380S10; Fri, 09 Jun 2023 11:34:38 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v5 08/14] lib: sbi: Fix printi Date: Fri, 9 Jun 2023 11:34:24 +0800 Message-Id: <20230609033430.84471-9-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609033430.84471-1-wxjstz@126.com> References: <20230609033430.84471-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wB3omDKnYJkJuYMAA--.4380S10 X-Coremail-Antispam: 1Uf129KBjvdXoWrKFy3AF15AFW5ury7tF4Dtwb_yoWkKFXEyF WkAay5Kws8JayUWa45trn0y3yUXr4jkwn7XayUtr43CryakrW7KryUtryDWa409FW2qFy0 vrW7Cr18Cr1YgjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRqeHK7UUUUU== X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi5A6JOlpEGBEaSAABsd X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230608_203450_361340_31956CC3 X-CRM114-Status: UNSURE ( 8.04 ) 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: Fix two bug: > printf("%#08x", 0x123); /* print 0000x123 */ > printf("%#x", 0); /* print 0x0 */ Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 36 +++++++++++++++++++++++ 1 file changed, 23 insertions(+), 13 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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 Fix two bug: > printf("%#08x", 0x123); /* print 0000x123 */ > printf("%#x", 0); /* print 0x0 */ Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index 047c51e..6f714f0 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -227,23 +227,33 @@ static int printi(char **out, u32 *out_len, long long i, } } - if (flags & PAD_ALTERNATE) { - if ((b == 16) && (letbase == 'A')) { - *--s = 'X'; - } else if ((b == 16) && (letbase == 'a')) { - *--s = 'x'; - } - *--s = '0'; - } - - if (sign) { - if (width && (flags & PAD_ZERO)) { + if (flags & PAD_ZERO) { + if (sign) { printc(out, out_len, sign); ++pc; --width; - } else { - *--s = sign; } + if (i && (flags & PAD_ALTERNATE)) { + if (b == 16 || b == 8) { + printc(out, out_len, '0'); + ++pc; + --width; + } + if (b == 16) { + printc(out, out_len, 'x' - 'a' + letbase); + ++pc; + --width; + } + } + } else { + if (i && (flags & PAD_ALTERNATE)) { + if (b == 16) + *--s = 'x' - 'a' + letbase; + if (b == 16 || b == 8) + *--s = '0'; + } + if (sign) + *--s = sign; } return pc + prints(out, out_len, s, width, flags); From patchwork Fri Jun 9 03:34:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1792752 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.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=Qzci2zwG; 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=k1goUviF; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QcmtR6p5sz20fT for ; Fri, 9 Jun 2023 13:35: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:References:In-Reply-To: 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: List-Owner; bh=TLwHrwomJQbvbXZm4guXLSo8Q7eQS39KZ4j7fgSSqlE=; b=Qzci2zwG2xb0eV 6HznGufoyviADGrUOR7Lht8QURmx5j8K3kVy0CuDxdfeU9JsHm/lU7qhjFRuWaQOtJdrFh8vpvhiq GutGY2XughM/XrghyUlk1iP10eeRki5DC6s70ouZmeBtEx3pGhfWn0Y2/YrIjo51yvtupvX0EeXtQ xCcwDsK6ck6z/qiJhizjApQU+RK5N0czUmYigP8hDCkDitsOGC9mEDSKkBXaAXd/+lh4uy3qaNgGa WmNWsFdtvqjVR1EXJEsPvOv+nqt3u7bhYOcdfJJTnpGj+rj5s6nM97ppJzTejDHB/UHquDDcsCJXU IhqB0dVeF9EhuQfylYDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Stu-00BTHX-0M; Fri, 09 Jun 2023 03:34:58 +0000 Received: from m126.mail.126.com ([220.181.12.29]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Stm-00BTD1-2m for opensbi@lists.infradead.org; Fri, 09 Jun 2023 03:34:54 +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=bytJR T2WrSH+LyziQSe+3ieIWMGZhVrdgWrQFYv4ip8=; b=k1goUviFYU3or/Ao0g5tp INS+S0DClReT/6+J3AiximvAIIqjOLszXhox/nSUm4QHwGLulg93jqP3nl/qlDcs /kiF7i/KsCXYofOtFKLdlgHxtS4lvpGV6BjNQkoLlMKP35lSFKvX/lqYSWGCBkgJ i2uyeoILrby1nd9PMLUrCY= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g0-1 (Coremail) with SMTP id _____wB3omDKnYJkJuYMAA--.4380S11; Fri, 09 Jun 2023 11:34:38 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v5 09/14] lib: sbi: Simplify prints Date: Fri, 9 Jun 2023 11:34:25 +0800 Message-Id: <20230609033430.84471-10-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609033430.84471-1-wxjstz@126.com> References: <20230609033430.84471-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wB3omDKnYJkJuYMAA--.4380S11 X-Coremail-Antispam: 1Uf129KBjvJXoW7WF4UCF4xZr4UJFWktFW5Jrb_yoW8Jw1Upa n3K3ZrJw4Fyas5Ary8twnFgF1Yy3WDCFW2yr9rXr18ZFWDZ3y8Jr4fJF1Fya47Jay8ZFy5 u3Z5uF4rXa1j9r7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zt2NixUUUUU= X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi5BOJOlpEGBEafAAAs1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230608_203451_238687_C38C2895 X-CRM114-Status: UNSURE ( 9.62 ) 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: When doing width = width - strlen(string) in prints there is no need to consider the case that witdh may be less than 0. This is because the code to do filling needs to be executed under the condition [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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 When doing width = width - strlen(string) in prints there is no need to consider the case that witdh may be less than 0. This is because the code to do filling needs to be executed under the condition that width > 0. Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index 6f714f0..824ff6e 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -151,24 +151,11 @@ static void printc(char **out, u32 *out_len, char ch) static int prints(char **out, u32 *out_len, const char *string, int width, int flags) { - int pc = 0; - char padchar = ' '; - - if (width > 0) { - int len = 0; - const char *ptr; - for (ptr = string; *ptr; ++ptr) - ++len; - if (len >= width) - width = 0; - else - width -= len; - if (flags & PAD_ZERO) - padchar = '0'; - } + int pc = 0; + width -= sbi_strlen(string); if (!(flags & PAD_RIGHT)) { for (; width > 0; --width) { - printc(out, out_len, padchar); + printc(out, out_len, flags & PAD_ZERO ? '0' : ' '); ++pc; } } @@ -177,7 +164,7 @@ static int prints(char **out, u32 *out_len, const char *string, int width, ++pc; } for (; width > 0; --width) { - printc(out, out_len, padchar); + printc(out, out_len, ' '); ++pc; } From patchwork Fri Jun 9 03:34:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1792751 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.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=pt86evmA; 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=KY8KuZ+c; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QcmtR446Mz20Wb for ; Fri, 9 Jun 2023 13:35: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:References:In-Reply-To: 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: List-Owner; bh=JHRDZhOddYYa1/lWrMxIxPlO6hm4oeCWos3uZ3x3eHM=; b=pt86evmA03zJ4X nKFnLwQMgYt9ROZr+EF1fHHxDcImmEUeE8231nUGFIe5hcEVHe/V0cgm99iU15lOnedyywi/vkqCr E+xM6AOoTnywQwLhiuKmNl2rRZF3dLHcSZ4eXd7FuvHP52zikbHpSmUMQ7KVsjnA9d9VFv4R5/qSN mkojNjJE2rZj9zDu4hGI4qh7vJiqx0Cy1TeoUVcn5qXt8ivXiv4w5iK1kHGXzPcfUob+Ica5orB5G 364r53IA/Z9t8rCbeF/FoPSjVTungqTCm0Tl3AekqTF1RwP/+6bvZhS9T48pgXlYhk4OR91O7T4Ng AzHGMFnELPq0GlMslxag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Sts-00BTGj-28; Fri, 09 Jun 2023 03:34:56 +0000 Received: from m126.mail.126.com ([220.181.12.29]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Stm-00BTCw-0N for opensbi@lists.infradead.org; Fri, 09 Jun 2023 03:34:53 +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=3UZnc 0RZkUK3YpjX+qu6bVrWrKbrAbVfIY8M1ZBvj+8=; b=KY8KuZ+c+kxvjTEX32h0J 9kTsy/zchwuuaryC7DOjqK6ppZmflGYD0bM5ac3lmlxW5tamWIY6QPuucmp2Q7A8 8y66em+Z5nqukApnK3xneyPmOOLRb4taxXwS3MYbFIw/0tUS0xMQeXL88es8d0mS b99UnHTG8sZF0mGuIpfojM= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g0-1 (Coremail) with SMTP id _____wB3omDKnYJkJuYMAA--.4380S12; Fri, 09 Jun 2023 11:34:39 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v5 10/14] lib: sbi: sbi_console.c code re-layout Date: Fri, 9 Jun 2023 11:34:26 +0800 Message-Id: <20230609033430.84471-11-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609033430.84471-1-wxjstz@126.com> References: <20230609033430.84471-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wB3omDKnYJkJuYMAA--.4380S12 X-Coremail-Antispam: 1Uf129KBjvJXoW7WF17XrykCw1fAFWrKrW5trb_yoW8GF4xpF Z3uFy3tw4FgFs3W3saqF45Gw1rAw1rKwnFqry3u3ySq3Z5A3s3t3W5Wa15tFW5Z395AFyr Aa4vy3W8Wa9rXw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zK-eFJUUUUU= X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbiJhOJOlpD8z50SwAAst X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230608_203450_498435_3FD9F33E X-CRM114-Status: UNSURE ( 7.34 ) 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: Move the type definitions and macros in sbi_console.c to the begin of the file. Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 22 +++++++++++ 1 file changed, 11 insertions(+), 11 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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 Move the type definitions and macros in sbi_console.c to the begin of the file. Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index 824ff6e..af93f51 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -14,8 +14,19 @@ #include #include +#define PAD_RIGHT 1 +#define PAD_ZERO 2 +#define PAD_ALTERNATE 4 +#define PAD_SIGN 8 +#define PRINT_BUF_LEN 64 #define CONSOLE_TBUF_MAX 256 +#define va_start(v, l) __builtin_va_start((v), l) +#define va_end __builtin_va_end +#define va_arg __builtin_va_arg + +typedef __builtin_va_list va_list; + static const struct sbi_console_device *console_dev = NULL; static char console_tbuf[CONSOLE_TBUF_MAX]; static u32 console_tbuf_len; @@ -117,17 +128,6 @@ unsigned long sbi_ngets(char *str, unsigned long len) return i; } -#define PAD_RIGHT 1 -#define PAD_ZERO 2 -#define PAD_ALTERNATE 4 -#define PAD_SIGN 8 -#define PRINT_BUF_LEN 64 - -#define va_start(v, l) __builtin_va_start((v), l) -#define va_end __builtin_va_end -#define va_arg __builtin_va_arg -typedef __builtin_va_list va_list; - static void printc(char **out, u32 *out_len, char ch) { if (!out) { From patchwork Fri Jun 9 03:35:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1792759 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.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=DY9fj2Q6; 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=GklNnK6q; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Qcmvh38H4z20WP for ; Fri, 9 Jun 2023 13:36:16 +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:References:In-Reply-To: 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: List-Owner; bh=yh+wUmZv11n7IZvQXetBXayytOlOwaQv+MxxLbWtWlo=; b=DY9fj2Q6IpzUfy 4EExg4NQr5IV5hcvV6UEIt4T8RJ0CdEdQsMaXCF3RFq4UQivp8Sxny8dDGtB8sduuEzccYPhz821+ e5NQa78IhsKvHahoHJVMkXktvmz7Q7+K8d4Kc7Toe0fJbdx9N8P+fIPe15Oq12YrnZUI5jTNoW4Gf mOjkfjbo0P8wUYMj677c3gTOUaRGV48zX9sr4oMbijlNrUZB86zMeo1lMvBZAvxY+qTUH8w3CmdKa YwYPNs2jKXkpUfDTNmntlJNbIUVdMTVg3VOZMUi7TpJUHwZINtfgBL3WNayshmsA9uh1tXmC5R0GM W88AClEG4HykQYICMEaA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Suy-00BTmc-1F; Fri, 09 Jun 2023 03:36:04 +0000 Received: from m126.mail.126.com ([220.181.12.35]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Sut-00BTl7-2T for opensbi@lists.infradead.org; Fri, 09 Jun 2023 03:36:02 +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=5yxGE mmt+JyJu1Wv0y0uU1dxM54ayzhcRt1eABTGRGo=; b=GklNnK6qIjiSJjKIOSjBH OFxa+sVYcwmjeVKoxMdv7evEdrZhYy+T6wGd4c+DejY4ks5P0Whk/54RKZnGn+lK uQLu21MAdbDB225rTyoxDViIO8ZhNG6qgagbhCtQIJ34TZiUJ16DFVNzAu87MtrD UGuY3JeUD4KfYfaUQHJRIY= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g1-1 (Coremail) with SMTP id _____wA3P5MXnoJk0+cMAA--.3962S2; Fri, 09 Jun 2023 11:35:52 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v5 11/14] lib: sbi: Add print_info for sbi_console.c Date: Fri, 9 Jun 2023 11:35:38 +0800 Message-Id: <20230609033538.84664-1-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609033430.84471-1-wxjstz@126.com> References: <20230609033430.84471-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wA3P5MXnoJk0+cMAA--.3962S2 X-Coremail-Antispam: 1Uf129KBjvJXoW3Zr4xZryfur47tF4xuFW5GFg_yoWDCw4rpF sIvFZxXa1rtw4xGrWDAw4DCF4Ykr98Cw1YvrZrG34SvF45C3ykZF4fGFyYvF4kCw43Zry5 C3Z5ta45ua1jyaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piF1v-UUUUU= X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbiFxWJOlpEGdKN0wABs7 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230608_203600_133501_3E8A896A X-CRM114-Status: GOOD ( 19.80 ) 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: Create a structure print_info for print, this structure simplifies parameter passing. Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 235 +++++++++++++++++++++ 1 file changed, 120 insertions(+), 115 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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 Create a structure print_info for print, this structure simplifies parameter passing. Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 235 +++++++++++++++++++++--------------------- 1 file changed, 120 insertions(+), 115 deletions(-) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index af93f51..c227b0f 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -27,11 +27,22 @@ typedef __builtin_va_list va_list; +struct print_info { + char *out; + int len; + int pos; + int pc; + int flags; + int width; + int wcnt; + char type; +}; + static const struct sbi_console_device *console_dev = NULL; static char console_tbuf[CONSOLE_TBUF_MAX]; -static u32 console_tbuf_len; static spinlock_t console_out_lock = SPIN_LOCK_INITIALIZER; + bool sbi_isprintable(char c) { if (((31 < c) && (c < 127)) || (c == '\f') || (c == '\r') || @@ -128,70 +139,63 @@ unsigned long sbi_ngets(char *str, unsigned long len) return i; } -static void printc(char **out, u32 *out_len, char ch) +static void printc(struct print_info *info, char ch) { - if (!out) { + /* output to the console */ + if (info->out == NULL) { sbi_putc(ch); + info->pc++; return; } - /* - * The *printf entry point functions have enforced that (*out) can - * only be null when out_len is non-null and its value is zero. - */ - if (!out_len || *out_len > 1) { - *(*out)++ = ch; - **out = '\0'; - } + /* unknown buffer length */ + if (info->len == 0) + goto append; - if (out_len && *out_len > 0) - --(*out_len); + /* The buffer is long enough to add new characters */ + if (info->len - info->pos > 1) + goto append; + return; + +append: + info->out[info->pos++] = ch; + info->out[info->pos] = '\0'; + info->pc++; } -static int prints(char **out, u32 *out_len, const char *string, int width, - int flags) +static void prints(struct print_info *info, const char *string) { - int pc = 0; - width -= sbi_strlen(string); - if (!(flags & PAD_RIGHT)) { - for (; width > 0; --width) { - printc(out, out_len, flags & PAD_ZERO ? '0' : ' '); - ++pc; - } - } - for (; *string; ++string) { - printc(out, out_len, *string); - ++pc; - } - for (; width > 0; --width) { - printc(out, out_len, ' '); - ++pc; + info->wcnt += sbi_strlen(string); + if (!(info->flags & PAD_RIGHT)) { + for (; info->wcnt < info->width; info->wcnt++) + printc(info, info->flags & PAD_ZERO ? '0' : ' '); } - - return pc; + for (; *string; ++string) + printc(info, *string); + for (; info->wcnt < info->width; info->wcnt++) + printc(info, ' '); } -static int printi(char **out, u32 *out_len, long long i, - int width, int flags, int type) +static void printi(struct print_info *info, long long i) { - int pc = 0; char *s, sign, letbase, print_buf[PRINT_BUF_LEN]; unsigned long long u, b, t; b = 10; letbase = 'a'; - if (type == 'o') + if (info->type == 'o') b = 8; - else if (type == 'x' || type == 'X' || type == 'p' || type == 'P') { + else if (info->type == 'x' || info->type == 'X' + || info->type == 'p' || info->type == 'P') { b = 16; letbase &= ~0x20; - letbase |= type & 0x20; + letbase |= info->type & 0x20; } u = i; sign = 0; - if (type == 'i' || type == 'd') { - if ((flags & PAD_SIGN) && i > 0) + if (info->type == 'i' || info->type == 'd') { + if ((info->flags & PAD_SIGN) && i > 0) sign = '+'; if (i < 0) { sign = '-'; @@ -214,26 +218,23 @@ static int printi(char **out, u32 *out_len, long long i, } } - if (flags & PAD_ZERO) { + if (info->flags & PAD_ZERO) { if (sign) { - printc(out, out_len, sign); - ++pc; - --width; + printc(info, sign); + ++info->wcnt; } - if (i && (flags & PAD_ALTERNATE)) { + if (i && (info->flags & PAD_ALTERNATE)) { if (b == 16 || b == 8) { - printc(out, out_len, '0'); - ++pc; - --width; + printc(info, '0'); + ++info->wcnt; } if (b == 16) { - printc(out, out_len, 'x' - 'a' + letbase); - ++pc; - --width; + printc(info, 'x' - 'a' + letbase); + ++info->wcnt; } } } else { - if (i && (flags & PAD_ALTERNATE)) { + if (i && (info->flags & PAD_ALTERNATE)) { if (b == 16) *--s = 'x' - 'a' + letbase; if (b == 16 || b == 8) @@ -243,15 +244,16 @@ static int printi(char **out, u32 *out_len, long long i, *--s = sign; } - return pc + prints(out, out_len, s, width, flags); + prints(info, s); } -static int print(char **out, u32 *out_len, const char *format, va_list args) +static void print(struct print_info *info, const char *format, va_list args) { bool flags_done; - int width, flags, pc = 0; - char type, scr[2], *tout; - bool use_tbuf = (!out) ? true : false; + char scr[2]; + bool use_tbuf = (!info->out) ? true : false; + info->pos = 0; + info->pc = 0; /* * The console_tbuf is protected by console_out_lock and @@ -259,19 +261,15 @@ static int print(char **out, u32 *out_len, const char *format, va_list args) * when out == NULL. */ if (use_tbuf) { - console_tbuf_len = CONSOLE_TBUF_MAX; - tout = console_tbuf; - out = &tout; - out_len = &console_tbuf_len; + info->out = console_tbuf; + info->len = CONSOLE_TBUF_MAX; } for (; *format != 0; ++format) { - if (use_tbuf && !console_tbuf_len) { - nputs_all(console_tbuf, CONSOLE_TBUF_MAX); - console_tbuf_len = CONSOLE_TBUF_MAX; - tout = console_tbuf; - } - + if (use_tbuf && (info->len - info->pos <= 1)) { + nputs_all(info->out, info->pos); + info->pos = 0; + } if (*format == '%') { ++format; if (*format == '\0') @@ -279,21 +277,21 @@ static int print(char **out, u32 *out_len, const char *format, va_list args) if (*format == '%') goto literal; /* Get flags */ - flags = 0; + info->flags = 0; flags_done = false; while (!flags_done) { switch (*format) { case '-': - flags |= PAD_RIGHT; + info->flags |= PAD_RIGHT; break; case '+': - flags |= PAD_SIGN; + info->flags |= PAD_SIGN; break; case '#': - flags |= PAD_ALTERNATE; + info->flags |= PAD_ALTERNATE; break; case '0': - flags |= PAD_ZERO; + info->flags |= PAD_ZERO; break; case ' ': case '\'': @@ -306,153 +304,160 @@ static int print(char **out, u32 *out_len, const char *format, va_list args) if (!flags_done) ++format; } - if (flags & PAD_RIGHT) - flags &= ~PAD_ZERO; + if (info->flags & PAD_RIGHT) + info->flags &= ~PAD_ZERO; /* Get width */ - width = 0; + info->width = 0; + info->wcnt = 0; for (; *format >= '0' && *format <= '9'; ++format) { - width *= 10; - width += *format - '0'; + info->width *= 10; + info->width += *format - '0'; } + info->type = *format; if (*format == 's') { char *s = va_arg(args, char *); - pc += prints(out, out_len, s ? s : "(null)", - width, flags); + prints(info, s ? s : "(null)"); continue; } if ((*format == 'd') || (*format == 'i')) { - pc += printi(out, out_len, va_arg(args, int), - width, flags, *format); + printi(info, va_arg(args, int)); continue; } if ((*format == 'u') || (*format == 'o') || (*format == 'x') || (*format == 'X')) { - pc += printi(out, out_len, va_arg(args, unsigned int), - width, flags, *format); + printi(info, va_arg(args, unsigned int)); continue; } if ((*format == 'p') || (*format == 'P')) { - pc += printi(out, out_len, (uintptr_t)va_arg(args, void*), - width, flags, *format); + printi(info, (uintptr_t)va_arg(args, void*)); continue; } if (*format == 'l') { - type = 'i'; + info->type = 'i'; if (format[1] == 'l') { ++format; if ((format[1] == 'u') || (format[1] == 'o') || (format[1] == 'd') || (format[1] == 'i') || (format[1] == 'x') || (format[1] == 'X')) { ++format; - type = *format; + info->type = *format; } - pc += printi(out, out_len, va_arg(args, long long), - width, flags, type); + printi(info, va_arg(args, long long)); continue; } if ((format[1] == 'u') || (format[1] == 'o') || (format[1] == 'd') || (format[1] == 'i') || (format[1] == 'x') || (format[1] == 'X')) { ++format; - type = *format; + info->type = *format; } - if ((type == 'd') || (type == 'i')) - pc += printi(out, out_len, va_arg(args, long), - width, flags, type); + if ((info->type == 'd') || (info->type == 'i')) + printi(info, va_arg(args, long)); else - pc += printi(out, out_len, va_arg(args, unsigned long), - width, flags, type); + printi(info, va_arg(args, unsigned long)); continue; } if (*format == 'c') { /* char are converted to int then pushed on the stack */ scr[0] = va_arg(args, int); scr[1] = '\0'; - pc += prints(out, out_len, scr, width, flags); + prints(info, scr); continue; } } else { literal: - printc(out, out_len, *format); - ++pc; + printc(info, *format); } } - if (use_tbuf && console_tbuf_len < CONSOLE_TBUF_MAX) - nputs_all(console_tbuf, CONSOLE_TBUF_MAX - console_tbuf_len); - - return pc; + if (use_tbuf && info->pos > 0) + nputs_all(info->out, info->pos); } int sbi_sprintf(char *out, const char *format, ...) { va_list args; - int retval; + struct print_info info; + info.out = out; + info.len = 0; + if (unlikely(!out)) sbi_panic("sbi_sprintf called with NULL output string\n"); va_start(args, format); - retval = print(&out, NULL, format, args); + print(&info, format, args); va_end(args); - return retval; + return info.pc; } int sbi_snprintf(char *out, u32 out_sz, const char *format, ...) { va_list args; - int retval; + struct print_info info; + info.out = out; + info.len = out_sz; + if (unlikely(!out && out_sz != 0)) sbi_panic("sbi_snprintf called with NULL output string and " "output size is not zero\n"); va_start(args, format); - retval = print(&out, &out_sz, format, args); + print(&info, format, args); va_end(args); - return retval; + return info.pc; } int sbi_printf(const char *format, ...) { va_list args; - int retval; + struct print_info info; + info.out = NULL; + info.len = 0; + spin_lock(&console_out_lock); va_start(args, format); - retval = print(NULL, NULL, format, args); + print(&info, format, args); va_end(args); spin_unlock(&console_out_lock); - return retval; + return info.pc; } int sbi_dprintf(const char *format, ...) { va_list args; - int retval = 0; struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); + struct print_info info; + info.out = NULL; + info.len = 0; + va_start(args, format); if (scratch->options & SBI_SCRATCH_DEBUG_PRINTS) { spin_lock(&console_out_lock); - retval = print(NULL, NULL, format, args); + print(&info, format, args); spin_unlock(&console_out_lock); } va_end(args); - return retval; + return info.pc; } void sbi_panic(const char *format, ...) { va_list args; + struct print_info info; + info.out = NULL; + info.len = 0; spin_lock(&console_out_lock); va_start(args, format); - print(NULL, NULL, format, args); + print(&info, format, args); va_end(args); spin_unlock(&console_out_lock); From patchwork Fri Jun 9 03:36:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1792763 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.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=VwW5Z9ek; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=UY0cEmZE; 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=garE/goC; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QcmyG50xXz20WP for ; Fri, 9 Jun 2023 13:38:30 +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:References:In-Reply-To: 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: List-Owner; bh=6+hvQOaEC97hXO6AoPKLISfc/s6wspbdvvQ/CjRLtSA=; b=VwW5Z9ekkOSudK usM7vcpAG9YQJKpVPnW1rfJCYYhx3w9uDv1//iJETYYBVpvIAnuFeq0Anfo0DMs5a46+MsZH7KGa4 BKBOTG3D1m+ysilrt6qVABwL0n57qBsvDdmpXxcfEp2u27TW7Nrrpx9kahWOcq0QGA5f8L7bzpGc6 cv64UeOckUnMB2PHCNg4rtvhgregp+497pCM2UOkGr1/nvL4TmzBaXY4H+RToWob5W2qbPowUh8a3 BxJqjQW33zPWy6YrRAwvB7FQzeQJxyNJvXQWQ3AZLHUY2ahR/wLLDyc4MfcXjSUYx7m0afcPk4LJN F1bn6HzCIO16qcr3gV0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Sx8-00BUDS-2C; Fri, 09 Jun 2023 03:38:18 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q7Sx7-00BUDC-1r for opensbi@bombadil.infradead.org; Fri, 09 Jun 2023 03:38:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=F5G9oVP8SJNYttUZrMhqezksabE3erkA5tKA+0zY2mA=; b=UY0cEmZE/JSNqs0Si+elk3Omcl YyuSkyopr/7ITCebo2a9kaq3X+7WXtxAMIv0wti3mEXpbrH6mmeSAFzEpcwftdmwVB29VH34Y9zWg 208NngWNzUaVSFIm2Vc1h3NdHS3aMo0RZENeYh2uwRntFtXG1zuhdk3R1ay/PNBcVmDvdSUYF04mV 6ro30ddf45hgXgRMk3BSkzZi+uaamuIsiqQYJgpDmsEnTXG/o63KOccLBbMWz2UDUnjDY0TS3DcGQ 1pNZt2EBbh0WPVZRsotfuos16Z4IbF84pVqFxhPWHPurxmCpdqpB9fVU46WH7XTSGlcjapV/2HBZi JoK06Fzw==; Received: from m126.mail.126.com ([220.181.12.29]) by casper.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1q7Sx3-00G8XR-PX for opensbi@lists.infradead.org; Fri, 09 Jun 2023 03:38:16 +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=F5G9o VP8SJNYttUZrMhqezksabE3erkA5tKA+0zY2mA=; b=garE/goC07GcS69ZFh267 JDbqcaBWp66NWHUK0xxon/Zfj2sGrhU7id1rbBX2D1Llq8mARIJ4VIw45G3QnfeK xmu71GTZ3dKx6JfFWSjsZvPgyQ9w8EhGRl+24cq54KNPSQzEtQDV0eJRXC8OdIXW H7zacWg7px6nwQU6ZgCGaM= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g5-1 (Coremail) with SMTP id _____wBHQb0pnoJkoNgMAA--.5905S2; Fri, 09 Jun 2023 11:36:09 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v5 12/14] lib: sbi: Fix timing of clearing tbuf Date: Fri, 9 Jun 2023 11:36:06 +0800 Message-Id: <20230609033606.84769-1-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609033430.84471-1-wxjstz@126.com> References: <20230609033430.84471-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wBHQb0pnoJkoNgMAA--.5905S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7ZF1UJF1kZFW8Jry7Zr47Arb_yoW8Wr1Upr 1akF98JF4rtF1fW3yvyF13CF4rA34kG3WayrZrJ34rXFn5J3s7WrWqgF9YvrsxXrZ3AF1Y kFn5JFyUZFyUWrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziU3kNUUUUU= X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbiJhmJOlpD8z52ygABsl X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230609_043814_349903_52A62E7A X-CRM114-Status: UNSURE ( 9.26 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.1 (--) X-Spam-Report: SpamAssassin version 3.4.6 on casper.infradead.org summary: Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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.0 T_SCC_BODY_TEXT_LINE No description available. 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 A single scan of the format char may add multiple characters to the tbuf, causing a buffer overflow. You should check if tbuf is full in printc so that it does not cause a buffer overflow. Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index c227b0f..2eefee1 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -18,6 +18,8 @@ #define PAD_ZERO 2 #define PAD_ALTERNATE 4 #define PAD_SIGN 8 +#define USED_TBUF (1 << (8 * sizeof(int) - 1)) + #define PRINT_BUF_LEN 64 #define CONSOLE_TBUF_MAX 256 @@ -161,6 +163,11 @@ append: info->out[info->pos++] = ch; info->out[info->pos] = '\0'; info->pc++; + + if ((info->flags & USED_TBUF) && (info->len - info->pos <= 1)) { + nputs_all(info->out, info->pos); + info->pos = 0; + } } static void prints(struct print_info *info, const char *string) @@ -266,10 +273,9 @@ static void print(struct print_info *info, const char *format, va_list args) } for (; *format != 0; ++format) { - if (use_tbuf && (info->len - info->pos <= 1)) { - nputs_all(info->out, info->pos); - info->pos = 0; - } + info->flags = 0; + if (use_tbuf) + info->flags |= USED_TBUF; if (*format == '%') { ++format; if (*format == '\0') @@ -277,7 +283,6 @@ static void print(struct print_info *info, const char *format, va_list args) if (*format == '%') goto literal; /* Get flags */ - info->flags = 0; flags_done = false; while (!flags_done) { switch (*format) { From patchwork Fri Jun 9 03:36:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1792760 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.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=nAp77KI1; 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=HYa40qCZ; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QcmwV2sXHz20WP for ; Fri, 9 Jun 2023 13:36:58 +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:References:In-Reply-To: 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: List-Owner; bh=5bwkQsOsE1C3kUI4UdtiFgdRJiI3qtI8WaFc2KAL2xs=; b=nAp77KI1bWZW9G CPjj5Lpxxml88obzOjqQWLFT7UI+0KTPl7DAxR6tOQz5SlRgj2IhBPuazKr43/mqZJUaa11IL3RmO /3pfad/odYfGebVg/FchXI8bKsabRI+lGkmJzmzC60y89xcirAOcSsxt/bMcb7UeGHv9hWcpx1o9+ ghmJLyzqYvi6l4YUB2A9q9fDvRAehDupxYPwQuuhSX3iyn7/75pdmwkuNWKFq3IWd8UTE8epmfuUd smbbojxXG/QSLQXTDdMxYOv4o7YvK9V6I15No8zWIA/wKjWceXtEC63O5fry8lNw6GvbTQ7tHPmjK K+foQWlADmLNbjHPvtsQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Svc-00BTwb-0g; Fri, 09 Jun 2023 03:36:44 +0000 Received: from m126.mail.126.com ([220.181.12.28]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7SvZ-00BTvD-1v for opensbi@lists.infradead.org; Fri, 09 Jun 2023 03:36:43 +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=v00PD 9CnKDtAGzJ2jFnSOFZSddlNeR0Bgn83xI0ee9I=; b=HYa40qCZPK1cphjUgZ1/i Jd2lTzELIxwgvUevj175ToTUujdVPQvV6kqNbeKxpYMsFMXFUmw2iPbuTqwuWD+b hsd3VZJT0dQQ67+tMTle+m14+YMUVTb1AIvv6XW3JS/oHgw0kySgesknONnMKO+i XRmm5jb+el4hNmocQDeuyM= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g2-0 (Coremail) with SMTP id _____wB3K+07noJk6d0MAA--.15775S2; Fri, 09 Jun 2023 11:36:28 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v5 13/14] lib: sbi: Fix missing '\0' when buffer szie equal 1 Date: Fri, 9 Jun 2023 11:36:24 +0800 Message-Id: <20230609033624.84865-1-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609033430.84471-1-wxjstz@126.com> References: <20230609033430.84471-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wB3K+07noJk6d0MAA--.15775S2 X-Coremail-Antispam: 1Uf129KBjvdXoWrKry3Gr1ruFW3ArykWryfWFg_yoW3JFcEya 97Cr1UK39rAFZakw1UAF4xArWYyw4S9F1DXa1DtrZxC3y7WrsxJrWYgwnagas8GFW2vr92 krW7urn5Cwn8WjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRtjg4PUUUUU== X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi5B2JOlpEGBEeTAAAsP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230608_203641_972186_1669B6C5 X-CRM114-Status: UNSURE ( 7.33 ) 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: Fix special case: sbi_snprintf(out, 1, ...), The previous code will not fill the buffer with any char. Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index 2eefee1..f7fd761 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -157,6 +157,14 @@ static void printc(struct print_in [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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 Fix special case: sbi_snprintf(out, 1, ...), The previous code will not fill the buffer with any char. Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index 2eefee1..f7fd761 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -157,6 +157,14 @@ static void printc(struct print_info *info, char ch) /* The buffer is long enough to add new characters */ if (info->len - info->pos > 1) goto append; + + /* + * special case: sbi_snprintf(out, 1, ...); + * This case never jumps to append, so add '\0' here + */ + if (info->pos == 0) + info->out[0] = '\0'; + return; append: From patchwork Fri Jun 9 03:36:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1792761 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.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=zWZn9xKU; 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=IlH+RGUt; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Qcmxm0RT9z20WP for ; Fri, 9 Jun 2023 13:38:04 +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:References:In-Reply-To: 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: List-Owner; bh=FGTN5w1mYcwvGrmr9/jCurznuROlCalWYe5irUcYUE0=; b=zWZn9xKUaHSJQv kXbuEwHFFklzXaCcXtkFv7Bw+6RnPTmh94Hh5OClScytMY4ybmMyZFTol5Udw51GFc+GZEERvBeJm x3KsKTgd85iDpZmJ4UuIy9QwUSyiBFp37z8uvBiPul9b/xt51Robd7b3b2wGrmTH4OX0GLgKXtovs 4vWklJ3WAy4yhs+GfIyOjIz3y/5/WqZl+Le6RUR8KX38+Cy4Z4zggPL+PNlXjJpDC/6OO7fujAFcC 270co7ayCaTGGJdmcjmVYPfe1pIdMb0/W1ZeAdSUWrSyXZYOKOd8yZu8RxnoUTo2W0fDNiLYmsOf4 LQ7I+Mn0+gBhm7AGBT8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Swh-00BU8u-1l; Fri, 09 Jun 2023 03:37:51 +0000 Received: from m126.mail.126.com ([220.181.12.29]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7Swd-00BU8U-2o for opensbi@lists.infradead.org; Fri, 09 Jun 2023 03:37:49 +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=+m+VB w5lEYAJ1Rf3bxPPQUDiABxiW+fz1cgGdy055io=; b=IlH+RGUtM1ZWI6YArYqpl aEfT5CEGENcoVCLsWOdrYfv+yJE5Xol+twFAeleUNgpcwZzzI7mw/brL8e+jzWSM GJGJVnVRfgKasg2+KAUGxEiSOCbX8UF6WCiQIOGS00ClL0vZP/fmlQ2GtlCmRDCp J54kaVtnH5fbYN8A2Dq+z4= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g2-1 (Coremail) with SMTP id _____wCHjDhMnoJkzcEMAA--.4294S2; Fri, 09 Jun 2023 11:36:45 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v5 14/14] lib: sbi: Fix invalid directive print Date: Fri, 9 Jun 2023 11:36:43 +0800 Message-Id: <20230609033643.85014-1-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609033430.84471-1-wxjstz@126.com> References: <20230609033430.84471-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wCHjDhMnoJkzcEMAA--.4294S2 X-Coremail-Antispam: 1Uf129KBjvJXoWruFWUArWUuryUKrWUXF15CFg_yoW8Jr1xpw sIkFZ8JFsYqF1Sgr97Aws7Ca4Fqws5J3W2qrZxJw4I9Fn5G397Wr4DG3WFyws3GryrJ3W5 AFn5ZryUGF18XrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zEiFxnUUUUU= X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi5A2JOlpEGBEe0wAAsA X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230608_203748_306120_4C908981 X-CRM114-Status: UNSURE ( 7.65 ) 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: before fix: > printf("%1234"); /* print noting */ after fix: > printf("%1234"); /* print %1234 */ Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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 before fix: > printf("%1234"); /* print noting */ after fix: > printf("%1234"); /* print %1234 */ Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index f7fd761..a4ee1e5 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -266,6 +266,7 @@ static void print(struct print_info *info, const char *format, va_list args) { bool flags_done; char scr[2]; + const char *format_bak; bool use_tbuf = (!info->out) ? true : false; info->pos = 0; info->pc = 0; @@ -285,6 +286,8 @@ static void print(struct print_info *info, const char *format, va_list args) if (use_tbuf) info->flags |= USED_TBUF; if (*format == '%') { + /* need restore when the directive is invalid */ + format_bak = format; ++format; if (*format == '\0') break; @@ -377,10 +380,11 @@ static void print(struct print_info *info, const char *format, va_list args) prints(info, scr); continue; } - } else { -literal: - printc(info, *format); + /* invalid directive */ + format = format_bak; } +literal: + printc(info, *format); } if (use_tbuf && info->pos > 0)