From abce50bee3586c8cc35aad6feb8ff9425a5e7b43 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joan=20Lled=C3=B3?= Date: Sun, 31 May 2020 10:28:56 +0200 Subject: [PATCH] Hurd: avoid redundant checks for port validity --- lib/hurd.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/hurd.c b/lib/hurd.c index 13d88ac..4627302 100644 --- a/lib/hurd.c +++ b/lib/hurd.c @@ -88,7 +88,7 @@ hurd_cleanup_dev(struct pci_dev *d) pci_mfree(d->aux); } -static void +static int device_port_lookup(struct pci_dev *d) { mach_port_t device_port; @@ -100,6 +100,8 @@ device_port_lookup(struct pci_dev *d) device_port = file_name_lookup(server, 0, 0); *((mach_port_t *) d->aux) = device_port; + + return d->aux != MACH_PORT_NULL; } /* Walk through the FS tree to see what is allowed for us */ @@ -186,8 +188,7 @@ enum_devices(const char *parent, struct pci_access *a, int domain, int bus, d->func = func; /* Get the arbiter port */ - device_port_lookup(d); - if (d->aux == MACH_PORT_NULL) + if (!device_port_lookup(d)) { if (closedir(dir) < 0) a->warning("Cannot close directory: %s (%s)", parent, @@ -235,8 +236,7 @@ hurd_read(struct pci_dev *d, int pos, byte * buf, int len) if (*((mach_port_t *) d->aux) == MACH_PORT_NULL) { /* We still don't have the port for this device */ - device_port_lookup(d); - if (d->aux == MACH_PORT_NULL) + if (device_port_lookup(d)) { d->access->error("Cannot find the PCI arbiter"); } @@ -284,8 +284,7 @@ hurd_write(struct pci_dev *d, int pos, byte * buf, int len) if (*((mach_port_t *) d->aux) == MACH_PORT_NULL) { /* We still don't have the port for this device */ - device_port_lookup(d); - if (d->aux == MACH_PORT_NULL) + if (device_port_lookup(d)) { d->access->error("Cannot find the PCI arbiter"); } -- 2.39.5