Rather than taking an virNodeDeviceObjPtr and dereffing the obj->def,
just pass the def.
Also check for an error in the function to have the calling function goto
cleanup on error.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/node_device/node_device_driver.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index 2a461fb..87953f3 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -106,16 +106,16 @@ nodeDeviceUpdateCaps(virNodeDeviceObjPtr dev)
* udev *and* HAL backends.
*/
static int
-nodeDeviceUpdateDriverName(virNodeDeviceObjPtr dev)
+nodeDeviceUpdateDriverName(virNodeDeviceDefPtr def)
{
char *driver_link = NULL;
char *devpath = NULL;
char *p;
int ret = -1;
- VIR_FREE(dev->def->driver);
+ VIR_FREE(def->driver);
- if (virAsprintf(&driver_link, "%s/driver", dev->def->sysfs_path)
< 0)
+ if (virAsprintf(&driver_link, "%s/driver", def->sysfs_path) < 0)
goto cleanup;
/* Some devices don't have an explicit driver, so just return
@@ -132,7 +132,7 @@ nodeDeviceUpdateDriverName(virNodeDeviceObjPtr dev)
}
p = strrchr(devpath, '/');
- if (p && VIR_STRDUP(dev->def->driver, p + 1) < 0)
+ if (p && VIR_STRDUP(def->driver, p + 1) < 0)
goto cleanup;
ret = 0;
@@ -144,7 +144,7 @@ nodeDeviceUpdateDriverName(virNodeDeviceObjPtr dev)
#else
/* XXX: Implement me for non-linux */
static int
-nodeDeviceUpdateDriverName(virNodeDeviceObjPtr dev ATTRIBUTE_UNUSED)
+nodeDeviceUpdateDriverName(virNodeDeviceDefPtr def ATTRIBUTE_UNUSED)
{
return 0;
}
@@ -338,7 +338,9 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr dev,
if (virNodeDeviceGetXMLDescEnsureACL(dev->conn, obj->def) < 0)
goto cleanup;
- nodeDeviceUpdateDriverName(obj);
+ if (nodeDeviceUpdateDriverName(obj->def) < 0)
+ goto cleanup;
+
if (nodeDeviceUpdateCaps(obj) < 0)
goto cleanup;
--
2.9.4