All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hw/virtio/vhost: simplify ring mapping verification with loop
@ 2026-04-03  9:16 Bin Guo
  2026-04-03  9:33 ` Michael S. Tsirkin
  0 siblings, 1 reply; 2+ messages in thread
From: Bin Guo @ 2026-04-03  9:16 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, richard.henderson, philmd

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);
     } else if (r == -EBUSY) {
-- 
2.50.1 (Apple Git-155)



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-04-03  9:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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.