* [PATCH] pci: fix closing an unopened file descriptor
@ 2013-09-04 7:34 Tetsuya Mukawa
[not found] ` <1378280075-2076-1-git-send-email-mukawa-AlSX/UN32fvPDbFq/vQRIQ@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Tetsuya Mukawa @ 2013-09-04 7:34 UTC (permalink / raw)
To: dev-VfR2kkLFssw
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 <mukawa-AlSX/UN32fvPDbFq/vQRIQ@public.gmane.org>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread[parent not found: <1378280075-2076-1-git-send-email-mukawa-AlSX/UN32fvPDbFq/vQRIQ@public.gmane.org>]
* Re: [PATCH] pci: fix closing an unopened file descriptor [not found] ` <1378280075-2076-1-git-send-email-mukawa-AlSX/UN32fvPDbFq/vQRIQ@public.gmane.org> @ 2013-09-04 7:38 ` Tetsuya.Mukawa 2013-09-12 15:28 ` Thomas Monjalon 1 sibling, 0 replies; 3+ messages in thread From: Tetsuya.Mukawa @ 2013-09-04 7:38 UTC (permalink / raw) To: dev-VfR2kkLFssw, thomas.monjalon-pdR9zngts4EAvxtiuMwx3w 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 (2013/09/04 16:34), Tetsuya Mukawa wrote: > 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 <mukawa-AlSX/UN32fvPDbFq/vQRIQ@public.gmane.org> > --- > 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; > } ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] pci: fix closing an unopened file descriptor [not found] ` <1378280075-2076-1-git-send-email-mukawa-AlSX/UN32fvPDbFq/vQRIQ@public.gmane.org> 2013-09-04 7:38 ` Tetsuya.Mukawa @ 2013-09-12 15:28 ` Thomas Monjalon 1 sibling, 0 replies; 3+ messages in thread From: Thomas Monjalon @ 2013-09-12 15:28 UTC (permalink / raw) To: Tetsuya Mukawa; +Cc: dev-VfR2kkLFssw 04/09/2013 09:34, Tetsuya Mukawa : > 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 <mukawa-AlSX/UN32fvPDbFq/vQRIQ@public.gmane.org> 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. Signed-off-by: Tetsuya Mukawa <mukawa-AlSX/UN32fvPDbFq/vQRIQ@public.gmane.org> Acked-by: Thomas Monjalon <thomas.monjalon-pdR9zngts4EAvxtiuMwx3w@public.gmane.org> --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -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; } ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-09-12 15:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-04 7:34 [PATCH] pci: fix closing an unopened file descriptor Tetsuya Mukawa
[not found] ` <1378280075-2076-1-git-send-email-mukawa-AlSX/UN32fvPDbFq/vQRIQ@public.gmane.org>
2013-09-04 7:38 ` Tetsuya.Mukawa
2013-09-12 15:28 ` Thomas Monjalon
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.