From: Bin Guo <guobin@linux.alibaba.com>
To: qemu-devel@nongnu.org
Cc: mst@redhat.com, richard.henderson@linaro.org, philmd@linaro.org
Subject: [PATCH] hw/virtio/vhost: simplify ring mapping verification with loop
Date: Fri, 3 Apr 2026 17:16:21 +0800 [thread overview]
Message-ID: <20260403091621.88914-1-guobin@linux.alibaba.com> (raw)
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)
next reply other threads:[~2026-04-03 9:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-03 9:16 Bin Guo [this message]
2026-04-03 9:33 ` [PATCH] hw/virtio/vhost: simplify ring mapping verification with loop Michael S. Tsirkin
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=20260403091621.88914-1-guobin@linux.alibaba.com \
--to=guobin@linux.alibaba.com \
--cc=mst@redhat.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.