virtio: use err label in __vring_new_virtqueue()
authorJason Wang <jasowang@redhat.com>
Fri, 4 Jun 2021 05:53:49 +0000 (13:53 +0800)
committerMichael S. Tsirkin <mst@redhat.com>
Thu, 8 Jul 2021 11:49:01 +0000 (07:49 -0400)
Using error label for unwind in __vring_new_virtqueue. This is useful
for future refacotring.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Link: https://lore.kernel.org/r/20210604055350.58753-7-jasowang@redhat.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/virtio/virtio_ring.c

index c7d9a6f..5faa876 100644 (file)
@@ -2161,10 +2161,8 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,
 
        vq->split.desc_state = kmalloc_array(vring.num,
                        sizeof(struct vring_desc_state_split), GFP_KERNEL);
-       if (!vq->split.desc_state) {
-               kfree(vq);
-               return NULL;
-       }
+       if (!vq->split.desc_state)
+               goto err_state;
 
        /* Put everything in free lists. */
        vq->free_head = 0;
@@ -2175,6 +2173,10 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,
 
        list_add_tail(&vq->vq.list, &vdev->vqs);
        return &vq->vq;
+
+err_state:
+       kfree(vq);
+       return NULL;
 }
 EXPORT_SYMBOL_GPL(__vring_new_virtqueue);