From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpbg65.qq.com (smtpbg65.qq.com [103.7.28.233]) by dpdk.org (Postfix) with ESMTP id 10895F612 for ; Thu, 5 Jan 2017 13:02:06 +0100 (CET) X-QQ-mid: bizesmtp5t1483617724t3g3fwzph Received: from local.opencloud.tech.localdomai (unknown [106.120.127.11]) by esmtp4.qq.com (ESMTP) with id ; Thu, 05 Jan 2017 20:02:03 +0800 (CST) X-QQ-SSF: 0110000000200070F650000A0000000 X-QQ-FEAT: 1RpXLlb/fsY9VRs6wIT+R56AF0byA8gzwjQqjDn55ZmhGuyvpcB6vhTcZC2n1 KKhWCMDyv/E7bJtRHLfzJU0zeDZ/TNr/oDL0aQrzHfVVabEQzV/N/4VM5CluD+n9c9j0CN1 5Er1YFOQpPzkkbuerl1tEy1vR6/edD3NoDC8phKLpbRF0iokR7Yx8ZKeppz2Q4fGfAfMlHq TGQwYww9ulpZ7x7RI6kt0CKPa0M4XrRDtJZsyKWiHhLNaOKKQHklMBIY3VVHP35ZcBEaIC9 K/Cul23WLntfZX X-QQ-GoodBg: 0 From: nickcooper-zhangtonghao To: dev@dpdk.org Cc: nickcooper-zhangtonghao Date: Thu, 5 Jan 2017 04:01:48 -0800 Message-Id: <1483617709-7088-4-git-send-email-nic@opencloud.tech> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1483617709-7088-1-git-send-email-nic@opencloud.tech> References: <1483617709-7088-1-git-send-email-nic@opencloud.tech> X-QQ-SENDSIZE: 520 X-QQ-Bgrelay: 1 Subject: [dpdk-dev] [PATCH v2 4/5] vmxnet3: Avoid memory leak in vmxnet3_dev_tx_queue_setup. X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Jan 2017 12:02:08 -0000 This patch will check the "nb_desc" parameter for tx queue, release the txq and re-allocation it soon. Signed-off-by: nickcooper-zhangtonghao --- drivers/net/vmxnet3/vmxnet3_rxtx.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/net/vmxnet3/vmxnet3_rxtx.c b/drivers/net/vmxnet3/vmxnet3_rxtx.c index d5d7c33..f00b3b9 100644 --- a/drivers/net/vmxnet3/vmxnet3_rxtx.c +++ b/drivers/net/vmxnet3/vmxnet3_rxtx.c @@ -828,6 +828,23 @@ return -EINVAL; } + /* Tx vmxnet ring length should be between 512-4096 */ + if (nb_desc < VMXNET3_DEF_TX_RING_SIZE) { + PMD_INIT_LOG(ERR, "VMXNET3 Tx Ring Size Min: %u", + VMXNET3_DEF_TX_RING_SIZE); + return -EINVAL; + } else if (nb_desc > VMXNET3_TX_RING_MAX_SIZE) { + PMD_INIT_LOG(ERR, "VMXNET3 Tx Ring Size Max: %u", + VMXNET3_TX_RING_MAX_SIZE); + return -EINVAL; + } + + /* Free memory prior to re-allocation if needed... */ + if (dev->data->tx_queues[queue_idx] != NULL) { + vmxnet3_dev_tx_queue_release(dev->data->tx_queues[queue_idx]); + dev->data->tx_queues[queue_idx] = NULL; + } + txq = rte_zmalloc("ethdev_tx_queue", sizeof(struct vmxnet3_tx_queue), RTE_CACHE_LINE_SIZE); if (txq == NULL) { @@ -846,19 +863,8 @@ comp_ring = &txq->comp_ring; data_ring = &txq->data_ring; - /* Tx vmxnet ring length should be between 512-4096 */ - if (nb_desc < VMXNET3_DEF_TX_RING_SIZE) { - PMD_INIT_LOG(ERR, "VMXNET3 Tx Ring Size Min: %u", - VMXNET3_DEF_TX_RING_SIZE); - return -EINVAL; - } else if (nb_desc > VMXNET3_TX_RING_MAX_SIZE) { - PMD_INIT_LOG(ERR, "VMXNET3 Tx Ring Size Max: %u", - VMXNET3_TX_RING_MAX_SIZE); - return -EINVAL; - } else { - ring->size = nb_desc; - ring->size &= ~VMXNET3_RING_SIZE_MASK; - } + ring->size = nb_desc; + ring->size &= ~VMXNET3_RING_SIZE_MASK; comp_ring->size = data_ring->size = ring->size; /* Tx vmxnet rings structure initialization*/ -- 1.8.3.1