提交 c6d483cd 编写于 作者: J John Ferlan

conf,qemu: Check for NULL addrs in virDomainUSBAddressEnsure

Rather than having the caller check, if the input @addrs is NULL
(e.g. priv->usbaddrs), then just return 0. This also removes the
need for ATTRIBUTE_NONNULL which only really helped if someone
passed a NULL as a parameter not if the passed parameter is NULL.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 207cece6
...@@ -2152,6 +2152,9 @@ int ...@@ -2152,6 +2152,9 @@ int
virDomainUSBAddressEnsure(virDomainUSBAddressSetPtr addrs, virDomainUSBAddressEnsure(virDomainUSBAddressSetPtr addrs,
virDomainDeviceInfoPtr info) virDomainDeviceInfoPtr info)
{ {
if (!addrs)
return 0;
if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE || if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE ||
(info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB && (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB &&
!virDomainUSBAddressPortIsValid(info->addr.usb.port))) { !virDomainUSBAddressPortIsValid(info->addr.usb.port))) {
......
...@@ -325,7 +325,7 @@ virDomainUSBAddressAssign(virDomainUSBAddressSetPtr addrs, ...@@ -325,7 +325,7 @@ virDomainUSBAddressAssign(virDomainUSBAddressSetPtr addrs,
int int
virDomainUSBAddressEnsure(virDomainUSBAddressSetPtr addrs, virDomainUSBAddressEnsure(virDomainUSBAddressSetPtr addrs,
virDomainDeviceInfoPtr info) virDomainDeviceInfoPtr info)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(2);
int int
virDomainUSBAddressRelease(virDomainUSBAddressSetPtr addrs, virDomainUSBAddressRelease(virDomainUSBAddressSetPtr addrs,
......
...@@ -677,10 +677,8 @@ qemuDomainAttachUSBMassStorageDevice(virQEMUDriverPtr driver, ...@@ -677,10 +677,8 @@ qemuDomainAttachUSBMassStorageDevice(virQEMUDriverPtr driver,
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
if (priv->usbaddrs) {
if (virDomainUSBAddressEnsure(priv->usbaddrs, &disk->info) < 0) if (virDomainUSBAddressEnsure(priv->usbaddrs, &disk->info) < 0)
return -1; return -1;
}
if (qemuDomainAttachDiskGeneric(driver, vm, disk) < 0) { if (qemuDomainAttachDiskGeneric(driver, vm, disk) < 0) {
virDomainUSBAddressRelease(priv->usbaddrs, &disk->info); virDomainUSBAddressRelease(priv->usbaddrs, &disk->info);
...@@ -1827,8 +1825,7 @@ qemuDomainAttachChrDeviceAssignAddr(virDomainObjPtr vm, ...@@ -1827,8 +1825,7 @@ qemuDomainAttachChrDeviceAssignAddr(virDomainObjPtr vm,
return -1; return -1;
return 1; return 1;
} else if (priv->usbaddrs && } else if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL &&
chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL &&
chr->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB) { chr->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB) {
if (virDomainUSBAddressEnsure(priv->usbaddrs, &chr->info) < 0) if (virDomainUSBAddressEnsure(priv->usbaddrs, &chr->info) < 0)
return -1; return -1;
...@@ -2247,10 +2244,8 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver, ...@@ -2247,10 +2244,8 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver,
bool teardowndevice = false; bool teardowndevice = false;
int ret = -1; int ret = -1;
if (priv->usbaddrs) {
if (virDomainUSBAddressEnsure(priv->usbaddrs, hostdev->info) < 0) if (virDomainUSBAddressEnsure(priv->usbaddrs, hostdev->info) < 0)
return -1; return -1;
}
if (qemuHostdevPrepareUSBDevices(driver, vm->def->name, &hostdev, 1, 0) < 0) if (qemuHostdevPrepareUSBDevices(driver, vm->def->name, &hostdev, 1, 0) < 0)
goto cleanup; goto cleanup;
...@@ -2840,12 +2835,10 @@ qemuDomainAttachInputDevice(virQEMUDriverPtr driver, ...@@ -2840,12 +2835,10 @@ qemuDomainAttachInputDevice(virQEMUDriverPtr driver,
if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev, "input") < 0) if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev, "input") < 0)
return -1; return -1;
} else if (input->bus == VIR_DOMAIN_INPUT_BUS_USB) { } else if (input->bus == VIR_DOMAIN_INPUT_BUS_USB) {
if (priv->usbaddrs) {
if (virDomainUSBAddressEnsure(priv->usbaddrs, &input->info) < 0) if (virDomainUSBAddressEnsure(priv->usbaddrs, &input->info) < 0)
goto cleanup; goto cleanup;
releaseaddr = true; releaseaddr = true;
} }
}
if (qemuAssignDeviceInputAlias(vm->def, input, -1) < 0) if (qemuAssignDeviceInputAlias(vm->def, input, -1) < 0)
goto cleanup; goto cleanup;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册