From: Bin Guo <guobin@linux.alibaba.com>
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 [thread overview]
Message-ID: <20260717015252.25675-1-guobin@linux.alibaba.com> (raw)
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é Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Bin Guo <guobin@linux.alibaba.com>
---
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 @@
*/
#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 scanout_id)
res = virtio_gpu_find_resource(g, scanout->resource_id);
if (res) {
- res->scanout_bitmask &= ~(1 << scanout_id);
+ res->scanout_bitmask &= ~BIT(scanout_id);
}
qemu_console_set_surface(scanout->con, NULL);
@@ -411,7 +412,7 @@ static void virtio_gpu_resource_destroy(VirtIOGPU *g,
if (res->scanout_bitmask) {
for (i = 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 = 0; i < g->parent_obj.conf.max_outputs; i++) {
QemuRect rect;
- if (!(res->scanout_bitmask & (1 << i))) {
+ if (!(res->scanout_bitmask & BIT(i))) {
continue;
}
scanout = &g->parent_obj.scanout[i];
@@ -611,10 +612,10 @@ void virtio_gpu_update_scanout(VirtIOGPU *g,
scanout = &g->parent_obj.scanout[scanout_id];
ores = virtio_gpu_find_resource(g, scanout->resource_id);
if (ores) {
- ores->scanout_bitmask &= ~(1 << scanout_id);
+ ores->scanout_bitmask &= ~BIT(scanout_id);
}
- res->scanout_bitmask |= (1 << scanout_id);
+ res->scanout_bitmask |= BIT(scanout_id);
scanout->resource_id = res->resource_id;
scanout->x = r->x;
scanout->y = r->y;
@@ -1496,7 +1497,7 @@ static int virtio_gpu_post_load(void *opaque, int version_id)
if (scanout->cursor.resource_id) {
update_cursor(g, &scanout->cursor);
}
- res->scanout_bitmask |= (1 << i);
+ res->scanout_bitmask |= BIT(i);
}
return 0;
--
2.50.1 (Apple Git-155)
next reply other threads:[~2026-07-17 1:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 1:52 Bin Guo [this message]
2026-07-17 5:59 ` [PATCH] virtio-gpu: use BIT() macro for scanout bitmask operations Akihiko Odaki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260717015252.25675-1-guobin@linux.alibaba.com \
--to=guobin@linux.alibaba.com \
--cc=alex.bennee@linaro.org \
--cc=dmitry.osipenko@collabora.com \
--cc=marcandre.lureau@redhat.com \
--cc=mst@redhat.com \
--cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.