From nobody Sun Nov 9 20:18:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551815845094153.76591925538548; Tue, 5 Mar 2019 11:57:25 -0800 (PST) Received: from localhost ([127.0.0.1]:48496 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1GBm-0007HM-2Y for importer@patchew.org; Tue, 05 Mar 2019 14:57:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45355) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1GA3-0006HW-1e for qemu-devel@nongnu.org; Tue, 05 Mar 2019 14:55:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1GA2-0005rB-9l for qemu-devel@nongnu.org; Tue, 05 Mar 2019 14:55:34 -0500 Received: from smtp.duncanthrax.net ([2001:470:70c5:1111::170]:56945) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1GA1-0005kc-Qn for qemu-devel@nongnu.org; Tue, 05 Mar 2019 14:55:34 -0500 Received: from [134.3.47.207] (helo=t470p.stackframe.org) by smtp.eurescom.eu with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1h1G9x-0004To-V4; Tue, 05 Mar 2019 20:55:30 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=duncanthrax.net; s=dkim; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=e7FyrcRLh4e7VbGBOCB2JSF1j1+j3xQgs9+D2RzjISU=; b=TXhJp+mrKu/LC9OKhPqUjClfxI x7d30kPW0RYsyBsJfu0Hahm+9/jV9t3Fmfg7qaozoxCGcG+R1Rzs3HbrMGpJxY3MVaHewUnuI42ZW fcTatIXrny422ZWf4+NrpIuWuIX2KAOajgiifP3xGzZwdgGSPAeqXMCyk7n1Ql1FscU0=; From: Sven Schnelle To: Paolo Bonzini Date: Tue, 5 Mar 2019 20:55:15 +0100 Message-Id: <20190305195519.24303-2-svens@stackframe.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305195519.24303-1-svens@stackframe.org> References: <20190305195519.24303-1-svens@stackframe.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:470:70c5:1111::170 Subject: [Qemu-devel] [PATCH v2 1/5] lsi: use ldn_le_p()/stn_le_p() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sven Schnelle , QEMU Developers Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Instead of using the open-coded versions, use the helper already present as this makes the code easier to read and less error-prone. Signed-off-by: Sven Schnelle Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/scsi/lsi53c895a.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c index 5623da8950..5f336606b9 100644 --- a/hw/scsi/lsi53c895a.c +++ b/hw/scsi/lsi53c895a.c @@ -289,8 +289,7 @@ typedef struct { uint8_t sbr; uint32_t adder; =20 - /* Script ram is stored as 32-bit words in host byteorder. */ - uint32_t script_ram[2048]; + uint8_t script_ram[2048 * sizeof(uint32_t)]; } LSIState; =20 #define TYPE_LSI53C810 "lsi53c810" @@ -2079,29 +2078,14 @@ static void lsi_ram_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) { LSIState *s =3D opaque; - uint32_t newval; - uint32_t mask; - int shift; - - newval =3D s->script_ram[addr >> 2]; - shift =3D (addr & 3) * 8; - mask =3D ((uint64_t)1 << (size * 8)) - 1; - newval &=3D ~(mask << shift); - newval |=3D val << shift; - s->script_ram[addr >> 2] =3D newval; + stn_le_p(s->script_ram + addr, size, val); } =20 static uint64_t lsi_ram_read(void *opaque, hwaddr addr, unsigned size) { LSIState *s =3D opaque; - uint32_t val; - uint32_t mask; - - val =3D s->script_ram[addr >> 2]; - mask =3D ((uint64_t)1 << (size * 8)) - 1; - val >>=3D (addr & 3) * 8; - return val & mask; + return ldn_le_p(s->script_ram + addr, size); } =20 static const MemoryRegionOps lsi_ram_ops =3D { @@ -2244,7 +2228,7 @@ static const VMStateDescription vmstate_lsi_scsi =3D { VMSTATE_BUFFER_UNSAFE(scratch, LSIState, 0, 18 * sizeof(uint32_t)), VMSTATE_UINT8(sbr, LSIState), =20 - VMSTATE_BUFFER_UNSAFE(script_ram, LSIState, 0, 2048 * sizeof(uint3= 2_t)), + VMSTATE_BUFFER_UNSAFE(script_ram, LSIState, 0, 8192), VMSTATE_END_OF_LIST() } }; --=20 2.20.1