On Tue, 22 Mar 2022 14:33:34 +0800, Jason Wang <[email protected]> wrote:
>
> 在 2022/3/14 下午5:34, Xuan Zhuo 写道:
> > Separate the logic of creating desc_state, desc_extra, and subsequent
> > patches will call it independently.
> >
> > Signed-off-by: Xuan Zhuo <[email protected]>
> > ---
> > 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)
>
>
> A nit here: I think we can simply remove the "__" prefix since:
>
> 1) We haven't had a version of helper without "__"
>
> 2) There're other internal helpers that doesn't use "__"
OK.
Thanks.
>
> Thanks
>
>
> > +{
> > + 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);
> >
>
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization