Since the @def is consumed by the assignment function, let's pass by
reference instead of value and really consume it.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/virnodedeviceobj.c | 8 ++++----
src/conf/virnodedeviceobj.h | 2 +-
src/node_device/node_device_hal.c | 2 +-
src/node_device/node_device_udev.c | 8 +++-----
src/test/test_driver.c | 5 ++---
5 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
index a7e51ef..1648b33 100644
--- a/src/conf/virnodedeviceobj.c
+++ b/src/conf/virnodedeviceobj.c
@@ -268,13 +268,13 @@ virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs)
virNodeDeviceObjPtr
virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs,
- virNodeDeviceDefPtr def)
+ virNodeDeviceDefPtr *def)
{
virNodeDeviceObjPtr obj;
- if ((obj = virNodeDeviceObjFindByName(devs, def->name))) {
+ if ((obj = virNodeDeviceObjFindByName(devs, (*def)->name))) {
virNodeDeviceDefFree(obj->def);
- obj->def = def;
+ VIR_STEAL_PTR(obj->def, *def);
return obj;
}
@@ -294,7 +294,7 @@ virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs,
virNodeDeviceObjFree(obj);
return NULL;
}
- obj->def = def;
+ VIR_STEAL_PTR(obj->def, *def);
return obj;
diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h
index 135a424..49c28e7 100644
--- a/src/conf/virnodedeviceobj.h
+++ b/src/conf/virnodedeviceobj.h
@@ -53,7 +53,7 @@ virNodeDeviceObjFindBySysfsPath(virNodeDeviceObjListPtr devs,
virNodeDeviceObjPtr
virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs,
- virNodeDeviceDefPtr def);
+ virNodeDeviceDefPtr *def);
void
virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs,
diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c
index e9031ea..2d996a9 100644
--- a/src/node_device/node_device_hal.c
+++ b/src/node_device/node_device_hal.c
@@ -482,7 +482,7 @@ dev_create(const char *udi)
/* Some devices don't have a path in sysfs, so ignore failure */
(void)get_str_prop(ctx, udi, "linux.sysfs_path", &devicePath);
- if (!(obj = virNodeDeviceObjAssignDef(&driver->devs, def))) {
+ if (!(obj = virNodeDeviceObjAssignDef(&driver->devs, &def))) {
VIR_FREE(devicePath);
goto failure;
}
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 83a8fcc..0250aab 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1395,7 +1395,7 @@ udevAddOneDevice(struct udev_device *device)
/* If this is a device change, the old definition will be freed
* and the current definition will take its place. */
- if (!(obj = virNodeDeviceObjAssignDef(&driver->devs, def)))
+ if (!(obj = virNodeDeviceObjAssignDef(&driver->devs, &def)))
goto cleanup;
objdef = virNodeDeviceObjGetDef(obj);
@@ -1685,8 +1685,7 @@ udevSetupSystemDev(void)
udevGetDMIData(&def->caps->data.system);
#endif
- obj = virNodeDeviceObjAssignDef(&driver->devs, def);
- if (obj == NULL)
+ if (!(obj = virNodeDeviceObjAssignDef(&driver->devs, &def)))
goto cleanup;
virNodeDeviceObjUnlock(obj);
@@ -1694,8 +1693,7 @@ udevSetupSystemDev(void)
ret = 0;
cleanup:
- if (ret == -1)
- virNodeDeviceDefFree(def);
+ virNodeDeviceDefFree(def);
return ret;
}
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 206fdf9..84ff1de 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1168,7 +1168,7 @@ testParseNodedevs(testDriverPtr privconn,
if (!def)
goto error;
- if (!(obj = virNodeDeviceObjAssignDef(&privconn->devs, def))) {
+ if (!(obj = virNodeDeviceObjAssignDef(&privconn->devs, &def))) {
virNodeDeviceDefFree(def);
goto error;
}
@@ -5491,9 +5491,8 @@ testNodeDeviceMockCreateVport(testDriverPtr driver,
caps = caps->next;
}
- if (!(obj = virNodeDeviceObjAssignDef(&driver->devs, def)))
+ if (!(obj = virNodeDeviceObjAssignDef(&driver->devs, &def)))
goto cleanup;
- def = NULL;
objdef = virNodeDeviceObjGetDef(obj);
event = virNodeDeviceEventLifecycleNew(objdef->name,
--
2.9.4