* [PATCH] virtio-gpu: use BIT() macro for scanout bitmask operations
@ 2026-07-17 1:52 Bin Guo
0 siblings, 0 replies; only message in thread
From: Bin Guo @ 2026-07-17 1:52 UTC (permalink / raw)
To: qemu-devel; +Cc: mst, alex.bennee, odaki, dmitry.osipenko, marcandre.lureau
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)
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-07-17 1:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-17 1:52 [PATCH] virtio-gpu: use BIT() macro for scanout bitmask operations Bin Guo
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.