From nobody Sat May 4 07:58:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 149812613806569.38138781133671; Thu, 22 Jun 2017 03:08:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A275EC04D2B8; Thu, 22 Jun 2017 10:08:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6FE085C7C2; Thu, 22 Jun 2017 10:08:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E94CC4E985; Thu, 22 Jun 2017 10:08:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5MA8shb004220 for ; Thu, 22 Jun 2017 06:08:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id F047D61F4C; Thu, 22 Jun 2017 10:08:54 +0000 (UTC) Received: from inaba.usersys.redhat.com (ovpn-12-121.pek2.redhat.com [10.72.12.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1D14E61F3D for ; Thu, 22 Jun 2017 10:08:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A275EC04D2B8 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A275EC04D2B8 From: Andrea Bolognani To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 18:08:46 +0800 Message-Id: <1498126126-32053-1-git-send-email-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2] qemu: Remove duplicated code in qemuBuildSerialChrDeviceStr() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 22 Jun 2017 10:08:57 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The call to qemuBuildDeviceAddressStr() happens no matter what, so we can move it to the outer possible scope inside the function. We can also move the call to virBufferAsprintf() after all the checks have been performed, where it makes more sense. Signed-off-by: Andrea Bolognani --- src/qemu/qemu_command.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index c53ab97..5118541 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -10292,14 +10292,8 @@ qemuBuildSerialChrDeviceStr(char **deviceStr, serial->info.type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRV= IO) { virBufferAsprintf(&cmd, "spapr-vty,chardev=3Dchar%s", serial->info.alias); - if (qemuBuildDeviceAddressStr(&cmd, def, &serial->info, qemuCa= ps) < 0) - goto error; } } else { - virBufferAsprintf(&cmd, "%s,chardev=3Dchar%s,id=3D%s", - virDomainChrSerialTargetTypeToString(serial->tar= getType), - serial->info.alias, serial->info.alias); - switch (serial->targetType) { case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB: if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_USB_SERIAL)) { @@ -10314,9 +10308,6 @@ qemuBuildSerialChrDeviceStr(char **deviceStr, _("usb-serial requires address of usb type"= )); goto error; } - - if (qemuBuildDeviceAddressStr(&cmd, def, &serial->info, qemuCa= ps) < 0) - goto error; break; =20 case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA: @@ -10326,9 +10317,6 @@ qemuBuildSerialChrDeviceStr(char **deviceStr, _("isa-serial requires address of isa type"= )); goto error; } - - if (qemuBuildDeviceAddressStr(&cmd, def, &serial->info, qemuCa= ps) < 0) - goto error; break; =20 case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI: @@ -10344,13 +10332,17 @@ qemuBuildSerialChrDeviceStr(char **deviceStr, _("pci-serial requires address of pci type"= )); goto error; } - - if (qemuBuildDeviceAddressStr(&cmd, def, &serial->info, qemuCa= ps) < 0) - goto error; break; } + + virBufferAsprintf(&cmd, "%s,chardev=3Dchar%s,id=3D%s", + virDomainChrSerialTargetTypeToString(serial->tar= getType), + serial->info.alias, serial->info.alias); } =20 + if (qemuBuildDeviceAddressStr(&cmd, def, &serial->info, qemuCaps) < 0) + goto error; + if (virBufferCheckError(&cmd) < 0) goto error; =20 --=20 2.7.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list