From patchwork Thu Dec 22 02:04:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 1718625 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=3jFTmZdQ; 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 4NcttD58fPz23dT for ; Thu, 22 Dec 2022 13:04:52 +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=hOHfDeJ/K5zi3DHh0iESrjMJALh1Dd1XGjACLqJD/ig=; b=3jFTmZdQBgaO0h oBKzD+TK48hdaypC541UViGEH2XxYjizLao0pCy6qK/8W1mizfWNw8Y+v/bti/DVrT8ddc8X7XG6y CGfyUT4Pt9fB4hAWjPgKfLcaRARYJibfoDoqVy9fUubJf36cnyydVm9PF3CmfllCH8qBCWAgXKNxc 4Y07G5cZET4y/mbjIbwkpGPBh2zJJ81Rt+yeWUwWTEsasj+78OcDPJ6bTKhi4afCb5cAEuJTiuUB3 D2L4bZavVmqLrNP8aPZRQUPbRgXFXhmsJbCWvCa7c0i7lKcwSH/UwhLu1491UOts4+yiFqVTpKw7T nO+6RhIXY4zCUGvXviDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p8Awe-005NSD-UM; Thu, 22 Dec 2022 02:04:28 +0000 Received: from 60-248-80-70.hinet-ip.hinet.net ([60.248.80.70] helo=Atcsqr.andestech.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p8Awa-005NNK-Pg for opensbi@lists.infradead.org; Thu, 22 Dec 2022 02:04:27 +0000 Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 2BM24EZI080309 for ; Thu, 22 Dec 2022 10:04:14 +0800 (+08) (envelope-from peterlin@andestech.com) Received: from atcfdc88.andestech.com (10.0.15.158) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Thu, 22 Dec 2022 10:04:10 +0800 From: Yu Chien Peter Lin To: CC: Yu Chien Peter Lin Subject: [PATCH] lib: utils/serial: Simplify semihosting_getc() function Date: Thu, 22 Dec 2022 10:04:03 +0800 Message-ID: <20221222020403.23209-1-peterlin@andestech.com> X-Mailer: git-send-email 2.38.0.68.ge85701b4af.dirty MIME-Version: 1.0 X-Originating-IP: [10.0.15.158] X-DNSRBL: X-MAIL: Atcsqr.andestech.com 2BM24EZI080309 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221221_180425_325072_107ED945 X-CRM114-Status: UNSURE ( 8.56 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.4 (/) 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: Simply pass the character returned by semihosting_trap(SYSREADC, NULL) on success, or -1 on failure. This also fixes issue [1] of comparison of constant -1 with char type. [1] https://github.com/riscv-software-src/opensbi/issues/269 Content analysis details: (0.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 TVD_RCVD_IP Message was received from an IP address -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS 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 Simply pass the character returned by semihosting_trap(SYSREADC, NULL) on success, or -1 on failure. This also fixes issue [1] of comparison of constant -1 with char type. [1] https://github.com/riscv-software-src/opensbi/issues/269 Signed-off-by: Yu Chien Peter Lin --- lib/utils/serial/semihosting.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/utils/serial/semihosting.c b/lib/utils/serial/semihosting.c index 5012fa1..cd15f91 100644 --- a/lib/utils/serial/semihosting.c +++ b/lib/utils/serial/semihosting.c @@ -151,15 +151,11 @@ static void semihosting_putc(char ch) static int semihosting_getc(void) { char ch = 0; - int ret; - if (semihosting_infd < 0) { - ch = semihosting_trap(SYSREADC, NULL); - ret = ch > -1 ? ch : -1; - } else - ret = semihosting_read(semihosting_infd, &ch, 1) > 0 ? ch : -1; - - return ret; + if (semihosting_infd < 0) + return semihosting_trap(SYSREADC, NULL); + else + return semihosting_read(semihosting_infd, &ch, 1) > 0 ? ch : -1; } static struct sbi_console_device semihosting_console = {