[libvirt] [PATCH v2 22/41] util: usb: modify virUSBDeviceListAdd to take double pointer

Sukrit Bhatnagar skrtbhtngr at gmail.com
Tue Jul 24 15:52:23 UTC 2018


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 at gmail.com>
---
 src/util/virhostdev.c |  6 +++---
 src/util/virusb.c     | 10 +++++-----
 src/util/virusb.h     |  2 +-
 tests/virusbtest.c    |  4 ++--
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index f4bd19d..d5075ac 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -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;
         }
diff --git a/src/util/virusb.c b/src/util/virusb.c
index 2fe1bfc..7818232 100644
--- a/src/util/virusb.c
+++ b/src/util/virusb.c
@@ -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
diff --git a/src/util/virusb.h b/src/util/virusb.h
index 716e8c6..078dee6 100644
--- a/src/util/virusb.h
+++ b/src/util/virusb.h
@@ -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);
diff --git a/tests/virusbtest.c b/tests/virusbtest.c
index 8728fe9..05bba2b 100644
--- a/tests/virusbtest.c
+++ b/tests/virusbtest.c
@@ -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;
     }
-- 
1.8.3.1




More information about the libvir-list mailing list