All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Bin Guo <guobin@linux.alibaba.com>
Cc: qemu-devel@nongnu.org, richard.henderson@linaro.org, philmd@linaro.org
Subject: Re: [PATCH] hw/virtio/vhost: simplify ring mapping verification with loop
Date: Fri, 3 Apr 2026 05:33:35 -0400	[thread overview]
Message-ID: <20260403053055-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20260403091621.88914-1-guobin@linux.alibaba.com>

On Fri, Apr 03, 2026 at 05:16:21PM +0800, Bin Guo wrote:
> Replace the three nearly-identical vhost_verify_ring_part_mapping() calls
> with a simple loop over arrays. This eliminates code duplication while
> maintaining identical behavior and error reporting.
> 
> Signed-off-by: Bin Guo <guobin@linux.alibaba.com>
> ---
>  hw/virtio/vhost.c | 34 ++++++++++++----------------------
>  1 file changed, 12 insertions(+), 22 deletions(-)
> 
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index b9dc4ed13b..7b5bfc86e6 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -525,31 +525,21 @@ static int vhost_verify_ring_mappings(struct vhost_dev *dev,
>              continue;
>          }
>  
> -        j = 0;
> -        r = vhost_verify_ring_part_mapping(
> -                vq->desc, vq->desc_phys, vq->desc_size,
> -                reg_hva, reg_gpa, reg_size);
> -        if (r) {
> -            break;
> -        }
> -
> -        j++;
> -        r = vhost_verify_ring_part_mapping(
> -                vq->avail, vq->avail_phys, vq->avail_size,
> -                reg_hva, reg_gpa, reg_size);
> -        if (r) {
> -            break;
> -        }
> -
> -        j++;
> -        r = vhost_verify_ring_part_mapping(
> -                vq->used, vq->used_phys, vq->used_size,
> -                reg_hva, reg_gpa, reg_size);
> -        if (r) {
> -            break;
> +        void *ring_addrs[] = {vq->desc, vq->avail, vq->used};
> +        uint64_t ring_phys[] = {vq->desc_phys, vq->avail_phys, vq->used_phys};
> +        uint64_t ring_sizes[] = {vq->desc_size, vq->avail_size, vq->used_size};
> +
> +        for (j = 0; j < 3; j++) {
> +            r = vhost_verify_ring_part_mapping(
> +                    ring_addrs[j], ring_phys[j], ring_sizes[j],
> +                    reg_hva, reg_gpa, reg_size);
> +            if (r) {
> +                goto out;
> +            }
>          }
>      }
>  
> +out:
>      if (r == -ENOMEM) {
>          error_report("Unable to map %s for ring %d", part_name[j], i);


I don't see the point, sorry. Maybe if it was a single array,
and we used ARRAY_SIZE ... Even then, I am not sure.

As it is, we are replacing straight forward linear code with
tricky arrays.

>      } else if (r == -EBUSY) {
> -- 
> 2.50.1 (Apple Git-155)



      reply	other threads:[~2026-04-03  9:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-03  9:16 [PATCH] hw/virtio/vhost: simplify ring mapping verification with loop Bin Guo
2026-04-03  9:33 ` Michael S. Tsirkin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260403053055-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=guobin@linux.alibaba.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.