OdevAttribute: Add config_odev_get_attribute helper

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

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Hans de Goede 2014-02-02 11:25:34 +01:00
parent 3346166a65
commit 10c64e8056
4 changed files with 30 additions and 22 deletions

View File

@ -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,18 @@ 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)
{

View File

@ -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

View File

@ -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;

View File

@ -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);