[PATCH] drm: simplify device open

Daniel Drake drake at endlessm.com
Wed Nov 27 05:51:26 PST 2013


libdrm's open functions are just wrappers around open(), and our
detection of which parameter to pass to drmOpen() is not 100%
reliable.

Simplify the code and just call open() directly.

Fixes https://bugs.freedesktop.org/show_bug.cgi?id=71590
---
 src/plugins/renderers/drm/plugin.c | 45 ++------------------------------------
 1 file changed, 2 insertions(+), 43 deletions(-)

diff --git a/src/plugins/renderers/drm/plugin.c b/src/plugins/renderers/drm/plugin.c
index a845fff..241509f 100644
--- a/src/plugins/renderers/drm/plugin.c
+++ b/src/plugins/renderers/drm/plugin.c
@@ -399,42 +399,6 @@ destroy_backend (ply_renderer_backend_t *backend)
   free (backend);
 }
 
-static char *
-find_driver_for_device (const char *device_name)
-{
-  char *driver;
-  int major_number, minor_number;
-  struct stat file_attributes;
-  char *device_path;
-  char device_link_path[PATH_MAX + 1] = "";
-
-  if (stat (device_name, &file_attributes) < 0)
-    return NULL;
-
-  if (!S_ISCHR (file_attributes.st_mode))
-    return NULL;
-
-  major_number = major (file_attributes.st_rdev);
-  minor_number = minor (file_attributes.st_rdev);
-
-  asprintf (&device_path, "/sys/dev/char/%d:%d/device/driver",
-            major_number, minor_number);
-
-  if (readlink (device_path, device_link_path, sizeof (device_link_path) - 1) < 0)
-    {
-      free (device_path);
-      return NULL;
-    }
-  free (device_path);
-
-  driver = strrchr (device_link_path, '/');
-
-  if (driver == NULL)
-    return NULL;
-
-  return strdup (driver + strlen ("/"));
-}
-
 static void
 activate (ply_renderer_backend_t *backend)
 {
@@ -495,25 +459,20 @@ on_active_vt_changed (ply_renderer_backend_t *backend)
 static bool
 load_driver (ply_renderer_backend_t *backend)
 {
-  char *driver_name;
   int device_fd;
 
-  driver_name = find_driver_for_device (backend->device_name);
-  ply_trace ("Attempting to load driver '%s'", driver_name);
-  device_fd = drmOpen (driver_name, NULL);
+  ply_trace ("Opening '%s'", backend->device_name);
+  device_fd = open (backend->device_name, O_RDWR, 0);
 
   if (device_fd < 0)
     {
       ply_trace ("drmOpen failed");
-      free (driver_name);
       return false;
     }
 
   backend->driver_interface = ply_renderer_generic_driver_get_interface (device_fd);
   backend->driver_supports_mapping_console = false;
 
-  free (driver_name);
-
   if (backend->driver_interface == NULL)
     {
       close (device_fd);
-- 
1.8.1.2



More information about the plymouth mailing list