From 2cb686dd46df27e9600f9df734303ec57bb38772 Mon Sep 17 00:00:00 2001 From: Gurchetan Singh Date: Fri, 26 Jul 2019 18:51:56 -0700 Subject: [PATCH] virgl/gbm: blacklist certain drivers when querying rendernodes We don't want to open the vgem or pvr drivers. v2: return fd as-is as well (@davidriley) v3: order of loops (@davidriley) Reviewed-by: David Riley Signed-off-by: Gurchetan Singh --- src/virgl_gbm.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/virgl_gbm.c b/src/virgl_gbm.c index d445044..054fd0e 100644 --- a/src/virgl_gbm.c +++ b/src/virgl_gbm.c @@ -35,6 +35,7 @@ #include #include "util/u_math.h" +#include "util/u_memory.h" #include "pipe/p_state.h" #include "virgl_gbm.h" @@ -86,9 +87,13 @@ static const struct planar_layout triplanar_yuv_420_layout = { static int rendernode_open(void) { DIR *dir; - struct dirent *dir_ent; int ret, fd; + bool undesired_found; + drmVersionPtr version; char *rendernode_name; + struct dirent *dir_ent; + const char *undesired[3] = { "vgem", "pvr", NULL }; + dir = opendir("/dev/dri"); if (!dir) return -1; @@ -103,21 +108,39 @@ static int rendernode_open(void) ret = asprintf(&rendernode_name, "/dev/dri/%s", dir_ent->d_name); if (ret < 0) - return -1; + goto out; fd = open(rendernode_name, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK); - if (fd < 0){ - free(rendernode_name); + free(rendernode_name); + + if (fd < 0) + continue; + + version = drmGetVersion(fd); + if (!version) { + close(fd); + fd = -1; + continue; + } + + undesired_found = false; + for (uint32_t i = 0; i < ARRAY_SIZE(undesired); i++) { + if (undesired[i] && !strcmp(version->name, undesired[i])) + undesired_found = true; + } + + drmFreeVersion(version); + if (undesired_found) { + close(fd); + fd = -1; continue; } - free(rendernode_name); break; } +out: closedir(dir); - if (fd < 0) - return -1; return fd; }