[Mesa-dev] [PATCH 5/8] loader: Move loader_get_driver_for_fd() into the three different #ifdef cases

Emil Velikov emil.l.velikov at gmail.com
Fri Feb 7 01:46:51 CET 2014


Having one function that tries to accomodate the different decision trees
for the three different #ifdef cases makes the logic hard to follow.  Now
that most of the complexity in loader_get_driver_for_fd() has been split
out in helper functions, we can just move loader_get_driver_for_fd() into
the #ifdefs and simplify the code for each case.

Signed-off-by: Kristian Høgsberg <krh at bitplanet.net>

v2:
 - change patch order and rebase (Emil)

Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
 src/loader/loader.c | 68 ++++++++++++++++++++++++++++++++---------------------
 1 file changed, 41 insertions(+), 27 deletions(-)

diff --git a/src/loader/loader.c b/src/loader/loader.c
index 2c72628..db14a74 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -299,6 +299,29 @@ out:
    return (*chip_id >= 0);
 }
 
+char *
+loader_get_driver_for_fd(int fd, unsigned int driver_types)
+{
+   int vendor_id, chip_id = -1;
+   char *driver = NULL;
+
+   if (!driver_types)
+      driver_types = _LOADER_GALLIUM | _LOADER_DRI;
+
+   driver = loader_get_hwdb_driver_for_fd(fd);
+   if (driver == NULL) {
+      if (!loader_get_pci_id_for_fd(fd, &vendor_id, &chip_id))
+         return fallback_to_kernel_name(fd);
+
+      driver = lookup_driver_for_pci_id(vendor_id, chip_id, driver_types);
+   }
+
+   if (driver == NULL)
+      log_(_LOADER_WARNING, "no driver %s for %d\n", fd);
+
+   return driver;
+}
+
 #elif defined(ANDROID) && !defined(__NOT_HAVE_DRM_H)
 
 /* for i915 */
@@ -376,20 +399,34 @@ loader_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
    return (*chip_id >= 0);
 }
 
-#else
-
 char *
-loader_get_hwdb_driver_for_fd(int fd)
+loader_get_driver_for_fd(int fd, unsigned int driver_types)
 {
-   return NULL
+   int vendor_id, chip_id;
+
+   if (!driver_types)
+      driver_types = _LOADER_GALLIUM | _LOADER_DRI;
+
+   if (!loader_get_pci_id_for_fd(fd, &vendor_id, &chip_id))
+      return fallback_to_kernel_name(fd);
+
+   return lookup_driver_for_pci_id(vendor_id, chip_id, driver_types);
 }
 
+#else
+
 int
 loader_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
 {
    return 0;
 }
 
+char *
+loader_get_driver_for_fd(int fd, unsigned int driver_types)
+{
+   return fallback_to_kernel_name(fd);
+}
+
 #endif
 
 
@@ -425,29 +462,6 @@ out:
    return device_name;
 }
 
-char *
-loader_get_driver_for_fd(int fd, unsigned int driver_types)
-{
-   int vendor_id, chip_id;
-   char *driver = NULL;
-
-   if (!driver_types)
-      driver_types = _LOADER_GALLIUM | _LOADER_DRI;
-
-   driver = loader_get_hwdb_driver_for_fd(fd);
-   if (driver == NULL) {
-      if (!loader_get_pci_id_for_fd(fd, &vendor_id, &chip_id))
-         return fallback_to_kernel_name(fd);
-
-      driver = lookup_driver_for_pci_id(vendor_id, chip_id, driver_types);
-   }
-
-   if (driver == NULL)
-      log_(_LOADER_WARNING, "no driver %s for %d\n", fd);
-
-   return driver;
-}
-
 void
 loader_set_logger(void (*logger)(int level, const char *fmt, ...))
 {
-- 
1.8.5.2



More information about the mesa-dev mailing list