node_device: use g_strdup instead of VIR_STRDUP

Replace all occurrences of
  if (VIR_STRDUP(a, b) < 0)
     /* effectively dead code */
with:
  a = g_strdup(b);

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Ján Tomko 2019-10-20 13:49:46 +02:00
parent 4d81b800e2
commit 7f1f0453fc
3 changed files with 29 additions and 62 deletions

View File

@ -130,8 +130,8 @@ nodeDeviceUpdateDriverName(virNodeDeviceDefPtr def)
}
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:
@ -242,12 +242,8 @@ nodeDeviceLookupByName(virConnectPtr conn,
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);
@ -276,12 +272,8 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
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);
@ -335,8 +327,7 @@ nodeDeviceGetParent(virNodeDevicePtr device)
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"));
@ -396,10 +387,8 @@ nodeDeviceListCaps(virNodeDevicePtr 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;
@ -546,8 +535,7 @@ nodeDeviceDestroy(virNodeDevicePtr device)
* 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);

View File

@ -461,14 +461,10 @@ dev_create(const char *udi)
if (VIR_ALLOC(def) < 0)
goto failure;
if (VIR_STRDUP(def->name, name) < 0)
goto failure;
def->name = g_strdup(name);
if (get_str_prop(ctx, udi, "info.parent", &parent_key) == 0) {
if (VIR_STRDUP(def->parent, hal_name(parent_key)) < 0) {
VIR_FREE(parent_key);
goto failure;
}
def->parent = g_strdup(hal_name(parent_key));
VIR_FREE(parent_key);
}

View File

@ -154,9 +154,7 @@ udevGetStringProperty(struct udev_device *udev_device,
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;
}
@ -221,8 +219,7 @@ udevGetStringSysfsAttr(struct udev_device *udev_device,
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);
@ -345,9 +342,8 @@ udevTranslatePCIIds(unsigned int vendor,
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;
}
@ -641,8 +637,7 @@ udevProcessSCSITarget(struct udev_device *device,
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);
@ -830,8 +825,7 @@ udevProcessCDROM(struct udev_device *device,
* 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)
@ -892,8 +886,8 @@ udevKludgeStorageType(virNodeDeviceDefPtr def)
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,
@ -920,8 +914,7 @@ udevProcessStorage(struct udev_device *device,
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;
@ -972,8 +965,7 @@ udevProcessStorage(struct udev_device *device,
}
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)
@ -1052,8 +1044,7 @@ udevProcessMediatedDevice(struct udev_device *dev,
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)
@ -1111,8 +1102,7 @@ udevGetDeviceNodes(struct udev_device *device,
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++;
@ -1122,8 +1112,7 @@ udevGetDeviceNodes(struct udev_device *device,
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;
@ -1295,14 +1284,10 @@ udevSetParent(struct udev_device *device,
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);
@ -1330,8 +1315,7 @@ udevAddOneDevice(struct udev_device *device)
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;
@ -1735,8 +1719,7 @@ udevSetupSystemDev(void)
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;