From nobody Wed Jan 15 09:25:55 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167141691086783.4389599524012; Sun, 18 Dec 2022 18:28:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p75jp-0001Mj-VF; Sun, 18 Dec 2022 21:18:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p75jo-0001Ja-9J for qemu-devel@nongnu.org; Sun, 18 Dec 2022 21:18:44 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p75jl-0001CG-OK for qemu-devel@nongnu.org; Sun, 18 Dec 2022 21:18:44 -0500 Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Dec 2022 10:18:39 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Dec 2022 17:36:56 -0800 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Dec 2022 18:18:40 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Nb3KW5dNNz1RvLy for ; Sun, 18 Dec 2022 18:18:39 -0800 (PST) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id gUh26rFpdbTD for ; Sun, 18 Dec 2022 18:18:39 -0800 (PST) Received: from toolbox.alistair23.me (unknown [10.225.167.4]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Nb3KT4d43z1RwtC; Sun, 18 Dec 2022 18:18:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1671416321; x=1702952321; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FTpM9wSisWlcMO9trrZZ4PMyQatiOo+GCvuYX47JsM8=; b=PjohIRUfWE/m739Vn2FsCTdCkmpZ2tNQBZTl5RWRTNkHn2CaNqgxIur/ vgsmu69+2odwJfsXPlVA1Jqldo3Ccbmc9b8iBZNApYEcSyjsGC2IY8ctU OnujlpHGOZeHWd3moxyCK8sFNq9jS3bMXHqIhelLkRJ+Kq0s3k8L6YFrQ +HcIo8GClg05fAPZLa4EdfY9lJmVFN6J04ANYdEgckQbRKuP/SOdzXbTC c7DXdCnimr3GjBvttS8SQ2/yBAW1y6O6sSTgL7oLSq25f++msIQ51PYuX FM3fTe5Y2sKzbWtwlxxBs8QEm1P/khDMV+Q950DD0RKCM6UtjsXPGJ5hQ g==; X-IronPort-AV: E=Sophos;i="5.96,254,1665417600"; d="scan'208";a="331056813" IronPort-SDR: jKhYm1P2VpALGoAfnT4oqxjnmhg5mtQJSwgkteSkf5QnSsDXuuPASUy1PSRT7FVe1qIIvvcvdV x0nuvOwMOSg1K6i0WyW9umXeWAvqIX8+hsEl3sMckYh0ehkeMjoFHetoW15j4xSdZn1tGrtHyx q0+2HniFix4Sq1pNZDTwInKh6MsFReWzhiLaI4DUoLCQYwfV7D2AD5IS9B7Kg7TtIESB0ozJBb VUsVve7Uplme3igtYrdyiqOT5Ad4LpTZUGWoOE38WuwUyZFSZBy/r68G1cUsFM2EweyY6O9JF1 kXM= IronPort-SDR: wb/TyGuyCCPxEIeDox7ECx0kWhapbHpeB2r3wL+g945x0UAoeU75xoEDCsJXh0AEo5ZsUa3iuU 64W85acT1qDgR1sxW+LNyXG5muXtou02FtiKm4g189ZVC4DXdXFQx9PvFX2QwDX7Ole1YYbaUs bHnj1/s/AikYoaFw3+XHKYhDdk6esyLMaHiUFOuLvie6Tyn6p9UGdUmqgRKWci54L2Y5Z88HfG nTl/6xFOgUFsi1OuKy005MzEQtqEN9hckdxJTzPCakprxBIWKd32n/klYP7CwVFkMsr8RyZqs+ buo= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1671416319; x=1674008320; bh=FTpM9wSisWlcMO9trr ZZ4PMyQatiOo+GCvuYX47JsM8=; b=dG84+zZs87ozdbDHnhTZBsLZp5yRem7+xY BBMA8XaKxbm/OyZGWcLz8L4v8ZVm4c5wqH6hFWAOIvRTzNGhNPqa3DV/4jo8vBnL mgk7ZNLqBKFUEyGHGZ0Ti9k3NCb/uv9pT/dd/PtEUwBXBR5JgEwh19vnbvWHT7mS e7VgKbz0Y+lNaRuWEtdDuj/zcev9uPGZaAZv9vpHbfZjgZvcS457E2HFIlSDoRvj jYvUfiMF2mWsUP87F/PUuCR6eRgH4yungqizHgxr6UDpZzkc7YV6y9BADvECkWtm d042hlrMuqLEPXpSJxzRmmm9DU77VNO0D3YRprMEuY8McI5spVGw== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Bin Meng , Alistair Francis Subject: [PULL 36/45] hw/intc: sifive_plic: Improve robustness of the PLIC config parser Date: Mon, 19 Dec 2022 12:16:54 +1000 Message-Id: <20221219021703.20473-37-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221219021703.20473-1-alistair.francis@opensource.wdc.com> References: <20221219021703.20473-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=345d64987=alistair.francis@opensource.wdc.com; helo=esa1.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1671416911858100003 Content-Type: text/plain; charset="utf-8" From: Bin Meng At present the PLIC config parser can only handle legal config string like "MS,MS". However if a config string like ",MS,MS,,MS,MS,," is given the parser won't get the correct configuration. This commit improves the config parser to make it more robust. Signed-off-by: Bin Meng Acked-by: Alistair Francis Message-Id: <20221211030829.802437-7-bmeng@tinylab.org> Signed-off-by: Alistair Francis --- hw/intc/sifive_plic.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/hw/intc/sifive_plic.c b/hw/intc/sifive_plic.c index 936dcf74bc..c9af94a888 100644 --- a/hw/intc/sifive_plic.c +++ b/hw/intc/sifive_plic.c @@ -290,7 +290,7 @@ static void sifive_plic_reset(DeviceState *dev) */ static void parse_hart_config(SiFivePLICState *plic) { - int addrid, hartid, modes; + int addrid, hartid, modes, m; const char *p; char c; =20 @@ -299,11 +299,13 @@ static void parse_hart_config(SiFivePLICState *plic) p =3D plic->hart_config; while ((c =3D *p++)) { if (c =3D=3D ',') { - addrid +=3D ctpop8(modes); - modes =3D 0; - hartid++; + if (modes) { + addrid +=3D ctpop8(modes); + hartid++; + modes =3D 0; + } } else { - int m =3D 1 << char_to_mode(c); + m =3D 1 << char_to_mode(c); if (modes =3D=3D (modes | m)) { error_report("plic: duplicate mode '%c' in config: %s", c, plic->hart_config); @@ -314,8 +316,9 @@ static void parse_hart_config(SiFivePLICState *plic) } if (modes) { addrid +=3D ctpop8(modes); + hartid++; + modes =3D 0; } - hartid++; =20 plic->num_addrs =3D addrid; plic->num_harts =3D hartid; @@ -326,11 +329,16 @@ static void parse_hart_config(SiFivePLICState *plic) p =3D plic->hart_config; while ((c =3D *p++)) { if (c =3D=3D ',') { - hartid++; + if (modes) { + hartid++; + modes =3D 0; + } } else { + m =3D char_to_mode(c); plic->addr_config[addrid].addrid =3D addrid; plic->addr_config[addrid].hartid =3D hartid; - plic->addr_config[addrid].mode =3D char_to_mode(c); + plic->addr_config[addrid].mode =3D m; + modes |=3D (1 << m); addrid++; } } --=20 2.38.1