]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nodedev: Dereference the obj/def in virNodeDeviceObjListFind* APIs
authorJohn Ferlan <jferlan@redhat.com>
Mon, 15 May 2017 14:20:51 +0000 (10:20 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 17 Jul 2017 14:40:24 +0000 (10:40 -0400)
Create local @obj and @def for the API's rather than referencing the
devs->objs[i][->def->].  It'll make future patches easier to read.

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/conf/virnodedeviceobj.c

index 2beec4959e9993b27d154f5fd522aa722099aa2f..bcd2324a931aaff4e0a6b19493252e9fad4c8b7e 100644 (file)
@@ -171,12 +171,16 @@ virNodeDeviceObjListFindBySysfsPath(virNodeDeviceObjListPtr devs,
     size_t i;
 
     for (i = 0; i < devs->count; i++) {
-        virNodeDeviceObjLock(devs->objs[i]);
-        if ((devs->objs[i]->def->sysfs_path != NULL) &&
-            (STREQ(devs->objs[i]->def->sysfs_path, sysfs_path))) {
-            return devs->objs[i];
+        virNodeDeviceObjPtr obj = devs->objs[i];
+        virNodeDeviceDefPtr def;
+
+        virNodeDeviceObjLock(obj);
+        def = obj->def;
+        if ((def->sysfs_path != NULL) &&
+            (STREQ(def->sysfs_path, sysfs_path))) {
+            return obj;
         }
-        virNodeDeviceObjUnlock(devs->objs[i]);
+        virNodeDeviceObjUnlock(obj);
     }
 
     return NULL;
@@ -190,10 +194,14 @@ virNodeDeviceObjListFindByName(virNodeDeviceObjListPtr devs,
     size_t i;
 
     for (i = 0; i < devs->count; i++) {
-        virNodeDeviceObjLock(devs->objs[i]);
-        if (STREQ(devs->objs[i]->def->name, name))
-            return devs->objs[i];
-        virNodeDeviceObjUnlock(devs->objs[i]);
+        virNodeDeviceObjPtr obj = devs->objs[i];
+        virNodeDeviceDefPtr def;
+
+        virNodeDeviceObjLock(obj);
+        def = obj->def;
+        if (STREQ(def->name, name))
+            return obj;
+        virNodeDeviceObjUnlock(obj);
     }
 
     return NULL;
@@ -208,14 +216,16 @@ virNodeDeviceObjListFindByWWNs(virNodeDeviceObjListPtr devs,
     size_t i;
 
     for (i = 0; i < devs->count; i++) {
+        virNodeDeviceObjPtr obj = devs->objs[i];
         virNodeDevCapsDefPtr cap;
-        virNodeDeviceObjLock(devs->objs[i]);
-        if ((cap = virNodeDeviceFindFCCapDef(devs->objs[i])) &&
+
+        virNodeDeviceObjLock(obj);
+        if ((cap = virNodeDeviceFindFCCapDef(obj)) &&
             STREQ_NULLABLE(cap->data.scsi_host.wwnn, parent_wwnn) &&
             STREQ_NULLABLE(cap->data.scsi_host.wwpn, parent_wwpn) &&
-            virNodeDeviceFindVPORTCapDef(devs->objs[i]))
-            return devs->objs[i];
-        virNodeDeviceObjUnlock(devs->objs[i]);
+            virNodeDeviceFindVPORTCapDef(obj))
+            return obj;
+        virNodeDeviceObjUnlock(obj);
     }
 
     return NULL;
@@ -229,13 +239,15 @@ virNodeDeviceObjListFindByFabricWWN(virNodeDeviceObjListPtr devs,
     size_t i;
 
     for (i = 0; i < devs->count; i++) {
+        virNodeDeviceObjPtr obj = devs->objs[i];
         virNodeDevCapsDefPtr cap;
-        virNodeDeviceObjLock(devs->objs[i]);
-        if ((cap = virNodeDeviceFindFCCapDef(devs->objs[i])) &&
+
+        virNodeDeviceObjLock(obj);
+        if ((cap = virNodeDeviceFindFCCapDef(obj)) &&
             STREQ_NULLABLE(cap->data.scsi_host.fabric_wwn, parent_fabric_wwn) &&
-            virNodeDeviceFindVPORTCapDef(devs->objs[i]))
-            return devs->objs[i];
-        virNodeDeviceObjUnlock(devs->objs[i]);
+            virNodeDeviceFindVPORTCapDef(obj))
+            return obj;
+        virNodeDeviceObjUnlock(obj);
     }
 
     return NULL;
@@ -249,10 +261,12 @@ virNodeDeviceObjListFindByCap(virNodeDeviceObjListPtr devs,
     size_t i;
 
     for (i = 0; i < devs->count; i++) {
-        virNodeDeviceObjLock(devs->objs[i]);
-        if (virNodeDeviceObjHasCap(devs->objs[i], cap))
-            return devs->objs[i];
-        virNodeDeviceObjUnlock(devs->objs[i]);
+        virNodeDeviceObjPtr obj = devs->objs[i];
+
+        virNodeDeviceObjLock(obj);
+        if (virNodeDeviceObjHasCap(obj, cap))
+            return obj;
+        virNodeDeviceObjUnlock(obj);
     }
 
     return NULL;