Use open(2) instead of access(2) to check for the existence of the target device. This avoids a possible race condition where the the device file is removed after a successful call to access(2) but before open(2).
This also fixes any potential bugs associated with passing open(2)-style flags into access(2). i.e. access(2) does not formally support the O_RDWR flag. Signed-off-by: Jake Freeland <jf...@freebsd.org> --- drivers/bus/pci/bsd/pci.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/bus/pci/bsd/pci.c b/drivers/bus/pci/bsd/pci.c index c64cd2c86c..9bce9df503 100644 --- a/drivers/bus/pci/bsd/pci.c +++ b/drivers/bus/pci/bsd/pci.c @@ -106,20 +106,29 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, { char devname[PATH_MAX]; /* contains the /dev/uioX */ struct rte_pci_addr *loc; + int fd; loc = &dev->addr; snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u", dev->addr.bus, dev->addr.devid, dev->addr.function); - if (access(devname, O_RDWR) < 0) { - PCI_LOG(WARNING, " "PCI_PRI_FMT" not managed by UIO driver, skipping", - loc->domain, loc->bus, loc->devid, loc->function); - return 1; + fd = open(devname, O_RDWR); + if (fd < 0) { + if (errno == ENOENT) { + PCI_LOG(WARNING, PCI_PRI_FMT" not managed by UIO " + "driver, skipping", loc->domain, + loc->bus, loc->devid, loc->function); + return 1; + } + PCI_LOG(ERR, "Failed to open device file for " PCI_PRI_FMT + " (%s)", loc->domain, loc->bus, loc->devid, + loc->function, devname); + return -1; } /* save fd if in primary process */ - if (rte_intr_fd_set(dev->intr_handle, open(devname, O_RDWR))) { + if (rte_intr_fd_set(dev->intr_handle, fd)) { PCI_LOG(WARNING, "Failed to save fd"); goto error; } -- 2.47.2