diff options
author | Emil Velikov <[email protected]> | 2019-02-19 15:30:40 +0000 |
---|---|---|
committer | Emil Velikov <[email protected]> | 2020-04-01 16:57:22 +0100 |
commit | 164f4a9a4a32b8e638ce3f3c684d147d70a3b1de (patch) | |
tree | 6f5de6299f18ab53972b9e686bcd5f5411d8e46b /src/loader | |
parent | 25b2b325885710dc7dc7539d6d37e77182767088 (diff) |
loader: simplify loader_get_user_preferred_fd()
Reoder the function a bit to make the code-flow more obvious and short.
Signed-off-by: Emil Velikov <[email protected]>
Reviewed-by: Adam Jackson <[email protected]>
Reviewed-by: Eric Engestrom <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4084>
Diffstat (limited to 'src/loader')
-rw-r--r-- | src/loader/loader.c | 51 |
1 files changed, 20 insertions, 31 deletions
diff --git a/src/loader/loader.c b/src/loader/loader.c index 96c1d4c0e6c..1a438a4fcc7 100644 --- a/src/loader/loader.c +++ b/src/loader/loader.c @@ -300,8 +300,7 @@ int loader_get_user_preferred_fd(int default_fd, bool *different_device) const char *dri_prime = getenv("DRI_PRIME"); char *default_tag, *prime = NULL; drmDevicePtr devices[MAX_DRM_DEVICES]; - int i, num_devices, fd; - bool found = false; + int i, num_devices, fd = -1; if (dri_prime) prime = strdup(dri_prime); @@ -320,44 +319,34 @@ int loader_get_user_preferred_fd(int default_fd, bool *different_device) goto err; num_devices = drmGetDevices2(0, devices, MAX_DRM_DEVICES); - if (num_devices < 0) + 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; - break; - } + /* 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)) + continue; + } else { + if (!drm_device_matches_tag(devices[i], prime)) + continue; } - } 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; - break; - } - } + 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; |