[igt-dev] [PATCH i-g-t] lib/drmtest: Move open device to separate function
Katarzyna Dec
katarzyna.dec at intel.com
Thu Aug 30 08:38:29 UTC 2018
While working on IGT code and during reviewes I've noticed that
it could be nice to have function that is opening particular device.
Let's move out conditions for opening device and rename __open_device
to __search_and_open() function.
Signed-off-by: Katarzyna Dec <katarzyna.dec at intel.com>
Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
---
lib/drmtest.c | 64 +++++++++++++++++++++++++++++++--------------------
1 file changed, 39 insertions(+), 25 deletions(-)
diff --git a/lib/drmtest.c b/lib/drmtest.c
index fae6f86f..b2d6cd26 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -218,38 +218,52 @@ static void modprobe_i915(const char *name)
igt_i915_driver_load(NULL);
}
-static int __open_device(const char *base, int offset, unsigned int chipset)
+static int open_device(const char *name, unsigned int chipset)
{
- for (int i = 0; i < 16; i++) {
- char name[80];
- int fd;
+ int fd;
- sprintf(name, "%s%u", base, i + offset);
- fd = open(name, O_RDWR);
- if (fd == -1)
- continue;
+ fd = open(name, O_RDWR);
- if (chipset & DRIVER_INTEL && is_i915_device(fd) &&
- has_known_intel_chipset(fd))
- return fd;
+ if (fd == -1)
+ return -1;
- if (chipset & DRIVER_VC4 && is_vc4_device(fd))
- return fd;
+ if (chipset & DRIVER_INTEL && is_i915_device(fd) &&
+ has_known_intel_chipset(fd))
+ return fd;
- if (chipset & DRIVER_VGEM && is_vgem_device(fd))
- return fd;
+ if (chipset & DRIVER_VC4 && is_vc4_device(fd))
+ return fd;
- if (chipset & DRIVER_VIRTIO && is_virtio_device(fd))
- return fd;
+ if (chipset & DRIVER_VGEM && is_vgem_device(fd))
+ return fd;
- if (chipset & DRIVER_AMDGPU && is_amd_device(fd))
- return fd;
+ if (chipset & DRIVER_VIRTIO && is_virtio_device(fd))
+ return fd;
- /* Only VGEM-specific tests should be run on VGEM */
- if (chipset == DRIVER_ANY && !is_vgem_device(fd))
- return fd;
+ if (chipset & DRIVER_AMDGPU && is_amd_device(fd))
+ return fd;
- close(fd);
+ /* Only VGEM-specific tests should be run on VGEM */
+ if (chipset == DRIVER_ANY && !is_vgem_device(fd))
+ return fd;
+
+ close(fd);
+
+ return -1;
+}
+
+static int __search_and_open(const char *base, int offset, unsigned int chipset)
+{
+ for (int i = 0; i < 16; i++) {
+ char name[80];
+ int fd;
+
+ sprintf(name, "%s%u", base, i + offset);
+ fd = open_device(name, chipset);
+ if (fd == -1)
+ continue;
+ else
+ return fd;
}
return -1;
@@ -272,7 +286,7 @@ static int __open_driver(const char *base, int offset, unsigned int chipset)
};
int fd;
- fd = __open_device(base, offset, chipset);
+ fd = __search_and_open(base, offset, chipset);
if (fd != -1)
return fd;
@@ -287,7 +301,7 @@ static int __open_driver(const char *base, int offset, unsigned int chipset)
}
pthread_mutex_unlock(&mutex);
- return __open_device(base, offset, chipset);
+ return __search_and_open(base, offset, chipset);
}
/**
--
2.17.1
More information about the igt-dev
mailing list