From nobody Fri May 3 01:41:16 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.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1555489143; cv=none; d=zoho.com; s=zohoarc; b=Iv55Cvt8bumEnUupmXApOtguyrHzBLQ0sedDQWq3JfBqGtLk+wSc7dwZj/zzQe9BBovrh4Syx3dFjG985UpVmQht4QKtSCNBeJpnj/kFJ2ok7Ab76lLXuhtAVg8s2m4Vvz17ZpdDDPkXzpa+LRI/Qz7vHbTMJ+T/gnXx2lSF1lo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555489143; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=DJ8bz4Xf0IFyUg8EohBu+pbEDU61YcW1cQSXEhOiDV4=; b=DFoDLrwSiD2QiomVls5RzPJiRhfhsozdn/N+mWT+CivR8W9+TYnR5IeBHNup9egFeS2tfLCf4LcYRqA9brZFEBUyJ1gcp9Ts+lC2tjF32ePpT/Ppf2d8+33eCC9M478GxFg9mWfwmqpnsbLzSryyU15Ar+A/Bncsds1+eXzBIbo= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1555489143334854.1346620443056; Wed, 17 Apr 2019 01:19:03 -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 7D18C308624C; Wed, 17 Apr 2019 08:19:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6FA1660148; Wed, 17 Apr 2019 08:18:59 +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 E7FFD181AC45; Wed, 17 Apr 2019 08:18:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3H8ItFt025823 for ; Wed, 17 Apr 2019 04:18:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 815396014E; Wed, 17 Apr 2019 08:18:55 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09A0760148 for ; Wed, 17 Apr 2019 08:18:52 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 10:18:50 +0200 Message-Id: <52f786537041f7d6b826be4b8658f443663930b8.1555489130.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] qemu: Simplify interface handling in qemuConnectDomainXMLToNative() 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: , 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.49]); Wed, 17 Apr 2019 08:19:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Firstly, VIR_STRDUP() accepts NULL, so there is no need to check if the string we want to duplicate is not-NULL. Secondly, virDomainNetSetModelString() also accepts NULL. Thirdly, we have VIR_AUTOFREE(). Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 0fb90c4049..c443c881d5 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7411,12 +7411,11 @@ static char *qemuConnectDomainXMLToNative(virConnec= tPtr conn, for (i =3D 0; i < vm->def->nnets; i++) { virDomainNetDefPtr net =3D vm->def->nets[i]; unsigned int bootIndex =3D net->info.bootIndex; - char *model =3D NULL; + VIR_AUTOFREE(char *) model =3D NULL; virMacAddr mac =3D net->mac; char *script =3D net->script; =20 - if (virDomainNetGetModelString(net) && - VIR_STRDUP(model, virDomainNetGetModelString(net)) < 0) + if (VIR_STRDUP(model, virDomainNetGetModelString(net)) < 0) goto cleanup; =20 net->script =3D NULL; @@ -7428,11 +7427,8 @@ static char *qemuConnectDomainXMLToNative(virConnect= Ptr conn, net->mac =3D mac; net->script =3D script; =20 - if (model && virDomainNetSetModelString(net, model) < 0) { - VIR_FREE(model); + if (virDomainNetSetModelString(net, model) < 0) goto cleanup; - } - VIR_FREE(model); } =20 if (!(cmd =3D qemuProcessCreatePretendCmd(driver, vm, NULL, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list