From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tetsuya Mukawa Subject: [PATCH v2] eal: Fix resource leak while secondary process maps pci devices Date: Thu, 16 Jun 2016 11:33:11 +0900 Message-ID: <1466044391-3210-3-git-send-email-mukawa@igel.co.jp> References: <1466044391-3210-1-git-send-email-mukawa@igel.co.jp> Cc: david.marchand@6wind.com, john.mcnamara@intel.com, michalx.k.jastrzebski@intel.com, Tetsuya Mukawa To: dev@dpdk.org Return-path: Received: from mail-pa0-f51.google.com (mail-pa0-f51.google.com [209.85.220.51]) by dpdk.org (Postfix) with ESMTP id 263C4C544 for ; Thu, 16 Jun 2016 04:33:35 +0200 (CEST) Received: by mail-pa0-f51.google.com with SMTP id bz2so13154827pad.1 for ; Wed, 15 Jun 2016 19:33:35 -0700 (PDT) In-Reply-To: <1466044391-3210-1-git-send-email-mukawa@igel.co.jp> In-Reply-To: <1465961172-28253-1-git-send-email-mukawa@igel.co.jp> References: <1465961172-28253-1-git-send-email-mukawa@igel.co.jp> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch fixes resource leak of pci_uio_map_secondary(). If pci_map_resource() succeeds but mapped address is different from an address primary process mapped, this should be error. Then the addresses secondary process mapped should be freed. Signed-off-by: Tetsuya Mukawa --- lib/librte_eal/common/eal_common_pci_uio.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/common/eal_common_pci_uio.c b/lib/librte_eal/common/eal_common_pci_uio.c index 488b6dd..83314c3 100644 --- a/lib/librte_eal/common/eal_common_pci_uio.c +++ b/lib/librte_eal/common/eal_common_pci_uio.c @@ -53,7 +53,7 @@ EAL_REGISTER_TAILQ(rte_uio_tailq) static int pci_uio_map_secondary(struct rte_pci_device *dev) { - int fd, i; + int fd, i, j; struct mapped_pci_resource *uio_res; struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list); @@ -85,6 +85,17 @@ pci_uio_map_secondary(struct rte_pci_device *dev) "Cannot mmap device resource file %s to address: %p\n", uio_res->maps[i].path, uio_res->maps[i].addr); + if (mapaddr != MAP_FAILED) { + /* unmap addrs correctly mapped */ + for (j = 0; j < i; j++) + pci_unmap_resource( + uio_res->maps[j].addr, + (size_t)uio_res->maps[j].size); + + /* unmap addr wrongly mapped */ + pci_unmap_resource(mapaddr, + (size_t)uio_res->maps[i].size); + } return -1; } } -- 2.7.4