Re: [PATCH v2 1/2] virtio: make virtio_add_queue() queue_size an unsigned int

Peter Maydell <[email protected]>
Newsgroups org.nongnu.qemu-devel,dev.linux.lists.virtio-fs
Message-ID <CAFEAcA-3zzanALJtPpOnd6iiVsgz9f9Ek5EHtQqQC5-6=0XogA@mail.gmail.com>
On Fri, 31 Jul 2026 at 09:35, Philippe Mathieu-Daudé
<[email protected]> wrote:
>
> Hi Stefan,
>
> On 30/7/26 22:58, Stefan Hajnoczi wrote:
> > virtio_add_queue()'s queue_size argument is a signed int. The
> > vdev->vq[i].vring.num and num_default fields are already declared as
> > unsigned int, so change the virtio_add_queue() argument's type for
> > consistency.
> >
> > A note on consistency: the VIRTIO specification defines queue size as an
> > unsigned 16-bit value.
>
> Why not use uint16_t then?

That's a bit awkward sometimes for a function like this that
is doing a bounds-check on the value. If a caller passes it an
argument that is a bigger type, then this function sees only
the lower 16 bits, and it might pass the bounds check, but
then the caller thinks the queue size is larger than this
layer of code thinks it is.

As a concrete example, the virtio-scsi callsite passes in
a value that is a uint32_t value settable by the user via
a QOM property, and it relies on this function to do the
upper bounds check for it.

-- PMM
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.