[PATCH v13 45/49] add parameter checks to common interfaces

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

 



Check NULL parameter inputs

Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx>
---
 src/util/virhostdev.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 9c189a7..73844a6 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -440,6 +440,11 @@ virHostdevPreparePciHostdevs(virHostdevManagerPtr hostdev_mgr,
     size_t i;
     int ret = -1;
 
+    if (!nhostdevs)
+        return 0;
+    if (hostdev_mgr == NULL)
+        return -1;
+
     virObjectLock(hostdev_mgr->activePciHostdevs);
     virObjectLock(hostdev_mgr->inactivePciHostdevs);
 
@@ -675,6 +680,11 @@ virHostdevReAttachPciHostdevs(virHostdevManagerPtr hostdev_mgr,
     virPCIDeviceListPtr pcidevs;
     size_t i;
 
+    if (!nhostdevs)
+        return;
+    if (hostdev_mgr == NULL)
+        return;
+
     virObjectLock(hostdev_mgr->activePciHostdevs);
     virObjectLock(hostdev_mgr->inactivePciHostdevs);
 
@@ -763,6 +773,11 @@ virHostdevUpdateActivePciHostdevs(virHostdevManagerPtr mgr,
     size_t i;
     int ret = -1;
 
+    if (!nhostdevs)
+        return 0;
+    if (mgr == NULL)
+        return -1;
+
     virObjectLock(mgr->activePciHostdevs);
     virObjectLock(mgr->inactivePciHostdevs);
 
@@ -823,6 +838,11 @@ virHostdevUpdateActiveUsbHostdevs(virHostdevManagerPtr mgr,
     size_t i;
     int ret = -1;
 
+    if (!nhostdevs)
+        return 0;
+    if (mgr == NULL)
+        return -1;
+
     virObjectLock(mgr->activeUsbHostdevs);
     for (i = 0; i < nhostdevs; i++) {
         virUSBDevicePtr usb = NULL;
@@ -870,6 +890,11 @@ virHostdevUpdateActiveScsiHostdevs(virHostdevManagerPtr mgr,
     virSCSIDevicePtr scsi = NULL;
     virSCSIDevicePtr tmp = NULL;
 
+    if (!nhostdevs)
+        return 0;
+    if (mgr == NULL)
+        return -1;
+
     virObjectLock(mgr->activeScsiHostdevs);
     for (i = 0; i < nhostdevs; i++) {
         hostdev = hostdevs[i];
@@ -1068,6 +1093,11 @@ virHostdevPrepareUsbHostdevs(virHostdevManagerPtr hostdev_mgr,
     virUSBDevicePtr tmp;
     bool coldBoot = !!(flags & VIR_COLD_BOOT);
 
+    if (!nhostdevs)
+        return 0;
+    if (hostdev_mgr == NULL)
+        return -1;
+
     /* To prevent situation where USB device is assigned to two domains
      * we need to keep a list of currently assigned USB devices.
      * This is done in several loops which cannot be joined into one big
@@ -1137,6 +1167,11 @@ virHostdevPrepareScsiHostdevs(virHostdevManagerPtr hostdev_mgr,
     virSCSIDeviceListPtr list;
     virSCSIDevicePtr tmp;
 
+    if (!nhostdevs)
+        return 0;
+    if (hostdev_mgr == NULL)
+        return -1;
+
     /* To prevent situation where SCSI device is assigned to two domains
      * we need to keep a list of currently assigned SCSI devices.
      * This is done in several loops which cannot be joined into one big
@@ -1245,6 +1280,12 @@ virHostdevReAttachUsbHostdevs(virHostdevManagerPtr hostdev_mgr,
                               int nhostdevs)
 {
     size_t i;
+
+    if (!nhostdevs)
+        return;
+    if (hostdev_mgr == NULL)
+        return;
+
     virObjectLock(hostdev_mgr->activeUsbHostdevs);
     for (i = 0; i < nhostdevs; i++) {
         virDomainHostdevDefPtr hostdev = hostdevs[i];
@@ -1311,6 +1352,11 @@ virHostdevReAttachScsiHostdevs(virHostdevManagerPtr hostdev_mgr,
 {
     size_t i;
 
+    if (!nhostdevs)
+        return;
+    if (hostdev_mgr == NULL)
+        return;
+
     virObjectLock(hostdev_mgr->activeScsiHostdevs);
     for (i = 0; i < nhostdevs; i++) {
         virDomainHostdevDefPtr hostdev = hostdevs[i];
@@ -1371,6 +1417,9 @@ virHostdevPciNodeDeviceDetach(virHostdevManagerPtr hostdev_mgr,
 {
     int ret = -1;
 
+    if (hostdev_mgr == NULL || pci == NULL)
+        return -1;
+
     virObjectLock(hostdev_mgr->activePciHostdevs);
     virObjectLock(hostdev_mgr->inactivePciHostdevs);
 
@@ -1393,6 +1442,9 @@ virHostdevPciNodeDeviceReAttach(virHostdevManagerPtr hostdev_mgr,
     virPCIDevicePtr other;
     int ret = -1;
 
+    if (hostdev_mgr == NULL || pci == NULL)
+        return -1;
+
     virObjectLock(hostdev_mgr->activePciHostdevs);
     virObjectLock(hostdev_mgr->inactivePciHostdevs);
     other = virPCIDeviceListFind(hostdev_mgr->activePciHostdevs, pci);
@@ -1432,6 +1484,10 @@ virHostdevPciNodeDeviceReset(virHostdevManagerPtr hostdev_mgr,
                              virPCIDevicePtr pci)
 {
     int ret = -1;
+
+    if (hostdev_mgr == NULL || pci == NULL)
+        return -1;
+
     virObjectLock(hostdev_mgr->activePciHostdevs);
     virObjectLock(hostdev_mgr->inactivePciHostdevs);
     if (virPCIDeviceReset(pci, hostdev_mgr->activePciHostdevs,
@@ -1522,6 +1578,9 @@ virHostdevUpdateDomainActiveHostdevs(virHostdevManagerPtr mgr,
     if (!def->nhostdevs)
         return 0;
 
+    if (mgr == NULL)
+        return -1;
+
     if (flags & VIR_SP_PCI_HOSTDEV) {
         if (virHostdevUpdateActivePciHostdevs(mgr,
                                               def->hostdevs,
-- 
1.6.0.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]