From patchwork Mon Feb 13 09:09:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1741473 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=Hd1g9/X3; 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=EOl4kS6G; 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 4PFdqC2KjDz23qt for ; Mon, 13 Feb 2023 20:10:47 +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=zEQ4X7E0TLrMrPcMka1Ss0bgZjb1bI4Hdeew9C8pcFE=; b=Hd1g9/X3YvVoYM 9GJJOTyNe/yL/HrIkrTSfYG3w4tDwsDei/nZfEsKIhGKuUTXInLD5POaDTkxhEvrbY9Gnd8zA6iiL 5mS0IRZXiLqvaAaaTX1NSlYI4Gfl2nIfvlcqHJ5UqT00me+iAUYUnqt6htp2EZK8aihO+5surBH+G QyN7jvbGVqO2yPqIkwGpauRrChy1bMKLyoNEAX7uoZMlHhAveyXUMtwToTRyr1FN1DTSuF7sMHuh5 JCxEk+XgdRGz8EAiD9KYtI5FwtP43T6HaC+IHeKFiP83n4e0dZQ/NpqIfjRHcwn65AgfSd8en3MVc Qf8AUq5LUkm3jp1P2arw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pRUr2-00DkgP-Li; Mon, 13 Feb 2023 09:10:32 +0000 Received: from m126.mail.126.com ([123.126.96.242]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pRUqy-00Dkes-Ej for opensbi@lists.infradead.org; Mon, 13 Feb 2023 09:10: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=b3+lL zmTz/Z5nNyV6folwxucy6ZDSEE5uS43lUjaFa0=; b=EOl4kS6G9IKG5r0gxCW/Q 3C0wKvwmTk5mnPQU65JShas0qu5hgvkl6rYpFMCmMT9Hgot1Ptaef0Z2W/Zo5Ej9 oa7Cp4Y6SxnAAw5iOSEOCXX4LOaexAeJJCGbui7C1o1k4E66W4tFMgCRgeFu1IfA 5PfytHNwng4TSApeRP9smM= Received: from x390.lan (unknown [58.247.140.37]) by smtp15 (Coremail) with SMTP id f+RpCgAXh9eB_uljOE2WAw--.10380S2; Mon, 13 Feb 2023 17:10:26 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W Subject: [PATCH v4] lib: sbi: fix missing '\r' for console Date: Mon, 13 Feb 2023 17:09:30 +0800 Message-Id: <20230213090929.144906-1-wxjstz@126.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-CM-TRANSID: f+RpCgAXh9eB_uljOE2WAw--.10380S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7urWrZF43WrW7KF15AFW7XFb_yoW8WFW3pF sxGay5trWFqF9aqas3Xrn7Wr1rGF1Iyay7trWxtwn7XF1DJay0v3y3Xw1Yv3y3ZryUXFyU Aa95tFyDCF4UX3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pRY-erUUUUU= X-Originating-IP: [58.247.140.37] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbiFwIVOlpEFt2EIgAAsJ X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230213_011029_186259_E7E5E7B0 X-CRM114-Status: GOOD ( 11.23 ) 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 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 Changes since v4: - nputs_all come back - implement partial writes as much as possible Changes since v3: - Prevent string overflow when looking for \n Changes since v2: - Fix the bug reported by Samuel. Prevent p from accessing memory other than strings. --- lib/sbi/sbi_console.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index f3ac003..4be5a8f 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -46,12 +46,41 @@ 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) +{ + unsigned long l; + const char *s, *p, *e; + s = str; + e = str + len; + while (s < e) { + p = sbi_strchr(s, '\n'); + if (p == NULL || p > e) + p = e; + l = console_dev->console_puts(s, p - s); + if (l < p - s) + return s - str + l; + if (p < e && *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; if (console_dev && console_dev->console_puts) { - ret = console_dev->console_puts(str, len); + ret = console_puts(str, len); } else { for (i = 0; i < len; i++) sbi_putc(str[i]);