[Mesa-dev] [PATCH v3 7/8] loader: Move loader_get_driver_for_fd() into the three different #ifdef cases
Kristian Høgsberg
krh at bitplanet.net
Wed Feb 5 02:18:17 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>
---
src/loader/loader.c | 62 +++++++++++++++++++++++------------------------------
1 file changed, 27 insertions(+), 35 deletions(-)
diff --git a/src/loader/loader.c b/src/loader/loader.c
index 7131d46..9bd3561 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -212,8 +212,8 @@ udev_device_new_from_fd(struct udev *udev, int fd)
return device;
}
-static int
-loader_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id, char **driver)
+char *
+loader_get_driver_for_fd(int fd, unsigned int driver_types)
{
struct udev *udev = NULL;
struct udev_device *device = NULL, *parent;
@@ -227,9 +227,8 @@ loader_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id, char **driver)
(struct udev_device *));
UDEV_SYMBOL(struct udev *, udev_unref, (struct udev *));
const char *hwdb_driver;
-
- *chip_id = -1;
- *driver = NULL;
+ int vendor_id, chip_id;
+ char *driver = NULL;
udev = udev_new();
device = udev_device_new_from_fd(udev, fd);
@@ -245,25 +244,25 @@ loader_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id, char **driver)
hwdb_driver = udev_device_get_property_value(parent, "DRI_DRIVER");
if (hwdb_driver != NULL) {
log_(_LOADER_INFO, "using driver %s from udev hwdb", driver);
- *driver = strdup(hwdb_driver);
+ driver = strdup(hwdb_driver);
goto out;
}
pci_id = udev_device_get_property_value(parent, "PCI_ID");
- if (pci_id == NULL ||
- sscanf(pci_id, "%x:%x", vendor_id, chip_id) != 2) {
- log_(_LOADER_WARNING, "MESA-LOADER: malformed or no PCI ID\n");
- *chip_id = -1;
+ if (pci_id && sscanf(pci_id, "%x:%x", &vendor_id, &chip_id) == 2) {
+ driver = lookup_driver_for_pci_id(vendor_id, chip_id, driver_types);
goto out;
}
+ driver = fallback_to_kernel_name(fd);
+
out:
if (device)
udev_device_unref(device);
if (udev)
udev_unref(udev);
- return (*driver != NULL) || (*chip_id >= 0);
+ return driver;
}
#elif defined(ANDROID) && defined(__HAVE_DRM_H)
@@ -338,12 +337,26 @@ loader_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id, char **driver)
return (*chip_id >= 0);
}
+char *
+loader_get_driver_for_fd(int fd, unsigned int driver_types)
+{
+ 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, char **driver)
+char *
+loader_get_driver_for_fd(int fd, unsigned int driver_types)
{
- return 0;
+ return fallback_to_kernel_name(fd);
}
#endif
@@ -381,27 +394,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;
-
- if (!loader_get_pci_id_for_fd(fd, &vendor_id, &chip_id, &driver))
- return fallback_to_kernel_name(fd);
-
- if (driver == NULL)
- 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.4.2
More information about the mesa-dev
mailing list