}
p = strrchr(devpath, '/');
- if (p && VIR_STRDUP(def->driver, p + 1) < 0)
- goto cleanup;
+ if (p)
+ def->driver = g_strdup(p + 1);
ret = 0;
cleanup:
if (virNodeDeviceLookupByNameEnsureACL(conn, def) < 0)
goto cleanup;
- if ((device = virGetNodeDevice(conn, name))) {
- if (VIR_STRDUP(device->parentName, def->parent) < 0) {
- virObjectUnref(device);
- device = NULL;
- }
- }
+ if ((device = virGetNodeDevice(conn, name)))
+ device->parentName = g_strdup(def->parent);
cleanup:
virNodeDeviceObjEndAPI(&obj);
if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn, def) < 0)
goto cleanup;
- if ((device = virGetNodeDevice(conn, def->name))) {
- if (VIR_STRDUP(device->parentName, def->parent) < 0) {
- virObjectUnref(device);
- device = NULL;
- }
- }
+ if ((device = virGetNodeDevice(conn, def->name)))
+ device->parentName = g_strdup(def->parent);
cleanup:
virNodeDeviceObjEndAPI(&obj);
goto cleanup;
if (def->parent) {
- if (VIR_STRDUP(ret, def->parent) < 0)
- goto cleanup;
+ ret = g_strdup(def->parent);
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no parent for this device"));
if (ncaps > maxnames)
ncaps = maxnames;
- for (i = 0; i < ncaps; i++) {
- if (VIR_STRDUP(names[i], virNodeDevCapTypeToString(list[i])) < 0)
- goto cleanup;
- }
+ for (i = 0; i < ncaps; i++)
+ names[i] = g_strdup(virNodeDevCapTypeToString(list[i]));
ret = ncaps;
* event which would essentially free the existing @def (obj->def) and
* replace it with something new, we need to grab the parent field
* and then find the parent obj in order to manage the vport */
- if (VIR_STRDUP(parent, def->parent) < 0)
- goto cleanup;
+ parent = g_strdup(def->parent);
virNodeDeviceObjEndAPI(&obj);
const char *property_key,
char **value)
{
- if (VIR_STRDUP(*value,
- udevGetDeviceProperty(udev_device, property_key)) < 0)
- return -1;
+ *value = g_strdup(udevGetDeviceProperty(udev_device, property_key));
return 0;
}
const char *attr_name,
char **value)
{
- if (VIR_STRDUP(*value, udevGetDeviceSysfsAttr(udev_device, attr_name)) < 0)
- return -1;
+ *value = g_strdup(udevGetDeviceSysfsAttr(udev_device, attr_name));
virStringStripControlChars(*value);
NULL,
NULL);
- if (VIR_STRDUP(*vendor_string, vendor_name) < 0 ||
- VIR_STRDUP(*product_string, device_name) < 0)
- return -1;
+ *vendor_string = g_strdup(vendor_name);
+ *product_string = g_strdup(device_name);
return 0;
}
sysname = udev_device_get_sysname(device);
- if (VIR_STRDUP(scsi_target->name, sysname) < 0)
- return -1;
+ scsi_target->name = g_strdup(sysname);
virNodeDeviceGetSCSITargetCaps(def->sysfs_path, &def->caps->data.scsi_target);
* change it to cdrom to preserve compatibility with earlier
* versions of libvirt. */
VIR_FREE(def->caps->data.storage.drive_type);
- if (VIR_STRDUP(def->caps->data.storage.drive_type, "cdrom") < 0)
- return -1;
+ def->caps->data.storage.drive_type = g_strdup("cdrom");
if (udevHasDeviceProperty(device, "ID_CDROM_MEDIA") &&
udevGetIntProperty(device, "ID_CDROM_MEDIA", &has_media, 0) < 0)
def->sysfs_path);
/* virtio disk */
- if (STRPREFIX(def->caps->data.storage.block, "/dev/vd") &&
- VIR_STRDUP(def->caps->data.storage.drive_type, "disk") > 0) {
+ if (STRPREFIX(def->caps->data.storage.block, "/dev/vd")) {
+ def->caps->data.storage.drive_type = g_strdup("disk");
VIR_DEBUG("Found storage type '%s' for device "
"with sysfs path '%s'",
def->caps->data.storage.drive_type,
goto cleanup;
}
- if (VIR_STRDUP(storage->block, devnode) < 0)
- goto cleanup;
+ storage->block = g_strdup(devnode);
if (udevGetStringProperty(device, "ID_BUS", &storage->bus) < 0)
goto cleanup;
}
if (str) {
- if (VIR_STRDUP(storage->drive_type, str) < 0)
- goto cleanup;
+ storage->drive_type = g_strdup(str);
} else {
/* If udev doesn't have it, perhaps we can guess it. */
if (udevKludgeStorageType(def) != 0)
goto cleanup;
}
- if (VIR_STRDUP(data->type, last_component(canonicalpath)) < 0)
- goto cleanup;
+ data->type = g_strdup(last_component(canonicalpath));
uuidstr = udev_device_get_sysname(dev);
if ((iommugrp = virMediatedDeviceGetIOMMUGroupNum(uuidstr)) < 0)
devnode = udev_device_get_devnode(device);
- if (VIR_STRDUP(def->devnode, devnode) < 0)
- return -1;
+ def->devnode = g_strdup(devnode);
udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device))
n++;
n = 0;
udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device)) {
- if (VIR_STRDUP(def->devlinks[n++], udev_list_entry_get_name(list_entry)) < 0)
- return -1;
+ def->devlinks[n++] = g_strdup(udev_list_entry_get_name(list_entry));
}
return 0;
if ((obj = virNodeDeviceObjListFindBySysfsPath(driver->devs,
parent_sysfs_path))) {
objdef = virNodeDeviceObjGetDef(obj);
- if (VIR_STRDUP(def->parent, objdef->name) < 0) {
- virNodeDeviceObjEndAPI(&obj);
- goto cleanup;
- }
+ def->parent = g_strdup(objdef->name);
virNodeDeviceObjEndAPI(&obj);
- if (VIR_STRDUP(def->parent_sysfs_path, parent_sysfs_path) < 0)
- goto cleanup;
+ def->parent_sysfs_path = g_strdup(parent_sysfs_path);
}
} while (def->parent == NULL && parent_device != NULL);
if (VIR_ALLOC(def) != 0)
goto cleanup;
- if (VIR_STRDUP(def->sysfs_path, udev_device_get_syspath(device)) < 0)
- goto cleanup;
+ def->sysfs_path = g_strdup(udev_device_get_syspath(device));
if (udevGetStringProperty(device, "DRIVER", &def->driver) < 0)
goto cleanup;
if (VIR_ALLOC(def) < 0)
return -1;
- if (VIR_STRDUP(def->name, "computer") < 0)
- goto cleanup;
+ def->name = g_strdup("computer");
if (VIR_ALLOC(def->caps) != 0)
goto cleanup;