summaryrefslogtreecommitdiffstats
path: root/src/loader
diff options
context:
space:
mode:
authorEmil Velikov <[email protected]>2019-02-19 15:30:38 +0000
committerEmil Velikov <[email protected]>2020-04-01 16:57:22 +0100
commit25b2b325885710dc7dc7539d6d37e77182767088 (patch)
tree9f81da81faac1c83106b464f825174c886263f0c /src/loader
parentd3c91439713ecf025c7fe97aae3a4829b3f1250b (diff)
loader: use a maximum of 64 drmDevices
Currently that's the hard-coded maximum in the kernel, even though the libdrm API allows for more. Latter is done with extendability in mind. Allocate 64 pointers^Wdevices on stack for now. Making for shorter and ever-so-slightly faster code. v2: Use single MAX_DRM_DEVICES #define (Eric) Signed-off-by: Emil Velikov <[email protected]> Reviewed-by: Adam Jackson <[email protected]> (v1) 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.c37
1 files changed, 11 insertions, 26 deletions
diff --git a/src/loader/loader.c b/src/loader/loader.c
index a6ad2ee075b..96c1d4c0e6c 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -50,6 +50,7 @@
#ifdef HAVE_LIBDRM
#include <xf86drm.h>
+#define MAX_DRM_DEVICES 64
#ifdef USE_DRICONF
#include "util/xmlconfig.h"
#include "util/xmlpool.h"
@@ -132,27 +133,14 @@ is_kernel_i915(int fd)
int
loader_open_render_node(const char *name)
{
- drmDevicePtr *devices, device;
- int err, render = -ENOENT, fd;
- unsigned int num, i;
+ drmDevicePtr devices[MAX_DRM_DEVICES], device;
+ int i, num_devices, fd = -1;
- err = drmGetDevices2(0, NULL, 0);
- if (err < 0)
- return err;
-
- num = err;
-
- devices = calloc(num, sizeof(*devices));
- if (!devices)
- return -ENOMEM;
-
- err = drmGetDevices2(0, devices, num);
- if (err < 0) {
- render = err;
- goto free;
- }
+ num_devices = drmGetDevices2(0, devices, MAX_DRM_DEVICES);
+ if (num_devices <= 0)
+ return -ENOENT;
- for (i = 0; i < num; i++) {
+ for (i = 0; i < num_devices; i++) {
device = devices[i];
if ((device->available_nodes & (1 << DRM_NODE_RENDER)) &&
@@ -176,16 +164,15 @@ loader_open_render_node(const char *name)
}
drmFreeVersion(version);
- render = fd;
break;
}
}
+ drmFreeDevices(devices, num_devices);
- drmFreeDevices(devices, num);
+ if (i == num_devices)
+ return -ENOENT;
-free:
- free(devices);
- return render;
+ return fd;
}
#ifdef USE_DRICONF
@@ -310,8 +297,6 @@ static char *drm_get_id_path_tag_for_fd(int fd)
int loader_get_user_preferred_fd(int default_fd, bool *different_device)
{
-/* Arbitrary "maximum" value of drm devices. */
-#define MAX_DRM_DEVICES 32
const char *dri_prime = getenv("DRI_PRIME");
char *default_tag, *prime = NULL;
drmDevicePtr devices[MAX_DRM_DEVICES];