}
p = strrchr(devpath, '/');
- if (p) {
- dev->def->driver = strdup(p+1);
- if (!dev->def->driver) {
- virReportOOMError();
- goto cleanup;
- }
- }
+ if (p && VIR_STRDUP(dev->def->driver, p + 1) < 0)
+ goto cleanup;
ret = 0;
cleanup:
virNodeDeviceObjLock(driver->devs.objs[i]);
if (cap == NULL ||
virNodeDeviceHasCap(driver->devs.objs[i], cap)) {
- if ((names[ndevs++] = strdup(driver->devs.objs[i]->def->name)) == NULL) {
+ if (VIR_STRDUP(names[ndevs++], driver->devs.objs[i]->def->name) < 0) {
virNodeDeviceObjUnlock(driver->devs.objs[i]);
- virReportOOMError();
goto failure;
}
}
}
if (obj->def->parent) {
- ret = strdup(obj->def->parent);
- if (!ret)
- virReportOOMError();
+ if (VIR_STRDUP(ret, obj->def->parent) < 0)
+ goto cleanup;
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no parent for this device"));
}
for (caps = obj->def->caps; caps && ncaps < maxnames; caps = caps->next) {
- names[ncaps] = strdup(virNodeDevCapTypeToString(caps->type));
- if (names[ncaps++] == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(names[ncaps], virNodeDevCapTypeToString(caps->type)) < 0)
goto cleanup;
- }
}
ret = ncaps;
goto out;
}
- parent_name = strdup(obj->def->parent);
/* virNodeDeviceGetParentHost will cause the device object's lock to be
* taken, so we have to dup the parent's name and drop the lock
* before calling it. We don't need the reference to the object
* any more once we have the parent's name. */
- virNodeDeviceObjUnlock(obj);
- obj = NULL;
-
- if (parent_name == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(parent_name, obj->def->parent) < 0) {
+ virNodeDeviceObjUnlock(obj);
+ obj = NULL;
goto out;
}
+ virNodeDeviceObjUnlock(obj);
+ obj = NULL;
if (virNodeDeviceGetParentHost(&driver->devs,
dev->name,
/* If this allocation is changed, the comment at the beginning
* of the function must also be changed. */
- *property_value = strdup(udev_value);
- if (*property_value == NULL) {
+ if (VIR_STRDUP(*property_value, udev_value) < 0) {
VIR_ERROR(_("Failed to allocate memory for property value for "
"property key '%s' on device with sysname '%s'"),
property_key, udev_device_get_sysname(udev_device));
- virReportOOMError();
ret = PROPERTY_ERROR;
goto out;
}
/* If this allocation is changed, the comment at the beginning
* of the function must also be changed. */
- *attr_value = strdup(udev_value);
- if (*attr_value == NULL) {
+ if (VIR_STRDUP(*attr_value, udev_value) < 0) {
VIR_ERROR(_("Failed to allocate memory for sysfs attribute value for "
"sysfs attribute '%s' on device with sysname '%s'"),
attr_name, udev_device_get_sysname(udev_device));
- virReportOOMError();
ret = PROPERTY_ERROR;
goto out;
}
NULL,
NULL);
- if (vendor_name != NULL) {
- *vendor_string = strdup(vendor_name);
- if (*vendor_string == NULL) {
- virReportOOMError();
- goto out;
- }
- }
-
- if (device_name != NULL) {
- *product_string = strdup(device_name);
- if (*product_string == NULL) {
- virReportOOMError();
- goto out;
- }
- }
+ if (VIR_STRDUP(*vendor_string, vendor_name) < 0||
+ VIR_STRDUP(*product_string, device_name) < 0)
+ goto out;
ret = 0;
sysname = udev_device_get_sysname(device);
- data->scsi_target.name = strdup(sysname);
- if (data->scsi_target.name == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(data->scsi_target.name, sysname) < 0)
goto out;
- }
if (udevGenerateDeviceName(device, def, NULL) != 0) {
goto out;
switch (type) {
case TYPE_DISK:
- *typestring = strdup("disk");
+ ignore_value(VIR_STRDUP(*typestring, "disk"));
break;
case TYPE_TAPE:
- *typestring = strdup("tape");
+ ignore_value(VIR_STRDUP(*typestring, "tape"));
break;
case TYPE_PROCESSOR:
- *typestring = strdup("processor");
+ ignore_value(VIR_STRDUP(*typestring, "processor"));
break;
case TYPE_WORM:
- *typestring = strdup("worm");
+ ignore_value(VIR_STRDUP(*typestring, "worm"));
break;
case TYPE_ROM:
- *typestring = strdup("cdrom");
+ ignore_value(VIR_STRDUP(*typestring, "cdrom"));
break;
case TYPE_SCANNER:
- *typestring = strdup("scanner");
+ ignore_value(VIR_STRDUP(*typestring, "scanner"));
break;
case TYPE_MOD:
- *typestring = strdup("mod");
+ ignore_value(VIR_STRDUP(*typestring, "mod"));
break;
case TYPE_MEDIUM_CHANGER:
- *typestring = strdup("changer");
+ ignore_value(VIR_STRDUP(*typestring, "changer"));
break;
case TYPE_ENCLOSURE:
- *typestring = strdup("enclosure");
+ ignore_value(VIR_STRDUP(*typestring, "enclosure"));
break;
case TYPE_RAID:
- *typestring = strdup("raid");
+ ignore_value(VIR_STRDUP(*typestring, "raid"));
break;
case TYPE_NO_LUN:
default:
if (*typestring == NULL) {
if (foundtype == 1) {
ret = -1;
- virReportOOMError();
} else {
VIR_DEBUG("Failed to find SCSI device type %d for %s",
type, def->sysfs_path);
* change it to cdrom to preserve compatibility with earlier
* versions of libvirt. */
VIR_FREE(def->caps->data.storage.drive_type);
- def->caps->data.storage.drive_type = strdup("cdrom");
- if (def->caps->data.storage.drive_type == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(def->caps->data.storage.drive_type, "cdrom") < 0)
goto out;
- }
if ((udevGetIntProperty(device, "ID_CDROM_MEDIA",
&tmp_int, 0) == PROPERTY_FOUND))
if (STRPREFIX(def->caps->data.storage.block, "/dev/vd")) {
/* virtio disk */
- def->caps->data.storage.drive_type = strdup("disk");
- if (def->caps->data.storage.drive_type != NULL) {
- ret = 0;
- }
+ ret = VIR_STRDUP(def->caps->data.storage.drive_type, "disk");
}
if (ret != 0) {
VIR_DEBUG("No devnode for '%s'", udev_device_get_devpath(device));
goto out;
}
- data->storage.block = strdup(devnode);
+
+ if (VIR_STRDUP(data->storage.block, devnode) < 0)
+ goto out;
if (udevGetStringProperty(device,
"ID_BUS",
&tmp_int, 0) == PROPERTY_FOUND) &&
(tmp_int == 1)) {
- data->storage.drive_type = strdup("floppy");
- if (!data->storage.drive_type)
+ if (VIR_STRDUP(data->storage.drive_type, "floppy") < 0)
goto out;
} else if ((udevGetIntProperty(device, "ID_DRIVE_FLASH_SD",
&tmp_int, 0) == PROPERTY_FOUND) &&
(tmp_int == 1)) {
- data->storage.drive_type = strdup("sd");
- if (!data->storage.drive_type)
+ if (VIR_STRDUP(data->storage.drive_type, "sd") < 0)
goto out;
} else {
dev = virNodeDeviceFindBySysfsPath(&driverState->devs,
parent_sysfs_path);
if (dev != NULL) {
- def->parent = strdup(dev->def->name);
- virNodeDeviceObjUnlock(dev);
-
- if (def->parent == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(def->parent, dev->def->name) < 0) {
+ virNodeDeviceObjUnlock(dev);
goto out;
}
+ virNodeDeviceObjUnlock(dev);
- def->parent_sysfs_path = strdup(parent_sysfs_path);
- if (def->parent_sysfs_path == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(def->parent_sysfs_path, parent_sysfs_path) < 0)
goto out;
- }
-
}
} while (def->parent == NULL && parent_device != NULL);
- if (def->parent == NULL) {
- def->parent = strdup("computer");
- }
-
- if (def->parent == NULL) {
- virReportOOMError();
+ if (!def->parent && VIR_STRDUP(def->parent, "computer") < 0)
goto out;
- }
ret = 0;
goto out;
}
- def->sysfs_path = strdup(udev_device_get_syspath(device));
+ if (VIR_STRDUP(def->sysfs_path, udev_device_get_syspath(device)) < 0)
+ goto out;
+
if (udevGetStringProperty(device,
"DRIVER",
&def->driver) == PROPERTY_ERROR) {
out:
if (ret != 0) {
VIR_DEBUG("Discarding device %d %p %s", ret, def,
- def ? def->sysfs_path : "");
+ def ? NULLSTR(def->sysfs_path) : "");
virNodeDeviceDefFree(def);
}
goto out;
}
- def->name = strdup("computer");
- if (def->name == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(def->name, "computer") < 0)
goto out;
- }
if (VIR_ALLOC(def->caps) != 0) {
virReportOOMError();