OdevAttribute: config_odev_add_attribute: replace existing values
authorHans de Goede <hdegoede@redhat.com>
Mon, 3 Feb 2014 14:47:35 +0000 (15:47 +0100)
committerHans de Goede <hdegoede@redhat.com>
Mon, 3 Mar 2014 07:13:55 +0000 (08:13 +0100)
If an attribute already exists replace its value rather than adding a
duplicate attribute with the new value to the list.

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>
config/config.c

index 088bd5a..776f1d8 100644 (file)
@@ -163,11 +163,14 @@ config_odev_add_attribute(struct OdevAttributes *attribs, int attrib,
 {
     struct OdevAttribute *oa;
 
-    oa = malloc(sizeof(struct OdevAttribute));
+    oa = config_odev_find_attribute(attribs, attrib);
+    if (!oa)
+        oa = calloc(1, sizeof(struct OdevAttribute));
     if (!oa)
         return FALSE;
 
     oa->attrib_id = attrib;
+    free(oa->attrib_name);
     oa->attrib_name = strdup(attrib_name);
     xorg_list_append(&oa->member, &attribs->list);
     return TRUE;