DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jianfeng Tan <jianfeng.tan@intel.com>
To: dev@dpdk.org
Cc: huawei.xie@intel.com, yuanhan.liu@linux.intel.com,
	Jianfeng Tan <jianfeng.tan@intel.com>
Subject: [dpdk-dev] [PATCH v3 1/2] virtio: cleanup virtio_dev_queue_setup()
Date: Fri, 29 Apr 2016 00:48:45 +0000	[thread overview]
Message-ID: <1461890926-16727-2-git-send-email-jianfeng.tan@intel.com> (raw)
In-Reply-To: <1461890926-16727-1-git-send-email-jianfeng.tan@intel.com>

Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
 drivers/net/virtio/virtio_ethdev.c | 47 +++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 23 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 1fe90ae..b3f4158 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -285,6 +285,7 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
 	unsigned int vq_size, size;
 	struct virtio_hw *hw = dev->data->dev_private;
 	struct virtqueue *vq = NULL;
+	const char *queue_names[] = {"rvq", "txq", "cvq"};
 
 	PMD_INIT_LOG(DEBUG, "setting up queue: %u", vtpci_queue_idx);
 
@@ -304,34 +305,34 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
 		return -EINVAL;
 	}
 
-	if (queue_type == VTNET_RQ) {
-		snprintf(vq_name, sizeof(vq_name), "port%d_rvq%d",
-			dev->data->port_id, queue_idx);
-		vq = rte_zmalloc(vq_name, sizeof(struct virtqueue) +
-			vq_size * sizeof(struct vq_desc_extra), RTE_CACHE_LINE_SIZE);
-		vq->sw_ring = rte_zmalloc_socket("rxq->sw_ring",
-			(RTE_PMD_VIRTIO_RX_MAX_BURST + vq_size) *
-			sizeof(vq->sw_ring[0]), RTE_CACHE_LINE_SIZE, socket_id);
-	} else if (queue_type == VTNET_TQ) {
-		snprintf(vq_name, sizeof(vq_name), "port%d_tvq%d",
-			dev->data->port_id, queue_idx);
-		vq = rte_zmalloc(vq_name, sizeof(struct virtqueue) +
-			vq_size * sizeof(struct vq_desc_extra), RTE_CACHE_LINE_SIZE);
-	} else if (queue_type == VTNET_CQ) {
-		snprintf(vq_name, sizeof(vq_name), "port%d_cvq",
-			dev->data->port_id);
-		vq = rte_zmalloc(vq_name, sizeof(struct virtqueue) +
-			vq_size * sizeof(struct vq_desc_extra),
-			RTE_CACHE_LINE_SIZE);
+	if (queue_type < VTNET_RQ || queue_type > VTNET_CQ) {
+		PMD_INIT_LOG(ERR, "invalid queue type: %d", queue_type);
+		return -EINVAL;
 	}
+
+	snprintf(vq_name, sizeof(vq_name), "port%d_%s%d",
+		 dev->data->port_id, queue_names[queue_type], queue_idx);
+	vq = rte_zmalloc(vq_name, sizeof(struct virtqueue) +
+			 vq_size * sizeof(struct vq_desc_extra),
+			 RTE_CACHE_LINE_SIZE);
 	if (vq == NULL) {
 		PMD_INIT_LOG(ERR, "Can not allocate virtqueue");
 		return -ENOMEM;
 	}
-	if (queue_type == VTNET_RQ && vq->sw_ring == NULL) {
-		PMD_INIT_LOG(ERR, "Can not allocate RX soft ring");
-		rte_free(vq);
-		return -ENOMEM;
+
+	if (queue_type == VTNET_RQ) {
+		size_t sz_sw;
+
+		sz_sw = (RTE_PMD_VIRTIO_RX_MAX_BURST + vq_size) *
+			sizeof(vq->sw_ring[0]);
+		vq->sw_ring = rte_zmalloc_socket("rxq->sw_ring", sz_sw,
+						 RTE_CACHE_LINE_SIZE,
+						 socket_id);
+		if (!vq->sw_ring) {
+			PMD_INIT_LOG(ERR, "Can not allocate RX soft ring");
+			rte_free(vq);
+			return -ENOMEM;
+		}
 	}
 
 	vq->hw = hw;
-- 
2.1.4

  reply	other threads:[~2016-04-29  0:48 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-26 12:32 [dpdk-dev] [PATCH] virtio: fix memory leak of virtqueue memzones Jianfeng Tan
2016-04-27 22:37 ` Yuanhan Liu
2016-04-28  2:01   ` Tan, Jianfeng
2016-04-28  3:29     ` Yuanhan Liu
2016-04-28 19:03 ` [dpdk-dev] [PATCH v2 0/2] " Jianfeng Tan
2016-04-28 19:04   ` [dpdk-dev] [PATCH v2 1/2] virtio: cleanup virtio_dev_queue_setup() Jianfeng Tan
2016-04-28 19:04   ` [dpdk-dev] [PATCH v2 2/2] virtio: fix memory leak of virtqueue memzones Jianfeng Tan
2016-04-28 19:05   ` [dpdk-dev] [PATCH v2 0/2] " Tan, Jianfeng
2016-04-28 19:08     ` Tan, Jianfeng
2016-04-29  0:48 ` [dpdk-dev] [PATCH v3 " Jianfeng Tan
2016-04-29  0:48   ` Jianfeng Tan [this message]
2016-05-05  3:19     ` [dpdk-dev] [PATCH v3 1/2] virtio: cleanup virtio_dev_queue_setup() Yuanhan Liu
2016-05-09  7:58       ` Tan, Jianfeng
2016-05-09 18:04         ` Yuanhan Liu
2016-04-29  0:48   ` [dpdk-dev] [PATCH v3 2/2] virtio: fix memory leak of virtqueue memzones Jianfeng Tan
2016-04-29  5:33     ` Yuanhan Liu
2016-05-05  3:27       ` Yuanhan Liu
2016-05-05  4:51         ` Tan, Jianfeng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1461890926-16727-2-git-send-email-jianfeng.tan@intel.com \
    --to=jianfeng.tan@intel.com \
    --cc=dev@dpdk.org \
    --cc=huawei.xie@intel.com \
    --cc=yuanhan.liu@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).