Separate the logic of creating desc_state, desc_extra, and subsequent patches will call it independently.
Signed-off-by: Xuan Zhuo <xuanz...@linux.alibaba.com> --- drivers/virtio/virtio_ring.c | 52 +++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index d7667f74c42b..9b850188c38e 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -2186,6 +2186,33 @@ irqreturn_t vring_interrupt(int irq, void *_vq) } EXPORT_SYMBOL_GPL(vring_interrupt); +static int __vring_alloc_state_extra_split(u32 num, + struct vring_desc_state_split **desc_state, + struct vring_desc_extra **desc_extra) +{ + struct vring_desc_state_split *state; + struct vring_desc_extra *extra; + + state = kmalloc_array(num, sizeof(struct vring_desc_state_split), GFP_KERNEL); + if (!state) + goto err_state; + + extra = vring_alloc_desc_extra(num); + if (!extra) + goto err_extra; + + memset(state, 0, num * sizeof(struct vring_desc_state_split)); + + *desc_state = state; + *desc_extra = extra; + return 0; + +err_extra: + kfree(state); +err_state: + return -ENOMEM; +} + /* Only available for split ring */ struct virtqueue *__vring_new_virtqueue(unsigned int index, struct vring vring, @@ -2196,7 +2223,10 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, void (*callback)(struct virtqueue *), const char *name) { + struct vring_desc_state_split *state; + struct vring_desc_extra *extra; struct vring_virtqueue *vq; + int err; if (virtio_has_feature(vdev, VIRTIO_F_RING_PACKED)) return NULL; @@ -2246,30 +2276,22 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, vq->split.avail_flags_shadow); } - vq->split.desc_state = kmalloc_array(vring.num, - sizeof(struct vring_desc_state_split), GFP_KERNEL); - if (!vq->split.desc_state) - goto err_state; + err = __vring_alloc_state_extra_split(vring.num, &state, &extra); + if (err) { + kfree(vq); + return NULL; + } - vq->split.desc_extra = vring_alloc_desc_extra(vring.num); - if (!vq->split.desc_extra) - goto err_extra; + vq->split.desc_state = state; + vq->split.desc_extra = extra; /* Put everything in free lists. */ vq->free_head = 0; - memset(vq->split.desc_state, 0, vring.num * - sizeof(struct vring_desc_state_split)); spin_lock(&vdev->vqs_list_lock); list_add_tail(&vq->vq.list, &vdev->vqs); spin_unlock(&vdev->vqs_list_lock); return &vq->vq; - -err_extra: - kfree(vq->split.desc_state); -err_state: - kfree(vq); - return NULL; } EXPORT_SYMBOL_GPL(__vring_new_virtqueue); -- 2.31.0 _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization