[Mesa-dev] [PATCH v3 3/8] loader: Factor out code to map PCI ID to driver name
Kristian Høgsberg
krh at bitplanet.net
Wed Feb 5 02:18:13 CET 2014
Making this its own function cleans up loader_get_driver_for_fd() a bit
and simplifies the control flow.
Signed-off-by: Kristian Høgsberg <krh at bitplanet.net>
---
src/loader/loader.c | 51 +++++++++++++++++++++++++++------------------------
1 file changed, 27 insertions(+), 24 deletions(-)
diff --git a/src/loader/loader.c b/src/loader/loader.c
index 51bac3e..88210df 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -92,6 +92,29 @@ static void default_logger(int level, const char *fmt, ...)
static void (*log_)(int level, const char *fmt, ...) = default_logger;
+static char *
+lookup_driver_for_pci_id(int vendor_id, int chip_id, unsigned int driver_types)
+{
+ int i, j;
+
+ for (i = 0; driver_map[i].driver; i++) {
+ if (vendor_id != driver_map[i].vendor_id)
+ continue;
+
+ if (!(driver_types & driver_map[i].driver_types))
+ continue;
+
+ if (driver_map[i].num_chips_ids == -1)
+ return strdup(driver_map[i].driver);
+
+ for (j = 0; j < driver_map[i].num_chips_ids; j++)
+ if (driver_map[i].chip_ids[j] == chip_id)
+ return strdup(driver_map[i].driver);
+ }
+
+ return NULL;
+}
+
#ifdef HAVE_LIBUDEV
#include <libudev.h>
@@ -326,9 +349,9 @@ out:
}
char *
-loader_get_driver_for_fd(int fd, unsigned driver_types)
+loader_get_driver_for_fd(int fd, unsigned int driver_types)
{
- int vendor_id, chip_id, i, j;
+ int vendor_id, chip_id;
char *driver = NULL;
if (!driver_types)
@@ -354,29 +377,9 @@ loader_get_driver_for_fd(int fd, unsigned driver_types)
return driver;
}
- if (driver)
- goto out;
-
- for (i = 0; driver_map[i].driver; i++) {
- if (vendor_id != driver_map[i].vendor_id)
- continue;
-
- if (!(driver_types & driver_map[i].driver_types))
- continue;
+ if (driver == NULL)
+ driver = lookup_driver_for_pci_id(vendor_id, chip_id, driver_types);
- if (driver_map[i].num_chips_ids == -1) {
- driver = strdup(driver_map[i].driver);
- goto out;
- }
-
- for (j = 0; j < driver_map[i].num_chips_ids; j++)
- if (driver_map[i].chip_ids[j] == chip_id) {
- driver = strdup(driver_map[i].driver);
- goto out;
- }
- }
-
-out:
if (driver && chip_id == -1) {
log_(_LOADER_INFO, "using driver %s from udev hwdb", driver);
} else {
--
1.8.4.2
More information about the mesa-dev
mailing list