minigbm: cros_gralloc: fix rendernode query
If the vgem driver and a hardware driver are both present on
a machine, and if the vgem driver corresponds to a lower
number rendernode, we'll end up picking the vgem driver. This is
not the desired behavior, so let's fix it.
BUG=chromium:616275
TEST=mediatek driver loads
CQ-DEPEND=CL:416396
Change-Id: Ib2647f4dbaf3c45fab97bbbcbb94e09c1daa6d5d
Reviewed-on: https://chromium-review.googlesource.com/416397
Commit-Ready: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
diff --git a/cros_gralloc/cros_gralloc_helpers.cc b/cros_gralloc/cros_gralloc_helpers.cc
index e5304a1..c38d8bc 100644
--- a/cros_gralloc/cros_gralloc_helpers.cc
+++ b/cros_gralloc/cros_gralloc_helpers.cc
@@ -86,9 +86,15 @@
}
static int32_t cros_gralloc_query_rendernode(struct driver **drv,
- const char *name)
+ const char *undesired)
{
- /* TODO(gsingh): Enable render nodes on udl/evdi. */
+ /*
+ * Create a driver from rendernode while filtering out
+ * the specified undesired driver.
+ *
+ * TODO(gsingh): Enable render nodes on udl/evdi.
+ */
+
int fd;
drmVersionPtr version;
char const *str = "%s/renderD%d";
@@ -109,8 +115,10 @@
continue;
version = drmGetVersion(fd);
+ if (!version)
+ continue;
- if (version && name && !strcmp(version->name, name)) {
+ if (undesired && !strcmp(version->name, undesired)) {
drmFreeVersion(version);
continue;
}
@@ -128,11 +136,11 @@
int32_t cros_gralloc_rendernode_open(struct driver **drv)
{
int32_t ret;
- ret = cros_gralloc_query_rendernode(drv, NULL);
+ ret = cros_gralloc_query_rendernode(drv, "vgem");
- /* Look for vgem driver if no hardware is found. */
+ /* Allow vgem driver if no hardware is found. */
if (ret)
- ret = cros_gralloc_query_rendernode(drv, "vgem");
+ ret = cros_gralloc_query_rendernode(drv, NULL);
return ret;
}