]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: usb: modify virUSBDeviceListAdd to take double pointer
authorSukrit Bhatnagar <skrtbhtngr@gmail.com>
Tue, 24 Jul 2018 15:52:23 +0000 (21:22 +0530)
committerErik Skultety <eskultet@redhat.com>
Fri, 27 Jul 2018 15:21:14 +0000 (17:21 +0200)
Modify virUSBDeviceListAdd to take a double pointer to
virUSBDevicePtr as the second argument. This will enable usage
of cleanup macros upon the virUSBDevicePtr item which is to be
added to the list as it will be cleared by virInsertElementsN
upon success.

Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/util/virhostdev.c
src/util/virusb.c
src/util/virusb.h
tests/virusbtest.c

index f4bd19df6453b480b2d3dc145d303925291cf36d..d5075acab01d1dad7d3f79ec030ccc41a207d6b4 100644 (file)
@@ -1236,7 +1236,7 @@ virHostdevUpdateActiveUSBDevices(virHostdevManagerPtr mgr,
 
         virUSBDeviceSetUsedBy(usb, drv_name, dom_name);
 
-        if (virUSBDeviceListAdd(mgr->activeUSBHostdevs, usb) < 0) {
+        if (virUSBDeviceListAdd(mgr->activeUSBHostdevs, &usb) < 0) {
             virUSBDeviceFree(usb);
             goto cleanup;
         }
@@ -1406,7 +1406,7 @@ virHostdevMarkUSBDevices(virHostdevManagerPtr mgr,
          * from the virUSBDeviceList that passed in on success,
          * perform rollback on failure.
          */
-        if (virUSBDeviceListAdd(mgr->activeUSBHostdevs, usb) < 0)
+        if (virUSBDeviceListAdd(mgr->activeUSBHostdevs, &usb) < 0)
             goto error;
     }
 
@@ -1555,7 +1555,7 @@ virHostdevPrepareUSBDevices(virHostdevManagerPtr mgr,
         if (virHostdevFindUSBDevice(hostdev, required, &usb) < 0)
             goto cleanup;
 
-        if (usb && virUSBDeviceListAdd(list, usb) < 0) {
+        if (usb && virUSBDeviceListAdd(list, &usb) < 0) {
             virUSBDeviceFree(usb);
             goto cleanup;
         }
index 2fe1bfc290c8cd28ce027d2a7399f9b970b31361..78182320ed4125e2b407c333af74d2da14e66f47 100644 (file)
@@ -181,7 +181,7 @@ virUSBDeviceSearch(unsigned int vendor,
         if (!usb)
             goto cleanup;
 
-        if (virUSBDeviceListAdd(list, usb) < 0) {
+        if (virUSBDeviceListAdd(list, &usb) < 0) {
             virUSBDeviceFree(usb);
             goto cleanup;
         }
@@ -463,15 +463,15 @@ virUSBDeviceListDispose(void *obj)
 
 int
 virUSBDeviceListAdd(virUSBDeviceListPtr list,
-                    virUSBDevicePtr dev)
+                    virUSBDevicePtr *dev)
 {
-    if (virUSBDeviceListFind(list, dev)) {
+    if (virUSBDeviceListFind(list, *dev)) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Device %s is already in use"),
-                       dev->name);
+                       (*dev)->name);
         return -1;
     }
-    return VIR_APPEND_ELEMENT(list->devs, list->count, dev);
+    return VIR_APPEND_ELEMENT(list->devs, list->count, *dev);
 }
 
 virUSBDevicePtr
index 716e8c6915746ed9ffa6d2adf8b615cf308fc81d..078dee69cd23c8ce88735ebd06bf10c691819561 100644 (file)
@@ -88,7 +88,7 @@ int virUSBDeviceFileIterate(virUSBDevicePtr dev,
 
 virUSBDeviceListPtr virUSBDeviceListNew(void);
 int virUSBDeviceListAdd(virUSBDeviceListPtr list,
-                        virUSBDevicePtr dev);
+                        virUSBDevicePtr *dev);
 virUSBDevicePtr virUSBDeviceListGet(virUSBDeviceListPtr list,
                                     int idx);
 size_t virUSBDeviceListCount(virUSBDeviceListPtr list);
index 8728fe9092b2c2582cdd3b998c59842fefcfbd39..05bba2b9bafdcc39364dc7c28e4fb729df596dc8 100644 (file)
@@ -173,7 +173,7 @@ testUSBList(const void *opaque ATTRIBUTE_UNUSED)
         dev = virUSBDeviceListGet(devlist, 0);
         dev = virUSBDeviceListSteal(devlist, dev);
 
-        if (virUSBDeviceListAdd(list, dev) < 0)
+        if (virUSBDeviceListAdd(list, &dev) < 0)
             goto cleanup;
         dev = NULL;
     }
@@ -196,7 +196,7 @@ testUSBList(const void *opaque ATTRIBUTE_UNUSED)
         dev = virUSBDeviceListGet(devlist, 0);
         dev = virUSBDeviceListSteal(devlist, dev);
 
-        if (virUSBDeviceListAdd(list, dev) < 0)
+        if (virUSBDeviceListAdd(list, &dev) < 0)
             goto cleanup;
         dev = NULL;
     }