From patchwork Sat Feb 11 12:52: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: 1740888 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=r6XdbNCA; 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=nEsrfY7e; 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 4PDWX154Lgz23hX for ; Sun, 12 Feb 2023 00:23:43 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=3ORFRH9Vtw5HNVJGB6/fuXM0D3+KzEK41pxlJnALRZU=; b=r6XdbNCAR8oHpk uH9Hx76iHl3ugxDrzZUrq6IXEhgL07BSAxhpILuyA9G/MKJUbILjvPSIWK3aWnPANjoRViywUMh1x Uq6pxWCNwDubWb9m1rtt5OHYvZtqI7t6+1/nD8Xj9XBv0OXM8jKG1ZK3IAypYk7hLwdIO1frPId15 POxBSb0PJb5DsXhRARSrMMQQRYz8QJ+YQbBCDJSxSXL8SKQ3+0h5DFaZRy/llcoD1UKWET/JCL+WH OIZwZHhUV7hSEhVZB9cUXUbBnAvexVfKMww/AXTTrMyM09GKhTeUsHHzJDf5VLCNFtV0p2nJwm2Pk CTd/EcUMNb9MAVkkMaVg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pQpqU-009YOi-Dk; Sat, 11 Feb 2023 13:23:14 +0000 Received: from m126.mail.126.com ([123.126.96.241]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pQpqQ-009YNx-0W for opensbi@lists.infradead.org; Sat, 11 Feb 2023 13:23:12 +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=dSUnC wZZWB8sVjx9vKCRJh8zKlVG+syfEX2oKSqxDUE=; b=nEsrfY7egNmnJk9BwCq/a MfyUo9g04F5ld/UskrFv3ay1SUSbpRo805VBHzR0UizT+Pl+i+NKyc4U3Qtidg7z R8PjE1lZDpPlKXVKW6X8h3pAWPGjOfXM2GP6Jx9YQxJMQ6zcroFZa6XFp4O3yo0H eDsZKQtR+/mtPs9wwPlnUQ= Received: from x390.lan (unknown [101.86.235.251]) by smtp15 (Coremail) with SMTP id f+RpCgAnGNZyj+djt_1LAw--.22571S2; Sat, 11 Feb 2023 20:52:04 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W Subject: [PATCH] lib: sbi: fix missing '\r' for console Date: Sat, 11 Feb 2023 20:52:00 +0800 Message-Id: <20230211125200.10381-1-wxjstz@126.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-CM-TRANSID: f+RpCgAnGNZyj+djt_1LAw--.22571S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7urWrZF4UCr1xury8uF4Durg_yoW8KrWrpr s3Ka13tr4FqFySqrySqr9rWF1rW3WkKw15trW7Awn7Za4DAay8Z3y3Xw1Yv3y3J34UZF1U AF9aqF95CF48XaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pR6T5LUUUUU= X-Originating-IP: [101.86.235.251] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbiIRQTOmIxlThnEQAAsU X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230211_052310_511369_236D2A48 X-CRM114-Status: UNSURE ( 9.90 ) 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: print is finally implemented by sbi_putc or console_dev->puts. sbi_putc will add a \r before the output \n. This patch adds missing \r when outputting characters via console_dev->puts. Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 46 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+), 15 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 print is finally implemented by sbi_putc or console_dev->puts. sbi_putc will add a \r before the output \n. This patch adds missing \r when outputting characters via console_dev->puts. Signed-off-by: Xiang W --- lib/sbi/sbi_console.c | 46 +++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index f3ac003..7dc053a 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -46,27 +46,43 @@ void sbi_putc(char ch) } } +static unsigned long console_puts_all(const char *str, unsigned long len) +{ + const char *s = str; + const char *e = s + len; + while (s < e) + s += console_dev->console_puts(s, e - s); + return len; +} + +static unsigned long console_puts(const char *str, unsigned long len) +{ + const char *s, *p, *e; + s = str; + e = str + len; + while (s < e) { + p = sbi_strchr(s, '\n'); + p = p ? p : e; + console_puts_all(s, p - s); + if (*p == '\n') + console_puts_all("\r\n", 2); + s = p + 1; + } + return len; +} + static unsigned long nputs(const char *str, unsigned long len) { - unsigned long i, ret; + unsigned long i; if (console_dev && console_dev->console_puts) { - ret = console_dev->console_puts(str, len); + console_puts(str, len); } else { for (i = 0; i < len; i++) sbi_putc(str[i]); - ret = len; } - return ret; -} - -static void nputs_all(const char *str, unsigned long len) -{ - unsigned long p = 0; - - while (p < len) - p += nputs(&str[p], len - p); + return len; } void sbi_puts(const char *str) @@ -74,7 +90,7 @@ void sbi_puts(const char *str) unsigned long len = sbi_strlen(str); spin_lock(&console_out_lock); - nputs_all(str, len); + nputs(str, len); spin_unlock(&console_out_lock); } @@ -255,7 +271,7 @@ 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); + nputs(console_tbuf, CONSOLE_TBUF_MAX); console_tbuf_len = CONSOLE_TBUF_MAX; tout = console_tbuf; } @@ -386,7 +402,7 @@ literal: } if (use_tbuf && console_tbuf_len < CONSOLE_TBUF_MAX) - nputs_all(console_tbuf, CONSOLE_TBUF_MAX - console_tbuf_len); + nputs(console_tbuf, CONSOLE_TBUF_MAX - console_tbuf_len); return pc; }