aboutsummaryrefslogtreecommitdiff
path: root/chardev/char-mux.c
diff options
context:
space:
mode:
authorRoman Penyaev <r.peniaev@gmail.com>2024-11-29 11:32:38 +0100
committerMarc-André Lureau <marcandre.lureau@redhat.com>2024-12-02 16:23:12 +0400
commit188df56eab8ed960e407762e31a35fc666355132 (patch)
treee25ef3d7bfdd86e1b44c648070d8043233fb034d /chardev/char-mux.c
parent72b88908d12ee9347d13539c7dd9a252625158d1 (diff)
downloadqemu-188df56eab8ed960e407762e31a35fc666355132.zip
qemu-188df56eab8ed960e407762e31a35fc666355132.tar.gz
qemu-188df56eab8ed960e407762e31a35fc666355132.tar.bz2
chardev/char-mux: shift unsigned long to avoid 32-bit overflow
Allthough the size of MAX_MUX is equal to 4 and likely will never change, this patch changes type of constant to unsigned long to be on the safe side. Also add a static compile check that MAX_MUX never bigger than `sizeof(d->mux_bitset) * BITS_PER_BYTE`. Signed-off-by: Roman Penyaev <r.peniaev@gmail.com> Reviewed-by: "Marc-André Lureau" <marcandre.lureau@redhat.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Clément Mathieu--Drif <clement.mathieu--drif@eviden.com> Cc: qemu-devel@nongnu.org Message-ID: <20241129103239.464061-2-r.peniaev@gmail.com>
Diffstat (limited to 'chardev/char-mux.c')
-rw-r--r--chardev/char-mux.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/chardev/char-mux.c b/chardev/char-mux.c
index bda5c45..9d67b8b 100644
--- a/chardev/char-mux.c
+++ b/chardev/char-mux.c
@@ -316,6 +316,8 @@ bool mux_chr_attach_frontend(MuxChardev *d, CharBackend *b,
{
unsigned int bit;
+ QEMU_BUILD_BUG_ON(MAX_MUX > (sizeof(d->mux_bitset) * BITS_PER_BYTE));
+
bit = find_next_zero_bit(&d->mux_bitset, MAX_MUX, 0);
if (bit >= MAX_MUX) {
error_setg(errp,
@@ -325,7 +327,7 @@ bool mux_chr_attach_frontend(MuxChardev *d, CharBackend *b,
return false;
}
- d->mux_bitset |= (1 << bit);
+ d->mux_bitset |= (1ul << bit);
d->backends[bit] = b;
*tag = bit;
@@ -341,7 +343,7 @@ bool mux_chr_detach_frontend(MuxChardev *d, unsigned int tag)
return false;
}
- d->mux_bitset &= ~(1 << bit);
+ d->mux_bitset &= ~(1ul << bit);
d->backends[bit] = NULL;
return true;