[Mesa-dev] [PATCH 3/4] loader: simplify loader_get_user_preferred_fd()
Emil Velikov
emil.l.velikov at gmail.com
Tue Feb 19 15:30:40 UTC 2019
From: Emil Velikov <emil.velikov at collabora.com>
Reoder the function a bit to make the code-flow more obvious and short.
Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
git show -w produces a nicer diff
---
src/loader/loader.c | 42 ++++++++++++++++--------------------------
1 file changed, 16 insertions(+), 26 deletions(-)
diff --git a/src/loader/loader.c b/src/loader/loader.c
index c578e3f0849..cea1aac5b56 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -280,7 +280,6 @@ int loader_get_user_preferred_fd(int default_fd, bool *different_device)
char *default_tag, *prime = NULL;
drmDevicePtr devices[MAX_DRM_DEVICES];
int i, num_devices, fd;
- bool found = false;
if (dri_prime)
prime = strdup(dri_prime);
@@ -302,41 +301,32 @@ int loader_get_user_preferred_fd(int default_fd, bool *different_device)
if (num_devices < 0)
goto err;
- /* two format are supported:
- * "1": choose any other card than the card used by default.
- * id_path_tag: (for example "pci-0000_02_00_0") choose the card
- * with this id_path_tag.
- */
- if (!strcmp(prime,"1")) {
- /* Hmm... detection for 2-7 seems to be broken. Oh well ...
- * Pick the first render device that is not our own.
- */
- for (i = 0; i < num_devices; i++) {
- if (devices[i]->available_nodes & 1 << DRM_NODE_RENDER &&
- !drm_device_matches_tag(devices[i], default_tag)) {
+ for (i = 0; i < num_devices; i++) {
+ if (!(devices[i]->available_nodes & 1 << DRM_NODE_RENDER))
+ continue;
- found = true;
+ /* two formats of DRI_PRIME are supported:
+ * "1": choose any other card than the card used by default.
+ * id_path_tag: (for example "pci-0000_02_00_0") choose the card
+ * with this id_path_tag.
+ */
+ if (!strcmp(prime,"1")) {
+ if (!drm_device_matches_tag(devices[i], default_tag)) {
+ fd = loader_open_device(devices[i]->nodes[DRM_NODE_RENDER]);
break;
}
- }
- } else {
- for (i = 0; i < num_devices; i++) {
- if (devices[i]->available_nodes & 1 << DRM_NODE_RENDER &&
- drm_device_matches_tag(devices[i], prime)) {
-
- found = true;
+ } else {
+ if (drm_device_matches_tag(devices[i], prime)) {
+ fd = loader_open_device(devices[i]->nodes[DRM_NODE_RENDER]);
break;
}
}
}
+ drmFreeDevices(devices, num_devices);
- if (!found) {
- drmFreeDevices(devices, num_devices);
+ if (i == num_devices)
goto err;
- }
- fd = loader_open_device(devices[i]->nodes[DRM_NODE_RENDER]);
- drmFreeDevices(devices, num_devices);
if (fd < 0)
goto err;
--
2.20.1
More information about the mesa-dev
mailing list