[PATCH v2 05/14] OdevAttribute: Add config_odev_get_attribute helper

Hans de Goede hdegoede at redhat.com
Tue Feb 4 12:49:11 CET 2014


Add a config_odev_get_attribute helper, and replace the diy looing over all
the attributes done in various places with calls to this helper.

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 config/config.c                            | 23 +++++++++++++++++++++++
 hw/xfree86/common/xf86platformBus.c        | 17 ++---------------
 hw/xfree86/os-support/linux/lnx_platform.c |  8 +-------
 include/hotplug.h                          |  3 +++
 4 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/config/config.c b/config/config.c
index 760cf19..64dfb88 100644
--- a/config/config.c
+++ b/config/config.c
@@ -145,6 +145,18 @@ config_odev_free_attribute_list(struct OdevAttributes *attribs)
     free(attribs);
 }
 
+static struct OdevAttribute *config_odev_find_attribute(
+    struct OdevAttributes *attribs, int attrib_id)
+{
+    struct OdevAttribute *oa;
+
+    xorg_list_for_each_entry(oa, &attribs->list, member) {
+        if (oa->attrib_id == attrib_id)
+          return oa;
+    }
+    return NULL;
+}
+
 Bool
 config_odev_add_attribute(struct OdevAttributes *attribs, int attrib,
                           const char *attrib_name)
@@ -161,6 +173,17 @@ config_odev_add_attribute(struct OdevAttributes *attribs, int attrib,
     return TRUE;
 }
 
+char *config_odev_get_attribute(struct OdevAttributes *attribs, int attrib_id)
+{
+    struct OdevAttribute *oa;
+
+    oa = config_odev_find_attribute(attribs, attrib_id);
+    if (!oa)
+        return NULL;
+
+    return oa->attrib_name;
+}
+
 void
 config_odev_free_attributes(struct OdevAttributes *attribs)
 {
diff --git a/hw/xfree86/common/xf86platformBus.c b/hw/xfree86/common/xf86platformBus.c
index 5875a91..6d3816d 100644
--- a/hw/xfree86/common/xf86platformBus.c
+++ b/hw/xfree86/common/xf86platformBus.c
@@ -92,26 +92,13 @@ xf86_add_platform_device_attrib(int index, int attrib_id, char *attrib_name)
 char *
 xf86_get_platform_attrib(int index, int attrib_id)
 {
-    struct xf86_platform_device *device = &xf86_platform_devices[index];
-    struct OdevAttribute *oa;
-
-    xorg_list_for_each_entry(oa, &device->attribs->list, member) {
-        if (oa->attrib_id == attrib_id)
-            return oa->attrib_name;
-    }
-    return NULL;
+    return config_odev_get_attribute(xf86_platform_devices[index].attribs, attrib_id);
 }
 
 char *
 xf86_get_platform_device_attrib(struct xf86_platform_device *device, int attrib_id)
 {
-    struct OdevAttribute *oa;
-
-    xorg_list_for_each_entry(oa, &device->attribs->list, member) {
-        if (oa->attrib_id == attrib_id)
-            return oa->attrib_name;
-    }
-    return NULL;
+    return config_odev_get_attribute(device->attribs, attrib_id);
 }
 
 Bool
diff --git a/hw/xfree86/os-support/linux/lnx_platform.c b/hw/xfree86/os-support/linux/lnx_platform.c
index 1865b31..4317209 100644
--- a/hw/xfree86/os-support/linux/lnx_platform.c
+++ b/hw/xfree86/os-support/linux/lnx_platform.c
@@ -118,17 +118,11 @@ xf86PlatformReprobeDevice(int index, struct OdevAttributes *attribs)
 void
 xf86PlatformDeviceProbe(struct OdevAttributes *attribs)
 {
-    struct OdevAttribute *attrib;
     int i;
     char *path = NULL;
     Bool ret;
 
-    xorg_list_for_each_entry(attrib, &attribs->list, member) {
-        if (attrib->attrib_id == ODEV_ATTRIB_PATH) {
-            path = attrib->attrib_name;
-            break;
-        }
-    }
+    path = config_odev_get_attribute(attribs, ODEV_ATTRIB_PATH);
     if (!path)
         goto out_free;
 
diff --git a/include/hotplug.h b/include/hotplug.h
index 29a22c4..ee7b7d7 100644
--- a/include/hotplug.h
+++ b/include/hotplug.h
@@ -53,6 +53,9 @@ Bool
 config_odev_add_attribute(struct OdevAttributes *attribs, int attrib,
                           const char *attrib_name);
 
+char *
+config_odev_get_attribute(struct OdevAttributes *attribs, int attrib_id);
+
 void
 config_odev_free_attributes(struct OdevAttributes *attribs);
 
-- 
1.8.5.3



More information about the xorg-devel mailing list