Skip to contentSkip to conversation

vhost: simplify vhost_dev_init() fail_busyloop label

PATCH In review Stefan Hajnoczi 3 participants 3 messages Feb 22, 2021 – Feb 23, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost: simplify vhost_dev_init() fail_busyloop label

Requiring a conditional for every goto is tedious:

  if (busyloop_timeout) {
      goto fail_busyloop;
  } else {
      goto fail;
  }

Move the conditional to into the fail_busyloop label so that it's safe to jump to this label unconditionally.

This change makes the migrate_add_blocker() error case more consistent. It jumped to fail_busyloop unconditionally whereas the memslots limits error case was conditional.

---
 hw/virtio/vhost.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
hw/virtio/vhost.c +5 -7
index 6e17d631f7..2a01662b08 100644
@@ -1388,18 +1388,16 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
         error_report("vhost backend memory slots limit is less"
                 " than current number of present memory slots");
         r = -1;
-        if (busyloop_timeout) {
-            goto fail_busyloop;
-        } else {
-            goto fail;
-        }
+        goto fail_busyloop;
     }
 
     return 0;
 
 fail_busyloop:
-    while (--i >= 0) {
-        vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i, 0);
+    if (busyloop_timeout) {
+        while (--i >= 0) {
+            vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i, 0);
+        }
     }
 fail:
     hdev->nvqs = n_initialized_vqs;
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Stefan Hajnoczi

Requiring a conditional for every goto is tedious:

 if (busyloop_timeout) {
     goto fail_busyloop;
 } else {
     goto fail;

}

Move the conditional to into the fail_busyloop label so that it's safe to jump to this label unconditionally.

Quoted 8 lines

This change makes the migrate_add_blocker() error case more consistent. It jumped to fail_busyloop unconditionally whereas the memslots limits error case was conditional.

---
hw/virtio/vhost.c | 12 +++++-------

1 file changed, 5 insertions(+), 7 deletions(-)
Quoted 32 lines
hw/virtio/vhost.c +1 -5
index 6e17d631f7..2a01662b08 100644
@@ -1388,18 +1388,16 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
        error_report("vhost backend memory slots limit is less"
                " than current number of present memory slots");
        r = -1;
-        if (busyloop_timeout) {
-            goto fail_busyloop;
-        } else {
-            goto fail;
-        }
+        goto fail_busyloop;
    }
 
    return 0;
 

fail_busyloop:

hw/virtio/vhost.c +4 -2
-    while (--i >= 0) {
-        vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i, 0);
+    if (busyloop_timeout) {
+        while (--i >= 0) {
+            vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i, 0);
+        }
    }

fail:

    hdev->nvqs = n_initialized_vqs;
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#2 lore raw
In reply to Stefan Hajnoczi
Quoted 11 lines · Stefan Hajnoczi

Requiring a conditional for every goto is tedious:

  if (busyloop_timeout) {
      goto fail_busyloop;
  } else {
      goto fail;
  }

Move the conditional to into the fail_busyloop label so that it's safe to jump to this label unconditionally.

Quoted 8 lines

This change makes the migrate_add_blocker() error case more consistent. It jumped to fail_busyloop unconditionally whereas the memslots limits error case was conditional.

---
 hw/virtio/vhost.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)