From patchwork Mon Feb 14 08:13:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuan Zhuo X-Patchwork-Id: 12745098 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F752C4321E for ; Mon, 14 Feb 2022 08:14:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241658AbiBNIOo (ORCPT ); Mon, 14 Feb 2022 03:14:44 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241633AbiBNIOl (ORCPT ); Mon, 14 Feb 2022 03:14:41 -0500 Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F20B5F8F2; Mon, 14 Feb 2022 00:14:33 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R431e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01424;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0V4OcHDO_1644826460; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0V4OcHDO_1644826460) by smtp.aliyun-inc.com(127.0.0.1); Mon, 14 Feb 2022 16:14:21 +0800 From: Xuan Zhuo To: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Cc: "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , bpf@vger.kernel.org Subject: [PATCH v5 04/22] virtio_ring: queue_reset: split: add __vring_init_virtqueue() Date: Mon, 14 Feb 2022 16:13:58 +0800 Message-Id: <20220214081416.117695-5-xuanzhuo@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20220214081416.117695-1-xuanzhuo@linux.alibaba.com> References: <20220214081416.117695-1-xuanzhuo@linux.alibaba.com> MIME-Version: 1.0 X-Git-Hash: 24fd8391539b Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Extract vq's initialization function __vring_init_virtqueue() from __vring_new_virtqueue() Signed-off-by: Xuan Zhuo --- drivers/virtio/virtio_ring.c | 61 +++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 4f95d650b066..9cfbe45ab286 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -2169,23 +2169,17 @@ irqreturn_t vring_interrupt(int irq, void *_vq) EXPORT_SYMBOL_GPL(vring_interrupt); /* Only available for split ring */ -struct virtqueue *__vring_new_virtqueue(unsigned int index, - struct vring vring, - struct virtio_device *vdev, - bool weak_barriers, - bool context, - bool (*notify)(struct virtqueue *), - void (*callback)(struct virtqueue *), - const char *name) +static int __vring_init_virtqueue(struct virtqueue *_vq, + unsigned int index, + struct vring vring, + struct virtio_device *vdev, + bool weak_barriers, + bool context, + bool (*notify)(struct virtqueue *), + void (*callback)(struct virtqueue *), + const char *name) { - struct vring_virtqueue *vq; - - if (virtio_has_feature(vdev, VIRTIO_F_RING_PACKED)) - return NULL; - - vq = kmalloc(sizeof(*vq), GFP_KERNEL); - if (!vq) - return NULL; + struct vring_virtqueue *vq = to_vvq(_vq); vq->packed_ring = false; vq->vq.callback = callback; @@ -2245,13 +2239,42 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, spin_lock(&vdev->vqs_list_lock); list_add_tail(&vq->vq.list, &vdev->vqs); spin_unlock(&vdev->vqs_list_lock); - return &vq->vq; + return 0; err_extra: kfree(vq->split.desc_state); err_state: - kfree(vq); - return NULL; + return -ENOMEM; +} + +struct virtqueue *__vring_new_virtqueue(unsigned int index, + struct vring vring, + struct virtio_device *vdev, + bool weak_barriers, + bool context, + bool (*notify)(struct virtqueue *), + void (*callback)(struct virtqueue *), + const char *name) +{ + struct vring_virtqueue *vq; + int err; + + if (virtio_has_feature(vdev, VIRTIO_F_RING_PACKED)) + return NULL; + + vq = kmalloc(sizeof(*vq), GFP_KERNEL); + if (!vq) + return NULL; + + err = __vring_init_virtqueue(&vq->vq, index, vring, vdev, weak_barriers, + context, notify, callback, name); + + if (err) { + kfree(vq); + return NULL; + } + + return &vq->vq; } EXPORT_SYMBOL_GPL(__vring_new_virtqueue);