[Libva] [PATCH] drm: avoid double checks of authentication state.

Gwenole Beauchesne gb.devel at gmail.com
Tue Jul 16 08:05:18 PDT 2013


Avoid double checks of authentication state. Trust the outcome of
va_drm_authenticate() on the first vaInitialize() call with the
specified VA display.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne at intel.com>
---
 va/drm/va_drm.c      |   15 +++++----------
 va/drm/va_drm_auth.c |   35 -----------------------------------
 va/drm/va_drm_auth.h |    4 ----
 3 files changed, 5 insertions(+), 49 deletions(-)

diff --git a/va/drm/va_drm.c b/va/drm/va_drm.c
index 25bf8bb..fcbdef2 100644
--- a/va/drm/va_drm.c
+++ b/va/drm/va_drm.c
@@ -67,19 +67,14 @@ va_DisplayContextGetDriverName(
     if (status != VA_STATUS_SUCCESS)
         return status;
 
-    ret = drmGetMagic(drm_state->fd, &magic);
-    if (ret < 0)
-        return VA_STATUS_ERROR_OPERATION_FAILED;
-
-    if (!va_drm_is_authenticated(drm_state->fd)) {
-        if (!va_drm_authenticate(drm_state->fd, magic))
+    if (drm_state->auth_type != VA_DRM_AUTH_CUSTOM) {
+        ret = drmGetMagic(drm_state->fd, &magic);
+        if (ret < 0)
             return VA_STATUS_ERROR_OPERATION_FAILED;
-        if (!va_drm_is_authenticated(drm_state->fd))
+        if (!va_drm_authenticate(drm_state->fd, magic))
             return VA_STATUS_ERROR_OPERATION_FAILED;
+        drm_state->auth_type = VA_DRM_AUTH_CUSTOM;
     }
-
-    drm_state->auth_type = VA_DRM_AUTH_CUSTOM;
-
     return VA_STATUS_SUCCESS;
 }
 
diff --git a/va/drm/va_drm_auth.c b/va/drm/va_drm_auth.c
index 53794d3..592381d 100644
--- a/va/drm/va_drm_auth.c
+++ b/va/drm/va_drm_auth.c
@@ -28,41 +28,6 @@
 #include "va_drm_auth.h"
 #include "va_drm_auth_x11.h"
 
-#if defined __linux__
-# include <sys/syscall.h>
-#endif
-
-/* Checks whether the thread id is the current thread */
-static bool
-is_local_tid(pid_t tid)
-{
-#if defined __linux__
-    /* On Linux systems, drmGetClient() would return the thread ID
-       instead of the actual process ID */
-    return syscall(SYS_gettid) == tid;
-#else
-    return false;
-#endif
-}
-
-/* Checks whether DRM connection is authenticated */
-bool
-va_drm_is_authenticated(int fd)
-{
-    pid_t client_pid;
-    int i, auth, pid, uid;
-    unsigned long magic, iocs;
-    bool is_authenticated = false;
-
-    client_pid = getpid();
-    for (i = 0; !is_authenticated; i++) {
-        if (drmGetClient(fd, i, &auth, &pid, &uid, &magic, &iocs) != 0)
-            break;
-        is_authenticated = auth && (pid == client_pid || is_local_tid(pid));
-    }
-    return is_authenticated;
-}
-
 /* Try to authenticate the DRM connection with the supplied magic id */
 bool
 va_drm_authenticate(int fd, uint32_t magic)
diff --git a/va/drm/va_drm_auth.h b/va/drm/va_drm_auth.h
index 1aa6989..a8ca794 100644
--- a/va/drm/va_drm_auth.h
+++ b/va/drm/va_drm_auth.h
@@ -30,10 +30,6 @@
 
 DLL_HIDDEN
 bool
-va_drm_is_authenticated(int fd);
-
-DLL_HIDDEN
-bool
 va_drm_authenticate(int fd, uint32_t magic);
 
 #endif /* VA_DRM_AUTH_H */
-- 
1.7.9.5



More information about the Libva mailing list