From nobody Sat Jul 25 15:19:00 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1784253245; cv=none; d=zohomail.com; s=zohoarc; b=CKEWEqbXYFxsso8WcZT1mc219b3QRDCH6o1dIAUEY3IAriSrnJpWTphW2jC12+XU8SKyXnssTf2aVcifgaKGx3LGpITquB0HP5EFkILrxIyScd4SeHfpWmW5ExZdL8lUN2xxxCrqtLvLnlrRdhpIN4z+sXHARGKaYDjPclvLk7k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784253245; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SSHr8TvCT7xeDPjBLGzUoDIlbiu1tCB3FhDjMALkW5g=; b=d9ZMqVFAlInQZBPILhMFewOH27cNeTEOMKwua6d7dQ3VOjh/cpQUKIw0HePm7tHsib+ZpTamg3P/qpUPqwVRqHZ4HwTWSL1rxfKkRX4b16x8SbwT/Q3gR9sIBIdvyDf3b9g6BSN76zCRdkLKryn4MR8NrSWl7R2w1G6P9p4iD1E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784253245551250.23175170839625; Thu, 16 Jul 2026 18:54:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkXlW-0001Zu-Dt; Thu, 16 Jul 2026 21:53:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkXlT-0001ZJ-5A for qemu-devel@nongnu.org; Thu, 16 Jul 2026 21:53:24 -0400 Received: from [115.124.30.112] (helo=out30-112.freemail.mail.aliyun.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkXlJ-00029o-9A for qemu-devel@nongnu.org; Thu, 16 Jul 2026 21:53:22 -0400 Received: from localhost(mailfrom:guobin@linux.alibaba.com fp:SMTPD_---0X7FeezJ_1784253173 cluster:ay36) by smtp.aliyun-inc.com; Fri, 17 Jul 2026 09:52:54 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1784253175; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; bh=SSHr8TvCT7xeDPjBLGzUoDIlbiu1tCB3FhDjMALkW5g=; b=QEZ5ko/aqq4gZSbNMiDStf0PtZcg+7dToqBo4DP9vyAHMwicWjeLs8FJLONlymhy/5AALA1yz8gQuxSVJhVSL0+QH+0ideRySZPezQT4nSD0mNoBQrWbkgteySF2glyKcFR/B1YvWVf+qzHW9jPsUAhtMtXyz63KqIFWEstTzsY= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R161e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033045133197; MF=guobin@linux.alibaba.com; NM=1; PH=DS; RN=6; SR=0; TI=SMTPD_---0X7FeezJ_1784253173; From: Bin Guo To: qemu-devel@nongnu.org Cc: mst@redhat.com, alex.bennee@linaro.org, odaki@rsg.ci.i.u-tokyo.ac.jp, dmitry.osipenko@collabora.com, marcandre.lureau@redhat.com Subject: [PATCH] virtio-gpu: use BIT() macro for scanout bitmask operations Date: Fri, 17 Jul 2026 09:52:52 +0800 Message-ID: <20260717015252.25675-1-guobin@linux.alibaba.com> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 115.124.30.112 (deferred) 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=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.112; envelope-from=guobin@linux.alibaba.com; helo=out30-112.freemail.mail.aliyun.com X-Spam_score_int: -166 X-Spam_score: -16.7 X-Spam_bar: ---------------- X-Spam_report: (-16.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1784253247502158500 The scanout_bitmask field is uint32_t, but all six bit operations used the signed literal `1 << shift`. When the shift count reaches 31 this is undefined behavior (signed integer overflow). Replace every occurrence with the BIT() macro to perform an unsigned shift, which is well-defined for all bit positions 0-31 and consistent with QEMU bit-operation conventions. No functional change; the result is already stored in a uint32_t, so the generated code is identical on most platforms. Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Bin Guo Reviewed-by: Akihiko Odaki --- hw/display/virtio-gpu.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index c20efe4fb9..cd07b70a05 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -12,6 +12,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/bitops.h" #include "qemu/units.h" #include "qemu/iov.h" #include "system/cpus.h" @@ -393,7 +394,7 @@ void virtio_gpu_disable_scanout(VirtIOGPU *g, int scano= ut_id) =20 res =3D virtio_gpu_find_resource(g, scanout->resource_id); if (res) { - res->scanout_bitmask &=3D ~(1 << scanout_id); + res->scanout_bitmask &=3D ~BIT(scanout_id); } =20 qemu_console_set_surface(scanout->con, NULL); @@ -411,7 +412,7 @@ static void virtio_gpu_resource_destroy(VirtIOGPU *g, =20 if (res->scanout_bitmask) { for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { - if (res->scanout_bitmask & (1 << i)) { + if (res->scanout_bitmask & BIT(i)) { virtio_gpu_disable_scanout(g, i); } } @@ -577,7 +578,7 @@ static void virtio_gpu_resource_flush(VirtIOGPU *g, for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { QemuRect rect; =20 - if (!(res->scanout_bitmask & (1 << i))) { + if (!(res->scanout_bitmask & BIT(i))) { continue; } scanout =3D &g->parent_obj.scanout[i]; @@ -611,10 +612,10 @@ void virtio_gpu_update_scanout(VirtIOGPU *g, scanout =3D &g->parent_obj.scanout[scanout_id]; ores =3D virtio_gpu_find_resource(g, scanout->resource_id); if (ores) { - ores->scanout_bitmask &=3D ~(1 << scanout_id); + ores->scanout_bitmask &=3D ~BIT(scanout_id); } =20 - res->scanout_bitmask |=3D (1 << scanout_id); + res->scanout_bitmask |=3D BIT(scanout_id); scanout->resource_id =3D res->resource_id; scanout->x =3D r->x; scanout->y =3D r->y; @@ -1496,7 +1497,7 @@ static int virtio_gpu_post_load(void *opaque, int ver= sion_id) if (scanout->cursor.resource_id) { update_cursor(g, &scanout->cursor); } - res->scanout_bitmask |=3D (1 << i); + res->scanout_bitmask |=3D BIT(i); } =20 return 0; --=20 2.50.1 (Apple Git-155)