From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tetsuya Mukawa Subject: [PATCH] pci: fix closing an unopened file descriptor Date: Wed, 4 Sep 2013 03:34:35 -0400 Message-ID: <1378280075-2076-1-git-send-email-mukawa@igel.co.jp> To: dev-VfR2kkLFssw@public.gmane.org Return-path: List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces-VfR2kkLFssw@public.gmane.org Sender: "dev" If CONFIG_RTE_EAL_UNBIND_PORTS is set and virtio-net is used, an unopened file descriptor will be illegally closed in the finalized phase of EAL. The fix adds a correct initial value to the file descriptor, and check it before closing it. Signed-off-by: Tetsuya Mukawa --- lib/librte_eal/linuxapp/eal/eal_pci.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index c793148..7c04ba3 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -519,6 +519,8 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus, dev->addr.devid = devid; dev->addr.function = function; + dev->intr_handle.fd = -1; + /* get vendor id */ rte_snprintf(filename, sizeof(filename), "%s/vendor", dirname); if (eal_parse_sysfs_value(filename, &tmp) < 0) { @@ -718,7 +720,8 @@ pci_exit_process(struct rte_pci_device *dev) RTE_LOG(ERR, EAL, "Error with munmap\n"); return -1; } - if (close(dev->intr_handle.fd) == -1){ + if ((dev->intr_handle.fd != -1) && + (close(dev->intr_handle.fd) == -1)) { RTE_LOG(ERR, EAL, "Error closing interrupt handle\n"); return -1; } -- 1.8.3.1