[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 9/9] Remove conn parameter from USB functions



It was used for error reporting only.
---
 src/qemu/qemu_security_dac.c    |   10 ++++------
 src/security/security_selinux.c |   10 ++++------
 src/security/virt-aa-helper.c   |   15 +++++++--------
 src/util/hostusb.c              |   29 +++++++++++++----------------
 src/util/hostusb.h              |    6 ++----
 5 files changed, 30 insertions(+), 40 deletions(-)

diff --git a/src/qemu/qemu_security_dac.c b/src/qemu/qemu_security_dac.c
index f06a8bc..e753490 100644
--- a/src/qemu/qemu_security_dac.c
+++ b/src/qemu/qemu_security_dac.c
@@ -210,8 +210,7 @@ qemuSecurityDACSetSecurityHostdevLabel(virConnectPtr conn,
 
     switch (dev->source.subsys.type) {
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
-        usbDevice *usb = usbGetDevice(conn,
-                                      dev->source.subsys.u.usb.bus,
+        usbDevice *usb = usbGetDevice(dev->source.subsys.u.usb.bus,
                                       dev->source.subsys.u.usb.device,
                                       dev->source.subsys.u.usb.vendor,
                                       dev->source.subsys.u.usb.product);
@@ -220,7 +219,7 @@ qemuSecurityDACSetSecurityHostdevLabel(virConnectPtr conn,
             goto done;
 
         ret = usbDeviceFileIterate(conn, usb, qemuSecurityDACSetSecurityUSBLabel, vm);
-        usbFreeDevice(conn, usb);
+        usbFreeDevice(usb);
         break;
     }
 
@@ -285,8 +284,7 @@ qemuSecurityDACRestoreSecurityHostdevLabel(virConnectPtr conn,
 
     switch (dev->source.subsys.type) {
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
-        usbDevice *usb = usbGetDevice(conn,
-                                      dev->source.subsys.u.usb.bus,
+        usbDevice *usb = usbGetDevice(dev->source.subsys.u.usb.bus,
                                       dev->source.subsys.u.usb.device,
                                       dev->source.subsys.u.usb.vendor,
                                       dev->source.subsys.u.usb.product);
@@ -295,7 +293,7 @@ qemuSecurityDACRestoreSecurityHostdevLabel(virConnectPtr conn,
             goto done;
 
         ret = usbDeviceFileIterate(conn, usb, qemuSecurityDACRestoreSecurityUSBLabel, NULL);
-        usbFreeDevice(conn, usb);
+        usbFreeDevice(usb);
 
         break;
     }
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index 902ace0..a97d3de 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -498,8 +498,7 @@ SELinuxSetSecurityHostdevLabel(virConnectPtr conn,
 
     switch (dev->source.subsys.type) {
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
-        usbDevice *usb = usbGetDevice(conn,
-                                      dev->source.subsys.u.usb.bus,
+        usbDevice *usb = usbGetDevice(dev->source.subsys.u.usb.bus,
                                       dev->source.subsys.u.usb.device,
                                       dev->source.subsys.u.usb.vendor,
                                       dev->source.subsys.u.usb.product);
@@ -508,7 +507,7 @@ SELinuxSetSecurityHostdevLabel(virConnectPtr conn,
             goto done;
 
         ret = usbDeviceFileIterate(conn, usb, SELinuxSetSecurityUSBLabel, vm);
-        usbFreeDevice(conn, usb);
+        usbFreeDevice(usb);
         break;
     }
 
@@ -572,8 +571,7 @@ SELinuxRestoreSecurityHostdevLabel(virConnectPtr conn,
 
     switch (dev->source.subsys.type) {
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
-        usbDevice *usb = usbGetDevice(conn,
-                                      dev->source.subsys.u.usb.bus,
+        usbDevice *usb = usbGetDevice(dev->source.subsys.u.usb.bus,
                                       dev->source.subsys.u.usb.device,
                                       dev->source.subsys.u.usb.vendor,
                                       dev->source.subsys.u.usb.product);
@@ -582,7 +580,7 @@ SELinuxRestoreSecurityHostdevLabel(virConnectPtr conn,
             goto done;
 
         ret = usbDeviceFileIterate(conn, usb, SELinuxRestoreSecurityUSBLabel, NULL);
-        usbFreeDevice(conn, usb);
+        usbFreeDevice(usb);
 
         break;
     }
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index 81ba1ae..619c8c3 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -836,25 +836,24 @@ get_files(vahControl * ctl)
             virDomainHostdevDefPtr dev = ctl->def->hostdevs[i];
             switch (dev->source.subsys.type) {
             case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: {
-                usbDevice *usb = usbGetDevice(NULL,
-                                          dev->source.subsys.u.usb.bus,
-                                          dev->source.subsys.u.usb.device,
-                                          dev->source.subsys.u.usb.vendor,
-                                          dev->source.subsys.u.usb.product);
+                usbDevice *usb = usbGetDevice(dev->source.subsys.u.usb.bus,
+                                              dev->source.subsys.u.usb.device,
+                                              dev->source.subsys.u.usb.vendor,
+                                              dev->source.subsys.u.usb.product);
 
                 if (usb == NULL)
                     continue;
 
                 rc = usbDeviceFileIterate(NULL, usb,
                                           file_iterate_cb, &buf);
-                usbFreeDevice(NULL, usb);
+                usbFreeDevice(usb);
                 if (rc != 0)
                     goto clean;
                 break;
             }
 /* TODO: update so files in /sys are readonly
             case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
-                pciDevice *pci = pciGetDevice(NULL,
+                pciDevice *pci = pciGetDevice(
                            dev->source.subsys.u.pci.domain,
                            dev->source.subsys.u.pci.bus,
                            dev->source.subsys.u.pci.slot,
@@ -864,7 +863,7 @@ get_files(vahControl * ctl)
                     continue;
 
                 rc = pciDeviceFileIterate(NULL, pci, file_iterate_cb, &buf);
-                pciFreeDevice(NULL, pci);
+                pciFreeDevice(pci);
 
                 break;
             }
diff --git a/src/util/hostusb.c b/src/util/hostusb.c
index 96ece38..7ed262b 100644
--- a/src/util/hostusb.c
+++ b/src/util/hostusb.c
@@ -54,12 +54,11 @@ struct _usbDevice {
 /* For virReportOOMError()  and virReportSystemError() */
 #define VIR_FROM_THIS VIR_FROM_NONE
 
-#define usbReportError(conn, code, fmt...)                     \
-    virReportErrorHelper(conn, VIR_FROM_NONE, code, __FILE__,  \
+#define usbReportError(code, fmt...)                           \
+    virReportErrorHelper(NULL, VIR_FROM_NONE, code, __FILE__,  \
                          __FUNCTION__, __LINE__, fmt)
 
-static int usbSysReadFile(virConnectPtr conn,
-                          const char *f_name, const char *d_name,
+static int usbSysReadFile(const char *f_name, const char *d_name,
                           int base, unsigned *value)
 {
     int ret = -1, tmp;
@@ -77,7 +76,7 @@ static int usbSysReadFile(virConnectPtr conn,
         goto cleanup;
 
     if (virStrToLong_ui(buf, &ignore, base, value) < 0) {
-        usbReportError(conn, VIR_ERR_INTERNAL_ERROR,
+        usbReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Could not parse usb file %s"), filename);
         goto cleanup;
     }
@@ -89,8 +88,7 @@ cleanup:
     return ret;
 }
 
-static int usbFindBusByVendor(virConnectPtr conn,
-                              unsigned vendor, unsigned product,
+static int usbFindBusByVendor(unsigned vendor, unsigned product,
                               unsigned *bus, unsigned *devno)
 {
     DIR *dir = NULL;
@@ -111,10 +109,10 @@ static int usbFindBusByVendor(virConnectPtr conn,
         if (de->d_name[0] == '.' || strchr(de->d_name, ':'))
             continue;
 
-        if (usbSysReadFile(conn, "idVendor", de->d_name,
+        if (usbSysReadFile("idVendor", de->d_name,
                            16, &found_vend) < 0)
             goto cleanup;
-        if (usbSysReadFile(conn, "idProduct", de->d_name,
+        if (usbSysReadFile("idProduct", de->d_name,
                            16, &found_prod) < 0)
             goto cleanup;
 
@@ -127,13 +125,13 @@ static int usbFindBusByVendor(virConnectPtr conn,
                 tmpstr += 3;
 
             if (virStrToLong_ui(tmpstr, &ignore, 10, &found_bus) < 0) {
-                usbReportError(conn, VIR_ERR_INTERNAL_ERROR,
+                usbReportError(VIR_ERR_INTERNAL_ERROR,
                                _("Failed to parse dir name '%s'"),
                                de->d_name);
                 goto cleanup;
             }
 
-            if (usbSysReadFile(conn, "devnum", de->d_name,
+            if (usbSysReadFile("devnum", de->d_name,
                                10, &found_addr) < 0)
                 goto cleanup;
 
@@ -145,7 +143,7 @@ static int usbFindBusByVendor(virConnectPtr conn,
     }
 
     if (!found)
-        usbReportError(conn, VIR_ERR_INTERNAL_ERROR,
+        usbReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Did not find USB device %x:%x"), vendor, product);
     else
         ret = 0;
@@ -160,8 +158,7 @@ cleanup:
 }
 
 usbDevice *
-usbGetDevice(virConnectPtr conn,
-             unsigned bus,
+usbGetDevice(unsigned bus,
              unsigned devno,
              unsigned vendor,
              unsigned product)
@@ -175,7 +172,7 @@ usbGetDevice(virConnectPtr conn,
 
     if (vendor) {
         /* Look up bus.dev by vendor:product */
-        if (usbFindBusByVendor(conn, vendor, product, &bus, &devno) < 0) {
+        if (usbFindBusByVendor(vendor, product, &bus, &devno) < 0) {
             VIR_FREE(dev);
             return NULL;
         }
@@ -198,7 +195,7 @@ usbGetDevice(virConnectPtr conn,
 }
 
 void
-usbFreeDevice(virConnectPtr conn ATTRIBUTE_UNUSED, usbDevice *dev)
+usbFreeDevice(usbDevice *dev)
 {
     VIR_DEBUG("%s %s: freeing", dev->id, dev->name);
     VIR_FREE(dev);
diff --git a/src/util/hostusb.h b/src/util/hostusb.h
index 739a4aa..2579bdb 100644
--- a/src/util/hostusb.h
+++ b/src/util/hostusb.h
@@ -26,13 +26,11 @@
 
 typedef struct _usbDevice usbDevice;
 
-usbDevice *usbGetDevice      (virConnectPtr  conn,
-                              unsigned       bus,
+usbDevice *usbGetDevice      (unsigned       bus,
                               unsigned       devno,
                               unsigned       vendor,
                               unsigned       product);
-void       usbFreeDevice     (virConnectPtr  conn,
-                              usbDevice     *dev);
+void       usbFreeDevice     (usbDevice     *dev);
 
 /*
  * Callback that will be invoked once for each file
-- 
1.6.3.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]