[PATCH v14 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 | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 577de48..5f61bfc 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -468,6 +468,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);
 
@@ -702,6 +707,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);
 
@@ -789,6 +799,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);
 
@@ -849,6 +864,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;
@@ -896,6 +916,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];
@@ -1094,6 +1119,11 @@ virHostdevPrepareUsbHostdevs(virHostdevManagerPtr hostdev_mgr,
     virUSBDevicePtr tmp;
     bool coldBoot = !!(flags & VIR_HOSTDEV_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
@@ -1163,6 +1193,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
@@ -1271,6 +1306,11 @@ virHostdevReAttachUsbHostdevs(virHostdevManagerPtr hostdev_mgr,
 {
     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];
@@ -1337,6 +1377,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];
@@ -1397,6 +1442,9 @@ virHostdevPciNodeDeviceDetach(virHostdevManagerPtr hostdev_mgr,
 {
     int ret = -1;
 
+    if (hostdev_mgr == NULL || pci == NULL)
+        return -1;
+
     virObjectLock(hostdev_mgr->activePciHostdevs);
     virObjectLock(hostdev_mgr->inactivePciHostdevs);
 
@@ -1419,6 +1467,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);
@@ -1459,6 +1510,9 @@ virHostdevPciNodeDeviceReset(virHostdevManagerPtr hostdev_mgr,
 {
     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,
@@ -1548,6 +1602,9 @@ virHostdevUpdateDomainActiveHostdevs(virHostdevManagerPtr mgr,
     if (!def->nhostdevs)
         return 0;
 
+    if (mgr == NULL)
+        return -1;
+
     if (flags & VIR_HOSTDEV_SP_PCI) {
         if (virHostdevUpdateActivePciHostdevs(mgr,
                                               def->hostdevs,
-- 
1.9.0

--
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]