]> xenbits.xensource.com Git - libvirt.git/commitdiff
src/phyp: Utilize more of VIR_(APPEND|INSERT|DELETE)_ELEMENT
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 7 Mar 2014 08:33:31 +0000 (09:33 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 10 Mar 2014 12:45:10 +0000 (13:45 +0100)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/phyp/phyp_driver.c
src/phyp/phyp_driver.h

index 9adb6b05fe6486b251f2fb8f30c360d540043be8..e819256699e740c710a92b507a1441322393fba0 100644 (file)
@@ -570,19 +570,16 @@ phypUUIDTable_AddLpar(virConnectPtr conn, unsigned char *uuid, int id)
 {
     phyp_driverPtr phyp_driver = conn->privateData;
     uuid_tablePtr uuid_table = phyp_driver->uuid_table;
+    lparPtr item = NULL;
 
-    uuid_table->nlpars++;
-    size_t i = uuid_table->nlpars;
-    i--;
-
-    if (VIR_REALLOC_N(uuid_table->lpars, uuid_table->nlpars) < 0)
+    if (VIR_ALLOC(item) < 0)
         goto err;
 
-    if (VIR_ALLOC(uuid_table->lpars[i]) < 0)
-        goto err;
+    item->id = id;
+    memcpy(item->uuid, uuid, VIR_UUID_BUFLEN);
 
-    uuid_table->lpars[i]->id = id;
-    memcpy(uuid_table->lpars[i]->uuid, uuid, VIR_UUID_BUFLEN);
+    if (VIR_APPEND_ELEMENT_COPY(uuid_table->lpars, uuid_table->nlpars, item) < 0)
+        goto err;
 
     if (phypUUIDTable_WriteFile(conn) == -1)
         goto err;
@@ -593,6 +590,7 @@ phypUUIDTable_AddLpar(virConnectPtr conn, unsigned char *uuid, int id)
     return 0;
 
 err:
+    VIR_FREE(item);
     return -1;
 }
 
index ad05b15dafa3fb999a0c45c3f4cf1d707ee0ebb8..a5e736936930e05467682944353241b61e1b0a92 100644 (file)
@@ -56,7 +56,7 @@ struct _lpar {
 typedef struct _uuid_table uuid_table_t;
 typedef uuid_table_t *uuid_tablePtr;
 struct _uuid_table {
-    int nlpars;
+    size_t nlpars;
     lparPtr *lpars;
 };