Re: [PATCH v2 1/2] virtio: make virtio_add_queue() queue_size an unsigned int
Peter Maydell <[email protected]> Fri, 31 Jul 2026 09:59:44 +0100
| Newsgroups | dev.linux.lists.virtio-fs,org.nongnu.qemu-devel |
|---|---|
| Message-ID | <CAFEAcA-3zzanALJtPpOnd6iiVsgz9f9Ek5EHtQqQC5-6=0XogA@mail.gmail.com> |
On Fri, 31 Jul 2026 at 09:35, Philippe Mathieu-Daud=C3=A9 <[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 a= n > > 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