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, '/'); p = strrchr(devpath, '/');
if (p && VIR_STRDUP(def->driver, p + 1) < 0) if (p)
goto cleanup; def->driver = g_strdup(p + 1);
ret = 0; ret = 0;
cleanup: cleanup:
@ -242,12 +242,8 @@ nodeDeviceLookupByName(virConnectPtr conn,
if (virNodeDeviceLookupByNameEnsureACL(conn, def) < 0) if (virNodeDeviceLookupByNameEnsureACL(conn, def) < 0)
goto cleanup; goto cleanup;
if ((device = virGetNodeDevice(conn, name))) { if ((device = virGetNodeDevice(conn, name)))
if (VIR_STRDUP(device->parentName, def->parent) < 0) { device->parentName = g_strdup(def->parent);
virObjectUnref(device);
device = NULL;
}
}
cleanup: cleanup:
virNodeDeviceObjEndAPI(&obj); virNodeDeviceObjEndAPI(&obj);
@ -276,12 +272,8 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn, def) < 0) if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn, def) < 0)
goto cleanup; goto cleanup;
if ((device = virGetNodeDevice(conn, def->name))) { if ((device = virGetNodeDevice(conn, def->name)))
if (VIR_STRDUP(device->parentName, def->parent) < 0) { device->parentName = g_strdup(def->parent);
virObjectUnref(device);
device = NULL;
}
}
cleanup: cleanup:
virNodeDeviceObjEndAPI(&obj); virNodeDeviceObjEndAPI(&obj);
@ -335,8 +327,7 @@ nodeDeviceGetParent(virNodeDevicePtr device)
goto cleanup; goto cleanup;
if (def->parent) { if (def->parent) {
if (VIR_STRDUP(ret, def->parent) < 0) ret = g_strdup(def->parent);
goto cleanup;
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no parent for this device")); "%s", _("no parent for this device"));
@ -396,10 +387,8 @@ nodeDeviceListCaps(virNodeDevicePtr device,
if (ncaps > maxnames) if (ncaps > maxnames)
ncaps = maxnames; ncaps = maxnames;
for (i = 0; i < ncaps; i++) { for (i = 0; i < ncaps; i++)
if (VIR_STRDUP(names[i], virNodeDevCapTypeToString(list[i])) < 0) names[i] = g_strdup(virNodeDevCapTypeToString(list[i]));
goto cleanup;
}
ret = ncaps; ret = ncaps;
@ -546,8 +535,7 @@ nodeDeviceDestroy(virNodeDevicePtr device)
* event which would essentially free the existing @def (obj->def) and * event which would essentially free the existing @def (obj->def) and
* replace it with something new, we need to grab the parent field * replace it with something new, we need to grab the parent field
* and then find the parent obj in order to manage the vport */ * and then find the parent obj in order to manage the vport */
if (VIR_STRDUP(parent, def->parent) < 0) parent = g_strdup(def->parent);
goto cleanup;
virNodeDeviceObjEndAPI(&obj); virNodeDeviceObjEndAPI(&obj);

View File

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

View File

@ -154,9 +154,7 @@ udevGetStringProperty(struct udev_device *udev_device,
const char *property_key, const char *property_key,
char **value) char **value)
{ {
if (VIR_STRDUP(*value, *value = g_strdup(udevGetDeviceProperty(udev_device, property_key));
udevGetDeviceProperty(udev_device, property_key)) < 0)
return -1;
return 0; return 0;
} }
@ -221,8 +219,7 @@ udevGetStringSysfsAttr(struct udev_device *udev_device,
const char *attr_name, const char *attr_name,
char **value) char **value)
{ {
if (VIR_STRDUP(*value, udevGetDeviceSysfsAttr(udev_device, attr_name)) < 0) *value = g_strdup(udevGetDeviceSysfsAttr(udev_device, attr_name));
return -1;
virStringStripControlChars(*value); virStringStripControlChars(*value);
@ -345,9 +342,8 @@ udevTranslatePCIIds(unsigned int vendor,
NULL, NULL,
NULL); NULL);
if (VIR_STRDUP(*vendor_string, vendor_name) < 0 || *vendor_string = g_strdup(vendor_name);
VIR_STRDUP(*product_string, device_name) < 0) *product_string = g_strdup(device_name);
return -1;
return 0; return 0;
} }
@ -641,8 +637,7 @@ udevProcessSCSITarget(struct udev_device *device,
sysname = udev_device_get_sysname(device); sysname = udev_device_get_sysname(device);
if (VIR_STRDUP(scsi_target->name, sysname) < 0) scsi_target->name = g_strdup(sysname);
return -1;
virNodeDeviceGetSCSITargetCaps(def->sysfs_path, &def->caps->data.scsi_target); 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 * change it to cdrom to preserve compatibility with earlier
* versions of libvirt. */ * versions of libvirt. */
VIR_FREE(def->caps->data.storage.drive_type); VIR_FREE(def->caps->data.storage.drive_type);
if (VIR_STRDUP(def->caps->data.storage.drive_type, "cdrom") < 0) def->caps->data.storage.drive_type = g_strdup("cdrom");
return -1;
if (udevHasDeviceProperty(device, "ID_CDROM_MEDIA") && if (udevHasDeviceProperty(device, "ID_CDROM_MEDIA") &&
udevGetIntProperty(device, "ID_CDROM_MEDIA", &has_media, 0) < 0) udevGetIntProperty(device, "ID_CDROM_MEDIA", &has_media, 0) < 0)
@ -892,8 +886,8 @@ udevKludgeStorageType(virNodeDeviceDefPtr def)
def->sysfs_path); def->sysfs_path);
/* virtio disk */ /* virtio disk */
if (STRPREFIX(def->caps->data.storage.block, "/dev/vd") && if (STRPREFIX(def->caps->data.storage.block, "/dev/vd")) {
VIR_STRDUP(def->caps->data.storage.drive_type, "disk") > 0) { def->caps->data.storage.drive_type = g_strdup("disk");
VIR_DEBUG("Found storage type '%s' for device " VIR_DEBUG("Found storage type '%s' for device "
"with sysfs path '%s'", "with sysfs path '%s'",
def->caps->data.storage.drive_type, def->caps->data.storage.drive_type,
@ -920,8 +914,7 @@ udevProcessStorage(struct udev_device *device,
goto cleanup; goto cleanup;
} }
if (VIR_STRDUP(storage->block, devnode) < 0) storage->block = g_strdup(devnode);
goto cleanup;
if (udevGetStringProperty(device, "ID_BUS", &storage->bus) < 0) if (udevGetStringProperty(device, "ID_BUS", &storage->bus) < 0)
goto cleanup; goto cleanup;
@ -972,8 +965,7 @@ udevProcessStorage(struct udev_device *device,
} }
if (str) { if (str) {
if (VIR_STRDUP(storage->drive_type, str) < 0) storage->drive_type = g_strdup(str);
goto cleanup;
} else { } else {
/* If udev doesn't have it, perhaps we can guess it. */ /* If udev doesn't have it, perhaps we can guess it. */
if (udevKludgeStorageType(def) != 0) if (udevKludgeStorageType(def) != 0)
@ -1052,8 +1044,7 @@ udevProcessMediatedDevice(struct udev_device *dev,
goto cleanup; goto cleanup;
} }
if (VIR_STRDUP(data->type, last_component(canonicalpath)) < 0) data->type = g_strdup(last_component(canonicalpath));
goto cleanup;
uuidstr = udev_device_get_sysname(dev); uuidstr = udev_device_get_sysname(dev);
if ((iommugrp = virMediatedDeviceGetIOMMUGroupNum(uuidstr)) < 0) if ((iommugrp = virMediatedDeviceGetIOMMUGroupNum(uuidstr)) < 0)
@ -1111,8 +1102,7 @@ udevGetDeviceNodes(struct udev_device *device,
devnode = udev_device_get_devnode(device); devnode = udev_device_get_devnode(device);
if (VIR_STRDUP(def->devnode, devnode) < 0) def->devnode = g_strdup(devnode);
return -1;
udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device)) udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device))
n++; n++;
@ -1122,8 +1112,7 @@ udevGetDeviceNodes(struct udev_device *device,
n = 0; n = 0;
udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device)) { 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) def->devlinks[n++] = g_strdup(udev_list_entry_get_name(list_entry));
return -1;
} }
return 0; return 0;
@ -1295,14 +1284,10 @@ udevSetParent(struct udev_device *device,
if ((obj = virNodeDeviceObjListFindBySysfsPath(driver->devs, if ((obj = virNodeDeviceObjListFindBySysfsPath(driver->devs,
parent_sysfs_path))) { parent_sysfs_path))) {
objdef = virNodeDeviceObjGetDef(obj); objdef = virNodeDeviceObjGetDef(obj);
if (VIR_STRDUP(def->parent, objdef->name) < 0) { def->parent = g_strdup(objdef->name);
virNodeDeviceObjEndAPI(&obj);
goto cleanup;
}
virNodeDeviceObjEndAPI(&obj); virNodeDeviceObjEndAPI(&obj);
if (VIR_STRDUP(def->parent_sysfs_path, parent_sysfs_path) < 0) def->parent_sysfs_path = g_strdup(parent_sysfs_path);
goto cleanup;
} }
} while (def->parent == NULL && parent_device != NULL); } while (def->parent == NULL && parent_device != NULL);
@ -1330,8 +1315,7 @@ udevAddOneDevice(struct udev_device *device)
if (VIR_ALLOC(def) != 0) if (VIR_ALLOC(def) != 0)
goto cleanup; goto cleanup;
if (VIR_STRDUP(def->sysfs_path, udev_device_get_syspath(device)) < 0) def->sysfs_path = g_strdup(udev_device_get_syspath(device));
goto cleanup;
if (udevGetStringProperty(device, "DRIVER", &def->driver) < 0) if (udevGetStringProperty(device, "DRIVER", &def->driver) < 0)
goto cleanup; goto cleanup;
@ -1735,8 +1719,7 @@ udevSetupSystemDev(void)
if (VIR_ALLOC(def) < 0) if (VIR_ALLOC(def) < 0)
return -1; return -1;
if (VIR_STRDUP(def->name, "computer") < 0) def->name = g_strdup("computer");
goto cleanup;
if (VIR_ALLOC(def->caps) != 0) if (VIR_ALLOC(def->caps) != 0)
goto cleanup; goto cleanup;