From patchwork Tue Jul 4 13:11:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1803210 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=Z+JDlnp9; 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=O8qhkbL+; 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 4QwNXK6Z3nz20Pf for ; Tue, 4 Jul 2023 23:13:37 +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=SLskTfjwNnBxHZBSsl+KTHruz5+Wq7zis4kefuTWeIY=; b=Z+JDlnp9toyFL9 VV6TjpEH5t2n68qGQT4KXM8PXImDf4dLn1VWISQ6dOQc4nuRqFY9XMINc23orQJxt4HldoFX1gfYK boMTDRX5elu6iFlOc9t/ZqawDS4gJwZ5JwMysO78Htt75Zr2dRvHx7ijr7erwgGtLp8T7X9kV8ImO ICvDFvMm1RfjVrn9JmxCmB6A5F1gdNUvZQsvw1qp1guZymDtfe/8al4ca3WmzSaHdSj8z5t7XRtJc 7XB9rNVJaevOoqhCVHntYZA+sJpPEfpWItrekg2XCpyB1kms/dkUptTne1+CBhV5rUIYVNe+/OQDI JsVioJVaZq/sclMTd+Cg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qGfqM-00DLnD-2b; Tue, 04 Jul 2023 13:13:22 +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 1qGfqK-00DLls-1s for opensbi@lists.infradead.org; Tue, 04 Jul 2023 13:13:22 +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=zGolQ uDDQWU9h+9erKP0EvieTJp28x55U4XuoY0aN5Q=; b=O8qhkbL+325oKjb4QHy3t VFYvb2ICKJhpwAVkgGUTbr5mmqAn/pRWA/CgiMRiaKzLfuSKnERnj3kJ2kiX1OVk 7Spukcs0g3/S7Lj16+yjpanDX75uqu5kUbh5ckrNBRk+wYPzKa0K5vbJvLaEKd2U EAT/5XnMTkiB0LaXfeb6vY= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g1-0 (Coremail) with SMTP id _____wCXJ8CyGqRkGritAQ--.14207S3; Tue, 04 Jul 2023 21:12:20 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v7 01/11] lib: sbi: Fix how print gets flags Date: Tue, 4 Jul 2023 21:11:58 +0800 Message-Id: <20230704131208.465914-2-wxjstz@126.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230704131208.465914-1-wxjstz@126.com> References: <20230704131208.465914-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wCXJ8CyGqRkGritAQ--.14207S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7Aw13Cry3tw4DuFWrKw4xCrg_yoW8GrWkpF n5CFZxJFnYyFn3Jay3Jws7CayrA395CFyj9rW3Gw4rWFy3CryFkFykXFyFyr93KryxAr15 K3WrJFyjgFWjq3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziPEf5UUUUU= X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbiFxWiOlpEGpr0bQABsc X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230704_061320_945513_A12E1D5C X-CRM114-Status: UNSURE ( 8.44 ) 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 | 30 +++++++++++++++++++ 1 file changed, 19 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 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 Reviewed-by: Anup Patel --- lib/sbi/sbi_console.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index 168dffd..d87b5c2 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; @@ -268,17 +269,24 @@ static int print(char **out, u32 *out_len, const char *format, va_list args) 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_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 */ for (; *format >= '0' && *format <= '9'; ++format) { From patchwork Tue Jul 4 13:11:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1803208 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=mMbt6CQk; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=e4RtsJxt; 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=CJQCa+9B; 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 4QwNWT0myYz20b5 for ; Tue, 4 Jul 2023 23:12:53 +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=oTT8xvLk1fWSBZuK5gZOrt5iKhElUOUmO/7pwEL38O4=; b=mMbt6CQkAd46h2 jGz2PpoG3JX3+1gLXNSey0WS/5wP6VUMT7YB6eNWxMfH4DMdyVNLqpu5obhvGGz1DCDnXg6BY+dte adVcUW5cANio2tPJf0vXzpEOrWcEbLPXHZv2EA/EfrRFxj5WoM9chgpUVFxVMsH30lsR7xU+tjsD6 FENb+Z6hjLk7NmBQsXvUnXeNtR++q5Oihq19UhghgE7963f9QNnDXwO8lKpyBWY6X+GGijcYLFSQ6 Wc3FN+P9I+EFuIKGNaSv0lkJB7xW9YC/1BrvqXILIXzS56yW+sOFUu/1+NF05Vz72HN9GzcjtmIG4 o5a8Vv9ssejPONl358vQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qGfpe-00DLQq-2d; Tue, 04 Jul 2023 13:12:38 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qGfpd-00DLQ3-0i for opensbi@bombadil.infradead.org; Tue, 04 Jul 2023 13:12:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=CRYGc/h9Okky6e89Z0r4MeC0c4LY3dZGQjzwt+vtg/I=; b=e4RtsJxtp6Ip1E8NiEzdoheua4 OO1Sz4VcmZKhX6z3TCN7VX/mB/DzlSjKnSXFTuqfiJRa4qovaNc8HAze3J5z3lP5xbRd+KCZHoW3W NiSl0+x/768Tpju8RqozqM9R/+MHcVMDz0AQL2ryFs5oZ3ahmZ5rHA4WtQXPeBbs3x1WMDb6ZwB4K mmrAr3X22xodiSEEn0TLN6pYtbRc2/vKUGO1sUgYYSqPVZlDsgX0zE2C1iUUpCZZc6SEoq5gXJp8S BjSRG/elIukGWqrzwLPOE7I1FK7iHbB5Tsc7gk/cAnmaKfS7YxbDETxgZK0c+5qM7OG3utO1lrlRW UB/G4AUg==; Received: from m126.mail.126.com ([220.181.12.26]) by desiato.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qGfpY-00AvJ8-11 for opensbi@lists.infradead.org; Tue, 04 Jul 2023 13:12:36 +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=CRYGc /h9Okky6e89Z0r4MeC0c4LY3dZGQjzwt+vtg/I=; b=CJQCa+9BrxNIOrLVoY2Jv j0yFcgvsV44ZXyYW9ARUki5AmGJu4eBazRx1CD1v2htHC7wW+Q9VKrIRFuoL/EcH zap1NJxXWeBQw0LAiiA493oylhfRyFllx1g2YVlOu9EWIcaT26Ecb2SrnJLOsdx2 sAxl8lsu+3Eg0413z533ew= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g1-0 (Coremail) with SMTP id _____wCXJ8CyGqRkGritAQ--.14207S4; Tue, 04 Jul 2023 21:12:20 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v7 02/11] lib: sbi: print not fill '0' when left-aligned Date: Tue, 4 Jul 2023 21:11:59 +0800 Message-Id: <20230704131208.465914-3-wxjstz@126.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230704131208.465914-1-wxjstz@126.com> References: <20230704131208.465914-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wCXJ8CyGqRkGritAQ--.14207S4 X-Coremail-Antispam: 1Uf129KBjvdXoW7XF1DGFyUtrW7Kr1fCrWfKrg_yoWxZrbEy3 yxA340grZ8JFZavr1ktF48Wr4Fkw18ursrWF17KFs0yrWIvr4UX3y0qr9Fgas8Ar47uryI k3y7Arn0kry5WjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRWUDXUUUUUU== X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi1xSiOl53bj3WoAAAsX X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230704_141233_079479_9824811C X-CRM114-Status: UNSURE ( 6.92 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.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 skips padding. Signed-off-by: Xiang W Reviewed-by: Anup Patel --- 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_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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 skips padding. Signed-off-by: Xiang W Reviewed-by: Anup Patel --- 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 d87b5c2..03ee05a 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 */ for (; *format >= '0' && *format <= '9'; ++format) { width *= 10; From patchwork Tue Jul 4 13:12:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1803205 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=Apovp4cs; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=dYYVTacG; 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=nFZ+wAFj; 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 4QwNWR0qJbz20b5 for ; Tue, 4 Jul 2023 23:12: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=4nYHfafwH2ssgQHJL1YhV9BtMH3bNvfPBLaA7xRUJXc=; b=Apovp4csGF+k6f 3P3cd4JlZfH9smRpOe3fDh6rwVjCWUo41oVauPuETyS81DQPY6uD8aelxZD406dm/G/2hbWmQ4TCd fpKpInQPrjoINDyBawM6NW9qm0/gqeoAyCo1heL/NQRjKO4huIxnCQB+UCS80bF0I2aglg+OzpKWu EpU+xBxH/F6uSIwAyNUk0MCn6t2aFY2kf5dkoKOLqQCdsLjdmwlqQmXD6wfbhvOd1tlFl0mH+YqiG Ck2BHOfSoSs9+VyNLDtLjhWqgtn5gqrtRurrXDn05VPjhqLdM+7RVyMgjBCuzRBE/lk7Xd5B7/+PB KobOgxsp8VaOnYobBLjg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qGfpe-00DLQd-18; Tue, 04 Jul 2023 13:12:38 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qGfpc-00DLPO-0t for opensbi@bombadil.infradead.org; Tue, 04 Jul 2023 13:12:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=GBfNI/zRRGqBH1W/pfiXBDWfSDR5jB+HnodEhLi17I0=; b=dYYVTacGAsCUNxfD120By27N1i NBcaoicKi4nAZ0HOQvakaWq8j2mpw+xm9n5G1G9yLAbPOFj2rdXzfqdAHr7FujcZP7PCtNLYnSbp1 F3Cd5Ewnv1qiqWHP5VtXpV/hS0JLSQhIIO6wir8RHIZ+AbbiqwJHQjd5SawIeE3U40fzXjCkWtQzN QfXfFlqkGTmwRsvZfY9Mc8/jnTlxMNag4tx1ewVS8ooj0mvZxd/yeX9FpEoAuKH3AZ2Gt0A22aOmU iyDHN8nkoBaehYgF0p79GJeR7CVbhrhx7sBo20Kndm2IhyvpxUIGTRosXvTyYVgcNnc4jJox7fEmn tLb/8upA==; Received: from m126.mail.126.com ([220.181.12.36]) by desiato.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qGfpX-00AvJ6-2z for opensbi@lists.infradead.org; Tue, 04 Jul 2023 13:12:34 +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=GBfNI /zRRGqBH1W/pfiXBDWfSDR5jB+HnodEhLi17I0=; b=nFZ+wAFjAZwq5Uct0ga46 pccgrwSJiJMMRJLtdJTFb3E2aXc59TJDJ1rHZ2F+afBlepXzYeMKTOpMDHb/CUgz Lxf4WcEg+UjeupOg2JyA7nCIZbLWf54O+Glf1ekp3/DRTzb8yE1yDtubfoWMrSTU J9cBfFGMUH//FyYWvS/nVI= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g1-0 (Coremail) with SMTP id _____wCXJ8CyGqRkGritAQ--.14207S5; Tue, 04 Jul 2023 21:12:20 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v7 03/11] lib: sbi: Add '+' flags for print Date: Tue, 4 Jul 2023 21:12:00 +0800 Message-Id: <20230704131208.465914-4-wxjstz@126.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230704131208.465914-1-wxjstz@126.com> References: <20230704131208.465914-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wCXJ8CyGqRkGritAQ--.14207S5 X-Coremail-Antispam: 1Uf129KBjvJXoW7AF1DCF18WF1rAw1DXryftFb_yoW8ArykpF 4fKFsIqFW0qF93G39xt3W5Ca4Yk34FkF12yrW3t3y8ZF1DCa1rtr4kX3Wrtry7u34kAF45 Aas5ZF4jga1DXw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziAnY7UUUUU= X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbiFxSiOlpEGpr0bAAAsd X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230704_141232_697350_5A89DF32 X-CRM114-Status: GOOD ( 10.61 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.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: Adds + flags for print, prefixing positive numbers with + when this flags is present Signed-off-by: Xiang W Reviewed-by: Anup Patel --- lib/sbi/sbi_console.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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 Adds + flags for print, prefixing positive numbers with + when this flags is present Signed-off-by: Xiang W Reviewed-by: Anup Patel --- 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 03ee05a..6ebdc44 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 Tue Jul 4 13:12:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1803219 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=RaWQ2snj; 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=Z0ObWx1L; 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 4QwNrv2nq7z20Pf for ; Tue, 4 Jul 2023 23:27:59 +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=uSfVfa7B8SVB+C06sk3tpAt7zeTxSQy7aby3qEQM/3Y=; b=RaWQ2snjsunMl0 u5YpuCRNbIxWD4klKOAmuCQH81IlYs9r8+H7CVNmcjOy224dSUo22keTzGy+jzfTx7n5eOC3AmMle a19/MmkdxHwYhJ25qE1vXkFoIjhXkwD6NBF+dbwX9BDThTYnn750EZM4oTndSIR9S5MWg1e9GgVo/ H5GRKc9LrMTEnYYHVWu6fhQODLtrnatwv4SrmwHAafw6u+5o2U3U5FRPqnzdHW1JEoSiFMKcl0rFH VQEp8CcyWBWDIJm0E5yAgxJWwGxWUyloDyHFWOqXC17Y+YvnqSiLWJYbKjrNsKV7yHTa6zYdrpEUU XG5O8Yi79fTkjj2xFI2Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qGg4G-00DOWg-03; Tue, 04 Jul 2023 13:27:44 +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 1qGg4C-00DOVE-1r for opensbi@lists.infradead.org; Tue, 04 Jul 2023 13:27:42 +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=LTnHc nCpUsYrsWLOz5L1AEWuPMH7YeduNI83a2SVRi8=; b=Z0ObWx1LfyS/lV2xNdWD0 dsoJFVFPzGO3FsDYloQePKWNeLRLZ5NRaXe913tQ04TtqWGKuYggpfxyFj2UTIBm fD7UWQyC3OZ2ywypwaq40slo/E2pNBiefIc2kpF+yE8d2oVr3ndwqHSr1DBOARv/ RGdEY+VR6CbRKdI/HFxo+E= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g1-0 (Coremail) with SMTP id _____wCXJ8CyGqRkGritAQ--.14207S6; Tue, 04 Jul 2023 21:12:20 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v7 04/11] lib: sbi: Add ' ' '\'' flags for print Date: Tue, 4 Jul 2023 21:12:01 +0800 Message-Id: <20230704131208.465914-5-wxjstz@126.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230704131208.465914-1-wxjstz@126.com> References: <20230704131208.465914-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wCXJ8CyGqRkGritAQ--.14207S6 X-Coremail-Antispam: 1Uf129KBjvdXoW7Jr17Kw4Utr1fKw4UGr1xZrb_yoWxKwb_Ga yxC34DuFs8Xa9avF1UtFs7Wr40k347AFn7Wa48KFs8Z3y0gr4xJ398Zr9IgFy8Wr4Uurn2 yr43Arn8CryagjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7sRlks6tUUUUU== X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi1xWiOl53bj3WpQAAsT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230704_062741_534056_4C3FA01C X-CRM114-Status: UNSURE ( 6.91 ) 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 space flag is used to add a space before positive numbers, and apostrophe is used to print the thousand separator. Add code to ignore these two flags Signed-off-by: Xiang W Reviewed-by: Anup Patel --- lib/sbi/sbi_console.c | 4 ++++ 1 file changed, 4 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 The space flag is used to add a space before positive numbers, and apostrophe is used to print the thousand separator. Add code to ignore these two flags Signed-off-by: Xiang W Reviewed-by: Anup Patel --- 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 6ebdc44..b6b23bf 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 Tue Jul 4 13:12:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1803221 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=uTAm1qHv; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=Pq3Fes67; 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=LvCXzT/1; 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 4QwNt060hbz20Pf for ; Tue, 4 Jul 2023 23:28:56 +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=WwJpMVbZDF4HZkWJJ92Y/jGr529esIyz91HLS40nzHI=; b=uTAm1qHvNp9nJv 8iZvJqUm5qu8eJuWuoqGPHDcm0Tnuk1P14Nd2DNK17PTKNZkF6P+5OdbMdEqq75OdljfRi0Emfyu5 U/aTWi3UzXeWNIegSLbEO8TV49+fCkMHtk3rZFRk/2VWV3BqEs1Q+jpbNgZuMHIUimfs9LqM9gdVo F/Z9LuRmdRPbRsyMgfKh7iETvjHkF9oSNA4Nj3BqFd++/Axi2n41stWiQh+DbvoZI5VFj37uOvhjy cSFpSXnPVEIksbS95ziBdBrFdUImJjTKK354u2ordYMmiwvze9dMHloy9LMv2Y5F9f/IWbLS67JqJ AmnyluKsJP1NUL8RU+kw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qGg5C-00DOiF-0J; Tue, 04 Jul 2023 13:28:42 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qGg5A-00DOhk-25 for opensbi@bombadil.infradead.org; Tue, 04 Jul 2023 13:28:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=P33YjdSl8zmNXCAaNgYNP4/qLLIZ5tyRN5u51qtXhY4=; b=Pq3Fes67rNNYY5nBgy7en2t8G2 twqIQ1M5nMPPeHKmrcN+v5v8QadcaiS9t5EgPbqapHEwMnAcLMNU4uCuZc/cXWWb7bVY4uBDXUCwg fD70fokg0GxAg/TDOTC6+HK43lK7VStkZUf2qQIPBhYRSn0FyQA6xNJfJ8uIbLcBimhvWxCXGK3Dr 10p0/GQYF1OsM1Ger/Vs1U5IuBDPHqn+QRClVdM7l7mj3QV5UE5xUVhv9ZeHDG3t6l9Q8Egoh19zR FcRyiT54zdF66udy0JziFVYv3DDQLH4bCDclaR32ULDXJrX/aLSw++8TzPk7cLVQ3vhAvPg1Sl4pi UsgYNicA==; Received: from m126.mail.126.com ([220.181.12.28]) by desiato.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qGg53-00Avh2-2S for opensbi@lists.infradead.org; Tue, 04 Jul 2023 13:28:39 +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=P33Yj dSl8zmNXCAaNgYNP4/qLLIZ5tyRN5u51qtXhY4=; b=LvCXzT/1iCikmVqAn2Gdj hSjS+EkSvmoygJAkS4PvC2MzzyGcOleds3OSI5b6OoT2FaNP9B9DCJHduoNaoDV2 E2FueUH2WKLqrHf+QhcHPD6O6yrcah+GCh7K5T+FTW2oIso6n0cOnQECYTq25vDI b4B8MJBDt8qEwQFP0yRtsM= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g1-0 (Coremail) with SMTP id _____wCXJ8CyGqRkGritAQ--.14207S7; Tue, 04 Jul 2023 21:12:21 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v7 05/11] lib: sbi: implifying the parameters of printi Date: Tue, 4 Jul 2023 21:12:02 +0800 Message-Id: <20230704131208.465914-6-wxjstz@126.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230704131208.465914-1-wxjstz@126.com> References: <20230704131208.465914-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wCXJ8CyGqRkGritAQ--.14207S7 X-Coremail-Antispam: 1Uf129KBjvJXoWxXw15AFWkCw1fWrWDtw4fKrg_yoWruF4rp3 WYkrnIqa1Sy347JrWFqay2qFZ8Z3s3JF129rsrXrWY9F45CFWFqFy5Gr1YyF1kGrZ8ZFWa ka45Jr4Ykw4jqaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRbBM_UUUUU= X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi5BqiOlpEGNljngABsF X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230704_142836_918922_B86E8576 X-CRM114-Status: GOOD ( 11.11 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.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 Reviewed-by: Anup Patel --- lib/sbi/sbi_console.c | 127 +++++++++++++++++ 1 file changed, 50 insertions(+), 77 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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 Reviewed-by: Anup Patel --- lib/sbi/sbi_console.c | 127 +++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 77 deletions(-) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index b6b23bf..7dd023f 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 @@ -314,83 +324,46 @@ 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'); + width, flags, *format); continue; } - if (*format == 'X') { - pc += printi(out, out_len, - va_arg(args, unsigned int), 16, 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 == 'u') { - pc += printi(out, out_len, - va_arg(args, unsigned int), 10, 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 == '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') { /* char are converted to int then pushed on the stack */ From patchwork Tue Jul 4 13:12:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1803209 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=xLYasdiI; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=QQyGxVFJ; 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=qP2bMMBk; 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 4QwNWV4z0hz20Pf for ; Tue, 4 Jul 2023 23:12:54 +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=9I3WNDo9NHPZJWCfg5COGLNJud9XOuQWFGflo67jzjY=; b=xLYasdiIB6ciZw +n8QqUtLcdstrhwruoHRVZd62dgoBt8sImlVd2Sx2sSWxntv2yTyfpzIUJT2WvWVUuAmjKgZoxqVb AZ4v01gvfE2GHxpLWyiKl7h8y4YNrvSxkWlVquIsr8LiWTSFjopTUaKkyhWmxPu7dWOASY+YATA4r 9nmqwAu6CLGjngzIQGphSep+wqHr8CgP//K0hzjBtX/gxCsHpsk4Z2SbQYiI9Ia6PjPxAbLm7ZB8+ AgG+HqoBNElyOO8qsnFUOFsRvlgNXCeBDrO6XWNka+uk+2Uz3E45t8pzHuBp3kcrz9ExI4gz/g1vW VAqCuSpqMNXXhYo/+3lA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qGfpg-00DLRT-1v; Tue, 04 Jul 2023 13:12:40 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qGfpe-00DLQc-2o for opensbi@bombadil.infradead.org; Tue, 04 Jul 2023 13:12:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=OBh7JwDa2PKEUkmDLQRxkCKYOhsCcyEXSnNKWPTCAVs=; b=QQyGxVFJDWw22L5zbaRjwHAsvA Jk+SR7jsYtsjn1d4ghJeBpB86E5lrZ4aeC4Cs71aj4XKttc1oRtJfwW16IritzK92am5Fbk49OVTB FtzqYekxrm/3yF3EvhkrrkQR65BxzRvrOdx9ztNcy3LrV1gwjtX6TvTNFl/hdnV9l9tbpHZSzUP+e cJb7dBmOf8TLBuqaKIx2fMu/Zup2JapNTmt6PLj3WTSb3f2kVM4o8jG2utxel4RwEPJcTNA/A8sMl zoh+AhNNs0TerCZ+ICDQXxr2lcFFg93u+f1ufbX1ojNaOy28kydAeBU+0UeafciClum3Yyz9cKfg8 UTV4Dk8g==; Received: from m126.mail.126.com ([220.181.12.36]) by desiato.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qGfpa-00AvJH-1G for opensbi@lists.infradead.org; Tue, 04 Jul 2023 13:12:37 +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=OBh7J wDa2PKEUkmDLQRxkCKYOhsCcyEXSnNKWPTCAVs=; b=qP2bMMBkDjSwH5M0/i3PB zedkHsh6334A1GiFm/WE2ZeKcKZGDI0fjrJDpku3RWO1DYlU7r3g48pSTIVAJU+e PidarwCMe75vt/qhVxT76D+RSEH+YnAjY2Xd5vmsC/EZM1WGn941bDeK05tz5dk2 QBmQf7WhmEOs9m/npEKWe8= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g1-0 (Coremail) with SMTP id _____wCXJ8CyGqRkGritAQ--.14207S8; Tue, 04 Jul 2023 21:12:21 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v7 06/11] lib: sbi: print add 'o' type Date: Tue, 4 Jul 2023 21:12:03 +0800 Message-Id: <20230704131208.465914-7-wxjstz@126.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230704131208.465914-1-wxjstz@126.com> References: <20230704131208.465914-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wCXJ8CyGqRkGritAQ--.14207S8 X-Coremail-Antispam: 1Uf129KBjvJXoW7tF1DKFy8JFyUCFW7JryDtrb_yoW8GF45pw n0yFyDt3WSyry3Ar9Iq3yxAFy5Z3s8Jryj9rZrGFW5WFn3CFykKr15GryYyrn7Krn8JFW3 Cw1rJw15tFWjgFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0p_6wZ8UUUUU= X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi5BqiOlpEGNljngAAsE X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230704_141235_719780_D0A8FAE9 X-CRM114-Status: UNSURE ( 6.45 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.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: Add o type for print to print octal numbers Signed-off-by: Xiang W Reviewed-by: Anup Patel --- 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 7dd023f..2a43e16 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -327,7 +327,8 @@ static int print(char **out, u32 *o [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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 Add o type for print to print octal numbers Signed-off-by: Xiang W Reviewed-by: Anup Patel --- 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 7dd023f..2a43e16 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -327,7 +327,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; @@ -341,7 +342,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; @@ -351,7 +352,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 Tue Jul 4 13:12:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1803211 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=mJFtbuwg; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=TRxfZpfs; 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=PHAk5syc; 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 4QwNXS5c1Zz20Pf for ; Tue, 4 Jul 2023 23:13:44 +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=kx1f9V5+efHn8BKA3QzMEf9GwVKUmy4CJmX+zzm0sok=; b=mJFtbuwgpaKCB+ u6SNCTbPbPXlNvmgv5TLR336+BV4hKWppd3SxhGCSon3FnV/ztP32u2ackbm8VCkWtDm6jVumfmUh wSZ5BZBWrunLX1iOaTIpVaFLsgr1Ucna0g5uLBlzYkJ/Iy2MCMixBN0zJN3nUCFv9IkwLW9uehX7W sovqVccr9o0VoelFyPhX77tUMml67507J5WBFg6sJ3H9EOWsaH5I6apmkpYRJzgovq8Cum94TyegK 4ETwnuWsDJ0bw+2xxmrrHzpk027sFEmyyIck9bSR5PpiZzfZlBRuiv9DIPiX0kPUWQpjiC1vbECcg ug59ATQeDFyFAGzHinjg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qGfqU-00DLrK-1N; Tue, 04 Jul 2023 13:13:30 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qGfqS-00DLq3-39 for opensbi@bombadil.infradead.org; Tue, 04 Jul 2023 13:13:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=vNpqWkg5iu0fyBhx2i7x8pIbkAjiCRpouofnfbjulSg=; b=TRxfZpfsSNLdH68O/nK9Qyhr+s lhlQVOuVur+dVMZdioqRa+RvwnedA35Y8foJ6BnJdJB9JF/ovasUctFp9Y9jC10BLuP28lsPbCWID vzA+Y/R1Z2OlRL1tFEyHQ94715IRzcYpsBJnb3IuSRchz5e/kZ0gMowokkMppbmmd9zmMknwXQUsV Yq1yQTrpP7RTiKup+JuPANkX8yhjC78jUFyX5eKL6JK2rr7H4HTxv9ffGFktspJcm2gjpuS2edOwZ x9cEdm4X2idNYXHd/xlOiaMIMj/XlstM/K/pevNYbuX5qyqYkQSk3oiA4Tl9P8oAfRBPL06ma6A/e TFbi7TwQ==; Received: from m126.mail.126.com ([220.181.12.27]) by desiato.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qGfqL-00AvLa-0W for opensbi@lists.infradead.org; Tue, 04 Jul 2023 13:13:24 +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=vNpqW kg5iu0fyBhx2i7x8pIbkAjiCRpouofnfbjulSg=; b=PHAk5syckZLZOTrJfN4ne M6UMh/smTjcZYVCCDPjz3QVkBgX+DvPR741mrIHrl42arSDkmVP/2tpCm2H6Vwce jrx1OD+IpQ4R9Ln49TFWVCdVR0bILDvAMCoxwY2+kFpIaYRiZyBX10Zg2cWt+z4o ssvYjmvRZhnjCrGAE8MzWI= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g1-0 (Coremail) with SMTP id _____wCXJ8CyGqRkGritAQ--.14207S9; Tue, 04 Jul 2023 21:12:21 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v7 07/11] lib: sbi: Fix printi Date: Tue, 4 Jul 2023 21:12:04 +0800 Message-Id: <20230704131208.465914-8-wxjstz@126.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230704131208.465914-1-wxjstz@126.com> References: <20230704131208.465914-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wCXJ8CyGqRkGritAQ--.14207S9 X-Coremail-Antispam: 1Uf129KBjvJXoWrKFy3AF1rJFyftr13AF1rCrg_yoW8JrWkp3 WSk3Z3Xw40qrn3JrZxXw12q3Z5J3y8Ja1qkr93Jw18ZF4rZa1rAw45tw1rtrZrGayfA343 Ja45AF4UWF4UX3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0p_6wZ8UUUUU= X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi1xeiOl53bj3WtAAAsA X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230704_141322_614887_23D98EBA X-CRM114-Status: UNSURE ( 8.42 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.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 Reviewed-by: Anup Patel --- 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_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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 Reviewed-by: Anup Patel --- 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 2a43e16..963d19f 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 Tue Jul 4 13:12:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1803207 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=lpBuAjb1; 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=PUXVd2ms; 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 4QwNWS47BNz20Pf for ; Tue, 4 Jul 2023 23:12:52 +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=p47rlGIfCaLYIOAGmwoI8Y+kfPem1ilR5kN+IoKDcVw=; b=lpBuAjb1twupwP YhfBlNMNwhaeGQVXD798TU2hVZE4eJG/4++iw1nov9EvoMCMJwvF1IJSBPL7hMbTTTej00f2RL4LJ V+9BCCa2bYJFzc+2pR1ecd1G0UCFDGxHCGZqEiwxV4Snp132JMbkhKlLa2KUSUKkXywOJxZ+lMFEP cMQSUUHftDXnNerV9wkSB+rI4fPqHt86LTdnGRPchpKJg/y6F079UTGtf5kv3D6lAEwNoUntdCLCl orBLa73lVzgfMi6H9Y3hjPf4V9kl9tune+tawsd0G1ubRhNUDoEgfNwl7YmetmgBZFfdgtRlSlY4N uDC/Fk/VmJs30amF6MBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qGfpb-00DLPP-16; Tue, 04 Jul 2023 13:12:35 +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 1qGfpX-00DLMF-1U for opensbi@lists.infradead.org; Tue, 04 Jul 2023 13:12:34 +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=UtTl7 yPZOqVgRjwIl85pYLY1vNnWudJ5vb1+Z6CvR1Y=; b=PUXVd2ms/pvNuWjzOA8rY BGxd/92UGc4jiQbfG6DxxeqvKMj00sixvZRKRb4/6N+/KWA3Sqjfv1bXELipDvdO WMH1pIedzQf0BPm/5VFxSmaaYHWQMwMilY2+zRQVAVIdNiGksrim8CKJBvwIgIcC z0h6lRkeEq76u+HG6V+hZI= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g1-0 (Coremail) with SMTP id _____wCXJ8CyGqRkGritAQ--.14207S10; Tue, 04 Jul 2023 21:12:21 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v7 08/11] lib: sbi: Simplify prints Date: Tue, 4 Jul 2023 21:12:05 +0800 Message-Id: <20230704131208.465914-9-wxjstz@126.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230704131208.465914-1-wxjstz@126.com> References: <20230704131208.465914-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wCXJ8CyGqRkGritAQ--.14207S10 X-Coremail-Antispam: 1Uf129KBjvJXoW7WF4UCF4xZr4UJFWktFW5Jrb_yoW8Jw1Upa n3K3ZrJw4Fvas5Ary8twnFgFyYyayUCFW2kr9rXr18ZFWDAay8Jr4fJF1Fya47GayUZFy5 u3WruF48X3Wj9r7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0p_6wZ8UUUUU= X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi5BeiOlpEGNljiAAAsf X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230704_061231_856339_B27C9063 X-CRM114-Status: GOOD ( 10.03 ) 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 Reviewed-by: Anup Patel --- 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 963d19f..43870b8 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 Tue Jul 4 13:12: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: 1803220 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=PsFpsRO5; 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=Cl8SPlCc; 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 4QwNs05mSKz20Pf for ; Tue, 4 Jul 2023 23:28: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=CAhlIpz6f1SJhH0HGIXSBFWriGi8NVSvisEwYUaN+9A=; b=PsFpsRO58iv8YS 2tpVCTpO57MhzcZlpsDQv521QsdtQ5y5wf8wkdW9N8zc8OZnrDoRtIuBiJFch5fyao1z6UVPIcxyz Iu0a1J0sLGxFnw/KSlu/NE6Sl/AfA0JABGSTJ6aph9fTUbP60w7E5hxMtxMYgF0MNQxzceG6uVAB5 k6e0vJiGDhQ+mXiowge8LhtrgJ/XZOIE+JJAYu8xlYigzI3j3YPdKk2XD3xW2NI8A4HHIXkCP0L5i sHZWBk3nUIjQWDCRN+YHn3lE0+5GYZ+XQboDYiFrYmZlNH3hTZAdu5SZzXVvL0kh2jgMafh1Bd/vv RsIfQtBJssCKLYYiaWkA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qGg4G-00DOWq-1N; Tue, 04 Jul 2023 13:27:44 +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 1qGg4D-00DOVe-0w for opensbi@lists.infradead.org; Tue, 04 Jul 2023 13:27:42 +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=flfM8 3tF+O/16Lm+O1snzNukZpK5MDrJYOsdsixqPCY=; b=Cl8SPlCcoUTfiG3VUJlXd U+4NYsXa4ubPxBmRgiDtW2j+JLX85RO2fseVgW4crFJWwY2tKps7TzEdyW4IbW55 dsqDFa8o6hUf6ivEziKid+jH55wYJrCP4B4SLut5Y7q3p0sZB8vuvE/HRrtUQDY8 Gd3NIcYVRpj+YRfj9z16+c= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g1-0 (Coremail) with SMTP id _____wCXJ8CyGqRkGritAQ--.14207S11; Tue, 04 Jul 2023 21:12:22 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v7 09/11] lib: sbi: Fix printc Date: Tue, 4 Jul 2023 21:12:06 +0800 Message-Id: <20230704131208.465914-10-wxjstz@126.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230704131208.465914-1-wxjstz@126.com> References: <20230704131208.465914-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wCXJ8CyGqRkGritAQ--.14207S11 X-Coremail-Antispam: 1Uf129KBjvdXoW7Gw15AFWrGw48GFykGF1kAFb_yoW3KFXEya yvyas8GrZ8AayYq3sFyrnYvrsFyw4xurn7WF15tr43Cry3tr4UGryjq3s0gFW8Xr47Cr9r Aa1j9r15Crya9jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7sRG_M37UUUUU== X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi1xqiOl53bj3WxQAAs8 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230704_062741_669047_77013551 X-CRM114-Status: UNSURE ( 9.05 ) 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: Because *out needs to reserve a byte to hold '\0', no more characters should be added to the buffer when *out has one byte left, and the buffer size *out_len should not be modified. this patch prevent [...] 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 Because *out needs to reserve a byte to hold '\0', no more characters should be added to the buffer when *out has one byte left, and the buffer size *out_len should not be modified. this patch prevents the correction of *out_len when *out_len is 1. Signed-off-by: Xiang W Reviewed-by: Anup Patel --- lib/sbi/sbi_console.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index 43870b8..af5e94b 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -142,10 +142,9 @@ static void printc(char **out, u32 *out_len, char ch) if (!out_len || *out_len > 1) { *(*out)++ = ch; **out = '\0'; + if (out_len) + --(*out_len); } - - if (out_len && *out_len > 0) - --(*out_len); } static int prints(char **out, u32 *out_len, const char *string, int width, From patchwork Tue Jul 4 13:12:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1803206 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=K1zAKnjn; 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=PO5jaAc0; 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 4QwNWQ6RHTz20Pf for ; Tue, 4 Jul 2023 23:12:50 +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=/Nnw9h21dfFu1EsQnJ6Zvd8mU+MHyvUtAhfbIr6KlRI=; b=K1zAKnjnRamAuQ OybJzvZ56YAYSiFMbaB0oZElCXJqdYWZaturPvb4wxjauUUCac1oiCGA+Gr7pm1czCJpGxdaXtBIA E31gF56TWk7ykldtJtGJc+8fRysFlZs1gS3KxQmAJI5TAswLhNIylDi6JM14tEnAHIDCRQScvhBqP FsNzvMwDAxt/6ekL3CL6qR1IuuuJfyBXT/AF0pqbbjz0FmO8U+5W8sIcv0RLZddzGSh4ZgsLXMNl1 2BtXiLU5LSZyjsgVQ2BZMcb/WzignTZ8ZQs81BtcxPfR0k0F0KslEvhOvWPRj/PGJTaIv/aB+qLeE alIW72qSuGZO93D4Di5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qGfpZ-00DLOX-2h; Tue, 04 Jul 2023 13:12:33 +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 1qGfpX-00DLMD-09 for opensbi@lists.infradead.org; Tue, 04 Jul 2023 13:12:32 +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=T7A1a N+RNJTcfrHloPZRBLVP8BOvSejV2qinPwt1SnI=; b=PO5jaAc0y4uhu9YmcElF/ A7y5YTifb746FyGqCBAhvqOwhf0T/Hh6dh0QUQ5MGYkuOzRJYzv3KtReNaklMNWO frXbjLmoMzTOICgdx5grHc3F4UY+FiZFSkuFTlLxcFIkK4WwG5CEI7ZbI8a+xrLA jbIReHHB/yg4PQ0BdXyAkI= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g1-0 (Coremail) with SMTP id _____wCXJ8CyGqRkGritAQ--.14207S12; Tue, 04 Jul 2023 21:12:22 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v7 10/11] lib: sbi: Fix timing of clearing tbuf Date: Tue, 4 Jul 2023 21:12:07 +0800 Message-Id: <20230704131208.465914-11-wxjstz@126.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230704131208.465914-1-wxjstz@126.com> References: <20230704131208.465914-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wCXJ8CyGqRkGritAQ--.14207S12 X-Coremail-Antispam: 1Uf129KBjvJXoWxXFWktr4DKFy8CFy7JFyftFb_yoW5CF13pF 4Sy3ZxXw4Fvas7JrW8Aan0gF4Yy34rCF4jkrsrXFy8ZFZ8Z3ykJrWfXF15tF1DCayUArW5 C3Z5Ja4UGw1jg3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziKsjbUUUUU= X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi5BeiOlpEGNljigAAsd X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230704_061231_433139_64D91B6C X-CRM114-Status: GOOD ( 10.78 ) 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: 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 | 35 +++++++++++++++++++ 1 file changed, 19 insertions(+), 16 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 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 | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index af5e94b..50af405 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -121,6 +121,7 @@ unsigned long sbi_ngets(char *str, unsigned long len) #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 va_start(v, l) __builtin_va_start((v), l) @@ -128,7 +129,7 @@ unsigned long sbi_ngets(char *str, unsigned long len) #define va_arg __builtin_va_arg typedef __builtin_va_list va_list; -static void printc(char **out, u32 *out_len, char ch) +static void printc(char **out, u32 *out_len, char ch, int flags) { if (!out) { sbi_putc(ch); @@ -142,8 +143,14 @@ static void printc(char **out, u32 *out_len, char ch) if (!out_len || *out_len > 1) { *(*out)++ = ch; **out = '\0'; - if (out_len) + if (out_len) { --(*out_len); + if ((flags & USED_TBUF) && *out_len == 1) { + nputs_all(console_tbuf, CONSOLE_TBUF_MAX - *out_len); + *out = console_tbuf; + *out_len = CONSOLE_TBUF_MAX; + } + } } } @@ -154,16 +161,16 @@ static int prints(char **out, u32 *out_len, const char *string, int width, width -= sbi_strlen(string); if (!(flags & PAD_RIGHT)) { for (; width > 0; --width) { - printc(out, out_len, flags & PAD_ZERO ? '0' : ' '); + printc(out, out_len, flags & PAD_ZERO ? '0' : ' ', flags); ++pc; } } for (; *string; ++string) { - printc(out, out_len, *string); + printc(out, out_len, *string, flags); ++pc; } for (; width > 0; --width) { - printc(out, out_len, ' '); + printc(out, out_len, ' ', flags); ++pc; } @@ -215,18 +222,18 @@ static int printi(char **out, u32 *out_len, long long i, if (flags & PAD_ZERO) { if (sign) { - printc(out, out_len, sign); + printc(out, out_len, sign, flags); ++pc; --width; } if (i && (flags & PAD_ALTERNATE)) { if (b == 16 || b == 8) { - printc(out, out_len, '0'); + printc(out, out_len, '0', flags); ++pc; --width; } if (b == 16) { - printc(out, out_len, 'x' - 'a' + letbase); + printc(out, out_len, 'x' - 'a' + letbase, flags); ++pc; --width; } @@ -265,15 +272,11 @@ static int print(char **out, u32 *out_len, const char *format, va_list args) } 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; - } - + width = flags = 0; + if (use_tbuf) + flags |= USED_TBUF; if (*format == '%') { ++format; - width = flags = 0; if (*format == '\0') break; if (*format == '%') @@ -371,7 +374,7 @@ static int print(char **out, u32 *out_len, const char *format, va_list args) } } else { literal: - printc(out, out_len, *format); + printc(out, out_len, *format, flags); ++pc; } } From patchwork Tue Jul 4 13:13:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1803212 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=ZoeprGbr; 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=mwNEnsB1; 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 4QwNXT6wBcz20Pf for ; Tue, 4 Jul 2023 23:13:45 +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=tgB8pNMlmE1fGeKjLe7rI0xLcxj1L4z46ANUf1RBhYQ=; b=ZoeprGbrxRTpgh Qyp5eTAjTE2KyHJTVaGpCslHLKJuoJMJ4FK7Ilf/1tgkhkDHsjsRvKxTqz4RDd/XuErYi0VU9MwLO AYMcp6tR+Wx6AssqqEt9N6nfisBJcxwujp9+h9436OxQlKZV92kRLjZboM4yqjBSCjBFtyrvO+6Ev 1lKFD3a7fTGBNKlib0iJkC9YyLkxVDFjqgtIH24qig4StM7V2Pq2VJHqjcdAx0EsQkSTkL3tcG09/ c44zY8lu8iDDy3Zaim8OAkyTv4AMwUuPD6Wn0orcB4/59aqFo97qe3pYKeS08GCJREp1lGgTd2ElD 6Z7wPpxoe+ZiVOjox6DQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qGfqV-00DLs1-2t; Tue, 04 Jul 2023 13:13:31 +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 1qGfqT-00DLpn-1F for opensbi@lists.infradead.org; Tue, 04 Jul 2023 13:13:30 +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=aZwzr Rn02khF+yTTQErfBfPgmsl+jr/v5rbq1En1oWE=; b=mwNEnsB1P6Y6IyfPcfpMV XCXiSgQpu7vk5G1imr1HYSoBlauqaVC5p0jgvobb0yLAKeQQvKUI8hNsdXc/jJyG m/Ou/Mskww2bo04BOLQ2TtmTkeMdYFe5kN3SkH2eEEzpB8Jlc7s8JiRfiDF7vPY/ 1awh79G6ggCvq9wgJPL1/Y= Received: from x390.lan (unknown [58.247.180.222]) by zwqz-smtp-mta-g4-1 (Coremail) with SMTP id _____wAXqgLtGqRkjdqiAQ--.14425S2; Tue, 04 Jul 2023 21:13:18 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org, jrtc27@jrtc27.com Subject: [PATCH v7 11/11] lib: sbi: Fix missing '\0' when buffer szie equal 1 Date: Tue, 4 Jul 2023 21:13:16 +0800 Message-Id: <20230704131316.466246-1-wxjstz@126.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230704131208.465914-1-wxjstz@126.com> References: <20230704131208.465914-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wAXqgLtGqRkjdqiAQ--.14425S2 X-Coremail-Antispam: 1Uf129KBjvdXoWrZF1fCF18Ww4xZF45ZF1rtFb_yoWxZrc_Ja 4kCas8KrZ8Za909rnrtFn0yr4avw4fAwnrWFWUtFs8C3429wsrWFyjq3sxKw1DGr17Cr92 yrWUCrn7Cry3WjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_iiStUUUUU== X-Originating-IP: [58.247.180.222] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbiFxOiOlpEGpr1twAAsA X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230704_061329_802045_48074882 X-CRM114-Status: UNSURE ( 7.14 ) 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, out_len, ...) when out_len equal 1, The previous code will not fill the buffer with any char. Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 4 ++++ 1 file changed, 4 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 Fix special case: sbi_snprintf(out, out_len, ...) when out_len equal 1, The previous code will not fill the buffer with any char. 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 50af405..4f7c4ca 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -271,6 +271,10 @@ static int print(char **out, u32 *out_len, const char *format, va_list args) out_len = &console_tbuf_len; } + /* handle special case: *out_len == 1*/ + if (out) + **out = '\0'; + for (; *format != 0; ++format) { width = flags = 0; if (use_tbuf)