From nobody Sun May 5 07:50:53 2024 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; 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 155294879700231.256011441443547; Mon, 18 Mar 2019 15:39:57 -0700 (PDT) Received: from localhost ([127.0.0.1]:48451 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h60vB-0006nS-OA for importer@patchew.org; Mon, 18 Mar 2019 18:39:53 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54813) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h60uA-0006Lq-CK for qemu-devel@nongnu.org; Mon, 18 Mar 2019 18:38:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h60u8-0006D1-Qd for qemu-devel@nongnu.org; Mon, 18 Mar 2019 18:38:50 -0400 Received: from zero.eik.bme.hu ([152.66.115.2]:44504) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h60u5-00069I-Di for qemu-devel@nongnu.org; Mon, 18 Mar 2019 18:38:46 -0400 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 5F7377456BB; Mon, 18 Mar 2019 23:38:42 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 427CB7456B2; Mon, 18 Mar 2019 23:38:42 +0100 (CET) From: BALATON Zoltan Date: Mon, 18 Mar 2019 23:34:46 +0100 MIME-Version: 1.0 To: qemu-devel@nongnu.org Message-Id: <20190318223842.427CB7456B2@zero.eik.bme.hu> Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 152.66.115.2 Subject: [Qemu-devel] [PATCH] ati-vga: Fix indexed access to video memory 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: Peter Maydell , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Coverity (CID 1399700) found that this was wrong so instead of trying to do it by hand use existing access functions that should work better. Signed-off-by: BALATON Zoltan --- hw/display/ati.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/hw/display/ati.c b/hw/display/ati.c index 055cc69e16..b88309af63 100644 --- a/hw/display/ati.c +++ b/hw/display/ati.c @@ -236,12 +236,9 @@ static uint64_t ati_mm_read(void *opaque, hwaddr addr,= unsigned int size) case MM_DATA ... MM_DATA + 3: /* indexed access to regs or memory */ if (s->regs.mm_index & BIT(31)) { - if (s->regs.mm_index <=3D s->vga.vram_size - size) { - int i =3D size - 1; - while (i >=3D 0) { - val <<=3D 8; - val |=3D s->vga.vram_ptr[s->regs.mm_index + i--]; - } + uint32_t idx =3D s->regs.mm_index & ~BIT(31); + if (idx <=3D s->vga.vram_size - size) { + val =3D ldn_le_p(s->vga.vram_ptr + idx, size); } } else { val =3D ati_mm_read(s, s->regs.mm_index + addr - MM_DATA, size= ); @@ -440,12 +437,9 @@ static void ati_mm_write(void *opaque, hwaddr addr, case MM_DATA ... MM_DATA + 3: /* indexed access to regs or memory */ if (s->regs.mm_index & BIT(31)) { - if (s->regs.mm_index <=3D s->vga.vram_size - size) { - int i =3D 0; - while (i < size) { - s->vga.vram_ptr[s->regs.mm_index + i] =3D data & 0xff; - data >>=3D 8; - } + uint32_t idx =3D s->regs.mm_index & ~BIT(31); + if (idx <=3D s->vga.vram_size - size) { + stn_le_p(s->vga.vram_ptr + idx, size, data); } } else { ati_mm_write(s, s->regs.mm_index + addr - MM_DATA, data, size); --=20 2.13.7