From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-f47.google.com (mail-lf0-f47.google.com [209.85.215.47]) by dpdk.org (Postfix) with ESMTP id 8335B9378 for ; Tue, 5 Jan 2016 15:04:40 +0100 (CET) Received: by mail-lf0-f47.google.com with SMTP id p203so296800534lfa.0 for ; Tue, 05 Jan 2016 06:04:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id; bh=NKxwJYtQrmrIn1+ki7BooYLlzNJHWciMWCSd7gk1pn4=; b=BhRYCsuhQREiATtiRaM0XfqKiJhalxtY6aL7J4EcrsD3O7hCdefPJJsTCLDMKxfvN9 ge+zdztZKgoyO/481Y2h3Pc5BTFDNKHtsQGfeH4jdWCqB2Wk5gx97gcvyBPQbWZj0T0C AEIDJlJMeO/wZZhrqj8I8p5RFBsgnc7+dmdE23t8U48vQg9UaxtzZXUfBCn881qRgAtk pJJdSb7QRj0IZkIMCNf6D7A5bu4JKdrUXgjjB7xD1xq8MqZhFEn1uO0iS5IxZ10eWKFc fl/a3+jyYP5fzD2dbsvuJmOLDZxDQwvLDyMNXyybqwuCpfAi0cx5TOAd0ekphTkggusm esAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=NKxwJYtQrmrIn1+ki7BooYLlzNJHWciMWCSd7gk1pn4=; b=kqLE3c253bsYgitD6NLPIqZP6qL/tRsG+oAGaC579tIoW/kd1lT3jYUGawatxLrQsy aShvz1Z3rvI7s2dvndIx4RmYfhIM/S1n2CEs7Z+cqBfzQAaaN9Cbn3e2iTYQ5qgo2ae2 q94GblM82txGwPLyLLbr1BypLXyQ8TztZSgcFLUbRWs5/zPWu9ID72JssXhehtEIH3WV 6zMYgCSVRQRZgzjXutQVSQZXB2nPyf6v32QuALKKf69HgSwTjbeadiEHNxP3spmJg1CV YpbM+ZL3hQtgVD72EJKap/PEmzfIqQCPkd6tLE2MYEGy3Azix91BT+La14JGsckkgPir pPPQ== X-Gm-Message-State: ALoCoQkdVmzzcuVPg1cDh7qCNn++hwtR3CnMQ3xh4/L9senJ5eMSLBsYkug4fY8lIa5H0A6ozaZPbHTuFUvpmZVUzVqbhKHiQA== X-Received: by 10.25.137.194 with SMTP id l185mr15946084lfd.41.1452002680018; Tue, 05 Jan 2016 06:04:40 -0800 (PST) Received: from woz.semihalf.local (cardhu.semihalf.com. [213.17.239.108]) by smtp.gmail.com with ESMTPSA id i127sm115430lfd.3.2016.01.05.06.04.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 Jan 2016 06:04:39 -0800 (PST) From: Wojciech Zmuda To: dev@dpdk.org Date: Tue, 5 Jan 2016 15:04:34 +0100 Message-Id: <1452002675-8919-1-git-send-email-woz@semihalf.com> X-Mailer: git-send-email 1.9.1 Subject: [dpdk-dev] [PATCH] af_packet: make the device detachable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jan 2016 14:04:40 -0000 Fix memory leak when detaching virtual device. Set dev_flags to RTE_ETH_DEV_DETACHABLE and implement pmd_af_packet_drv.uninit method. Copy device name to ethdev->data to make it compatibile with rte_eth_dev_allocated(). Signed-off-by: Wojciech Zmuda --- drivers/net/af_packet/rte_eth_af_packet.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index 767f36b..7ef65ff 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -667,11 +667,13 @@ rte_pmd_init_internals(const char *name, data->nb_tx_queues = (uint16_t)nb_queues; data->dev_link = pmd_link; data->mac_addrs = &(*internals)->eth_addr; + strncpy(data->name, + (*eth_dev)->data->name, strlen((*eth_dev)->data->name)); (*eth_dev)->data = data; (*eth_dev)->dev_ops = &ops; (*eth_dev)->driver = NULL; - (*eth_dev)->data->dev_flags = 0; + (*eth_dev)->data->dev_flags = RTE_ETH_DEV_DETACHABLE; (*eth_dev)->data->drv_name = drivername; (*eth_dev)->data->kdrv = RTE_KDRV_NONE; (*eth_dev)->data->numa_node = numa_node; @@ -836,10 +838,35 @@ exit: return ret; } +static int +rte_pmd_af_packet_devuninit(const char *name) +{ + struct rte_eth_dev *eth_dev = NULL; + + RTE_LOG(INFO, PMD, "Closing AF_PACKET ethdev on numa socket %u\n", + rte_socket_id()); + + if (name == NULL) + return -1; + + /* reserve an ethdev entry */ + eth_dev = rte_eth_dev_allocated(name); + if (eth_dev == NULL) + return -1; + + rte_free(eth_dev->data->dev_private); + rte_free(eth_dev->data); + + rte_eth_dev_release_port(eth_dev); + + return 0; +} + static struct rte_driver pmd_af_packet_drv = { .name = "eth_af_packet", .type = PMD_VDEV, .init = rte_pmd_af_packet_devinit, + .uninit = rte_pmd_af_packet_devuninit, }; PMD_REGISTER_DRIVER(pmd_af_packet_drv); -- 1.9.1