summaryrefslogtreecommitdiffstats
path: root/src/loader/loader.c
diff options
context:
space:
mode:
authorQiang Yu <[email protected]>2018-08-06 11:19:25 +0800
committerEmil Velikov <[email protected]>2018-08-17 17:16:32 +0100
commite8b91e99e9965fa717be25da66fba0cdc3aef5dc (patch)
tree1e397156e48ef4981c3a33cf7439b82a5a07612e /src/loader/loader.c
parent30b10dbb7c6f6bdf3e489620f8333c727bd3a6dd (diff)
loader: abstract loader_get_kernel_driver_name for reuse
This function can be shared by the following kernel_driver drirc patch. Signed-off-by: Qiang Yu <[email protected]> Acked-by: Michel Dänzer <[email protected]> Reviewed-by: Emil Velikov <[email protected]>
Diffstat (limited to 'src/loader/loader.c')
-rw-r--r--src/loader/loader.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/src/loader/loader.c b/src/loader/loader.c
index fda49521aae..28a4c5855c9 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -82,6 +82,26 @@ loader_open_device(const char *device_name)
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[] =
@@ -339,22 +359,9 @@ loader_get_driver_for_fd(int fd)
}
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;
}