Refactor the error paths for attaching char device (it's about to be more complicated). Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/qemu/qemu_hotplug.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 58156c6..7d05073 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1524,17 +1524,12 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver, goto cleanup; qemuDomainObjEnterMonitor(driver, vm); - if (qemuMonitorAttachCharDev(priv->mon, charAlias, &chr->source) < 0) { - ignore_value(qemuDomainObjExitMonitor(driver, vm)); - goto audit; - } + if (qemuMonitorAttachCharDev(priv->mon, charAlias, &chr->source) < 0) + goto failchardev; + + if (qemuMonitorAddDevice(priv->mon, devstr) < 0) + goto failadddev; - if (devstr && qemuMonitorAddDevice(priv->mon, devstr) < 0) { - /* detach associated chardev on error */ - qemuMonitorDetachCharDev(priv->mon, charAlias); - ignore_value(qemuDomainObjExitMonitor(driver, vm)); - goto audit; - } if (qemuDomainObjExitMonitor(driver, vm) < 0) goto audit; @@ -1550,6 +1545,13 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver, VIR_FREE(charAlias); VIR_FREE(devstr); return ret; + + failadddev: + /* detach associated chardev on error */ + qemuMonitorDetachCharDev(priv->mon, charAlias); + failchardev: + ignore_value(qemuDomainObjExitMonitor(driver, vm)); + goto audit; } -- 2.5.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list