LIBVA_DRIVER_NAME still needs va_getDriverName to open DRM device
authorFei Jiang <fei.jiang@intel.com>
Wed, 27 Mar 2013 20:29:36 +0000 (04:29 +0800)
committerXiang, Haihao <haihao.xiang@intel.com>
Wed, 19 Jun 2013 06:34:12 +0000 (14:34 +0800)
va_getDriverName is bypassed when LIBVA_DRIVER_NAME is set, but driver
needs DRM device fd which is only opened in va_getDriverName

Change-Id: I4fe11edf9d8c328806255d4c93313cf99655a91d
Signed-off-by: Fei Jiang <fei.jiang@intel.com>
(cherry picked from commit 04706eb13ae410b53b6b38150413d544b7fdb524)

va/va.c

diff --git a/va/va.c b/va/va.c
index 400273e..3358119 100644 (file)
--- a/va/va.c
+++ b/va/va.c
@@ -449,24 +449,30 @@ VAStatus vaInitialize (
 
     va_infoMessage("VA-API version %s\n", VA_VERSION_S);
 
+    vaStatus = va_getDriverName(dpy, &driver_name);
+    va_infoMessage("va_getDriverName() returns %d\n", vaStatus);
+
     driver_name_env = getenv("LIBVA_DRIVER_NAME");
-    if (driver_name_env && geteuid() == getuid()) {
+    if ((VA_STATUS_SUCCESS == vaStatus) &&
+        driver_name_env && (geteuid() == getuid())) {
         /* Don't allow setuid apps to use LIBVA_DRIVER_NAME */
+        if (driver_name) /* memory is allocated in va_getDriverName */
+            free(driver_name);
+        
         driver_name = strdup(driver_name_env);
         vaStatus = VA_STATUS_SUCCESS;
         va_infoMessage("User requested driver '%s'\n", driver_name);
-    } else {
-        vaStatus = va_getDriverName(dpy, &driver_name);
-        va_infoMessage("va_getDriverName() returns %d\n", vaStatus);
     }
 
-    if (VA_STATUS_SUCCESS == vaStatus) {
+    if ((VA_STATUS_SUCCESS == vaStatus) && (driver_name != NULL)) {
         vaStatus = va_openDriver(dpy, driver_name);
         va_infoMessage("va_openDriver() returns %d\n", vaStatus);
 
         *major_version = VA_MAJOR_VERSION;
         *minor_version = VA_MINOR_VERSION;
-    }
+    } else
+        va_errorMessage("va_getDriverName() failed with %s,driver_name=%s\n",
+                        vaErrorStr(vaStatus), driver_name);
 
     if (driver_name)
         free(driver_name);