Re: [PATCH V7 12/19] virtio_ring: use u16 for last_used_idx in virtqueue_poll_split()

From: David Laight

Date: Sun Sep 28 2025 - 14:28:12 EST


On Thu, 25 Sep 2025 18:37:01 +0800
Jason Wang <jasowang@xxxxxxxxxx> wrote:

> Use u16 for last_used_idx in virtqueue_poll_split() to align with the
> spec.

If you care about performance you should pretty much never use 'u16' for
function parameters, return values or any arithmetic.
Just because the domain of the variable is [0..65535] doesn't mean that
'unsigned int' isn't the correct type.

>
> Acked-by: Eugenio Pérez <eperezma@xxxxxxxxxx>
> Reviewed-by: Xuan Zhuo <xuanzhuo@xxxxxxxxxxxxxxxxx>
> Signed-off-by: Jason Wang <jasowang@xxxxxxxxxx>
> ---
> drivers/virtio/virtio_ring.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index 58c03a8aab85..4679a027dc53 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -806,7 +806,7 @@ static void detach_buf_split(struct vring_virtqueue *vq, unsigned int head,
> }
>
> static bool virtqueue_poll_split(const struct vring_virtqueue *vq,
> - unsigned int last_used_idx)
> + u16 last_used_idx)
> {
> return (u16)last_used_idx != virtio16_to_cpu(vq->vq.vdev,

You can't want that (u16) cast now, I doubt it was ever needed.
Note that the compiler promotes the value to 'signed int',
so the LHS of the comparison is actually (int)(u16)last_used_idx.

David

> vq->split.vring.used->idx);