From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpbguseast2.qq.com (smtpbguseast2.qq.com [54.204.34.130]) by dpdk.org (Postfix) with ESMTP id 0F0DAF610 for ; Thu, 5 Jan 2017 13:02:06 +0100 (CET) X-QQ-mid: bizesmtp5t1483617720t0cwkmw0s Received: from local.opencloud.tech.localdomai (unknown [106.120.127.11]) by esmtp4.qq.com (ESMTP) with id ; Thu, 05 Jan 2017 20:01:59 +0800 (CST) X-QQ-SSF: 0110000000200070F650000A0000000 X-QQ-FEAT: GxmJagP+DMl//AsRCvjRCzXVvxDWhSw7lRvxwtK0yh5eYWRX5GtJQEgtSWMwC tiJ/gRNug8lJ+vXRsXJ+E/HgoJ9wVxc7lRp13JVMpLdwYQdine+Ck4NRtkBvy1BQnhF4RU9 G7P2CSpsTRm6TjYHiVNlG2m1qvKVr13V1pKmn4GQJrDLGgao37hXjwFqttqyAex8wAe+KS9 OtuQ50khe5sVj11vzXfkGiKQgeQkemPdlahJAtZiCqAHMF/9VH1NaO+PgTjwc3FZC9qShyL 6qVAR6mdZShDMY X-QQ-GoodBg: 0 From: nickcooper-zhangtonghao To: dev@dpdk.org Cc: nickcooper-zhangtonghao Date: Thu, 5 Jan 2017 04:01:46 -0800 Message-Id: <1483617709-7088-2-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 2/5] vmxnet3: Avoid memory leak in vmxnet3_dev_rx_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:07 -0000 This patch will check the "nb_desc" parameter for rx queue, release the rxq and re-allocation it soon. Signed-off-by: nickcooper-zhangtonghao --- drivers/net/vmxnet3/vmxnet3_rxtx.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/net/vmxnet3/vmxnet3_rxtx.c b/drivers/net/vmxnet3/vmxnet3_rxtx.c index b109168..e77374f 100644 --- a/drivers/net/vmxnet3/vmxnet3_rxtx.c +++ b/drivers/net/vmxnet3/vmxnet3_rxtx.c @@ -926,6 +926,21 @@ PMD_INIT_FUNC_TRACE(); + /* Rx vmxnet rings length should be between 128-4096 */ + if (nb_desc < VMXNET3_DEF_RX_RING_SIZE) { + PMD_INIT_LOG(ERR, "VMXNET3 Rx Ring Size Min: 128"); + return -EINVAL; + } else if (nb_desc > VMXNET3_RX_RING_MAX_SIZE) { + PMD_INIT_LOG(ERR, "VMXNET3 Rx Ring Size Max: 4096"); + return -EINVAL; + } + + /* Free memory prior to re-allocation if needed. */ + if (dev->data->rx_queues[queue_idx] != NULL) { + vmxnet3_dev_rx_queue_release(dev->data->rx_queues[queue_idx]); + dev->data->rx_queues[queue_idx] = NULL; + } + rxq = rte_zmalloc("ethdev_rx_queue", sizeof(struct vmxnet3_rx_queue), RTE_CACHE_LINE_SIZE); if (rxq == NULL) { @@ -946,18 +961,9 @@ ring1 = &rxq->cmd_ring[1]; comp_ring = &rxq->comp_ring; - /* Rx vmxnet rings length should be between 256-4096 */ - if (nb_desc < VMXNET3_DEF_RX_RING_SIZE) { - PMD_INIT_LOG(ERR, "VMXNET3 Rx Ring Size Min: 256"); - return -EINVAL; - } else if (nb_desc > VMXNET3_RX_RING_MAX_SIZE) { - PMD_INIT_LOG(ERR, "VMXNET3 Rx Ring Size Max: 4096"); - return -EINVAL; - } else { - ring0->size = nb_desc; - ring0->size &= ~VMXNET3_RING_SIZE_MASK; - ring1->size = ring0->size; - } + ring0->size = nb_desc; + ring0->size &= ~VMXNET3_RING_SIZE_MASK; + ring1->size = ring0->size; comp_ring->size = ring0->size + ring1->size; -- 1.8.3.1