loader: abstract loader_get_kernel_driver_name for reuse
authorQiang Yu <Qiang.Yu@amd.com>
Mon, 6 Aug 2018 03:19:25 +0000 (11:19 +0800)
committerEmil Velikov <emil.l.velikov@gmail.com>
Fri, 17 Aug 2018 16:16:32 +0000 (17:16 +0100)
This function can be shared by the following kernel_driver
drirc patch.

Signed-off-by: Qiang Yu <Qiang.Yu@amd.com>
Acked-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
src/loader/loader.c

index fda49521aae4056214d54e9366acccc818cb64b9..28a4c5855c99f40e2ce1b67e982c414bcbbc674c 100644 (file)
@@ -82,6 +82,26 @@ loader_open_device(const char *device_name)
    return fd;
 }
 
    return fd;
 }
 
+static char *loader_get_kernel_driver_name(int fd)
+{
+#if HAVE_LIBDRM
+   char *driver;
+   drmVersionPtr version = drmGetVersion(fd);
+
+   if (!version) {
+      log_(_LOADER_WARNING, "failed to get driver name for fd %d\n", fd);
+      return NULL;
+   }
+
+   driver = strndup(version->name, version->name_len);
+
+   drmFreeVersion(version);
+   return driver;
+#else
+   return NULL;
+#endif
+}
+
 #if defined(HAVE_LIBDRM)
 #ifdef USE_DRICONF
 static const char __driConfigOptionsLoader[] =
 #if defined(HAVE_LIBDRM)
 #ifdef USE_DRICONF
 static const char __driConfigOptionsLoader[] =
@@ -339,22 +359,9 @@ loader_get_driver_for_fd(int fd)
    }
 
    if (!loader_get_pci_id_for_fd(fd, &vendor_id, &chip_id)) {
    }
 
    if (!loader_get_pci_id_for_fd(fd, &vendor_id, &chip_id)) {
-
-#if HAVE_LIBDRM
-      /* fallback to drmGetVersion(): */
-      drmVersionPtr version = drmGetVersion(fd);
-
-      if (!version) {
-         log_(_LOADER_WARNING, "failed to get driver name for fd %d\n", fd);
-         return NULL;
-      }
-
-      driver = strndup(version->name, version->name_len);
-      log_(_LOADER_INFO, "using driver %s for %d\n", driver, fd);
-
-      drmFreeVersion(version);
-#endif
-
+      driver = loader_get_kernel_driver_name(fd);
+      if (driver)
+         log_(_LOADER_INFO, "using driver %s for %d\n", driver, fd);
       return driver;
    }
 
       return driver;
    }