pci: fix closing an unopened file descriptor
PATCH 1/1 pci: fix closing an unopened file descriptor
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.
--- lib/librte_eal/linuxapp/eal/eal_pci.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
lib/librte_eal/linuxapp/eal/eal_pci.c +4 -1
@@ -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 ; }
Signature · 1 line
1.8.3.1
A message that is not in the archive (sent off-list or not yet received): 1378280075-2076-1-git-send-email-mukawa-AlSX/UN32fvPDbFq/[email protected]
Hi Thomas,
I've sent the patch to fix an uninitialized variable access. Could you please check it?
I will send ver.2 patch if I need.
Thanks,
Tetsuya Mukawa
Quoted 33 lines · Tetsuya Mukawa
If
CONFIG_RTE_EAL_UNBIND_PORTSis 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.--- lib/librte_eal/linuxapp/eal/eal_pci.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)lib/librte_eal/linuxapp/eal/eal_pci.c +4
-1@@ -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 ; }
Thomas Monjalon
Acked-by04/09/2013 09:34, Tetsuya Mukawa :
Quoted 6 lines
If
CONFIG_RTE_EAL_UNBIND_PORTSis 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.
Thanks for the patch.
I have reproduced the issue only once.
It seems that fd 0 is open most of the time.
But the patch seems OK so I applied it with light modifications:
---
pci: fix closing an unopened file descriptor
If CONFIG_RTE_EAL_UNBIND_PORTS is set and a non Intel PMD 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.
lib/librte_eal/linuxapp/eal/eal_pci.c +0 -0
@@ -514,6 +514,7 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t
bus,
}
memset(dev, 0, sizeof(*dev));
+ dev->intr_handle.fd = -1;
dev->addr.domain = domain;
dev->addr.bus = bus;
dev->addr.devid = devid;
@@ -718,7 +719,7 @@ 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;
}