]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
hw/misc: use extract64 instead of 1 << i
authorTigran Sogomonian <tsogomonian@astralinux.ru>
Fri, 27 Dec 2024 10:46:18 +0000 (13:46 +0300)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 17 Mar 2025 07:53:25 +0000 (08:53 +0100)
1 << i is casted to uint64_t while bitwise and with val.
So this value may become 0xffffffff80000000 but only
31th "start" bit is required.
Use the bitfield extract() API instead.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Tigran Sogomonian <tsogomonian@astralinux.ru>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Link: https://lore.kernel.org/r/20241227104618.2526-1-tsogomonian@astralinux.ru
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hw/misc/mps2-fpgaio.c

index d07568248d6ed39d8f1657a1363772674ae26a85..04a3da5db051faa0c7262698956319f5f1e04cd7 100644 (file)
@@ -198,7 +198,7 @@ static void mps2_fpgaio_write(void *opaque, hwaddr offset, uint64_t value,
 
             s->led0 = value & MAKE_64BIT_MASK(0, s->num_leds);
             for (i = 0; i < s->num_leds; i++) {
-                led_set_state(s->led[i], value & (1 << i));
+                led_set_state(s->led[i], extract64(value, i, 1));
             }
         }
         break;