[libvirt] [PATCH] qemu: Simplify interface handling in qemuConnectDomainXMLToNative()

Michal Privoznik posted 1 patch 5 years ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/52f786537041f7d6b826be4b8658f443663930b8.1555489130.git.mprivozn@redhat.com
src/qemu/qemu_driver.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
[libvirt] [PATCH] qemu: Simplify interface handling in qemuConnectDomainXMLToNative()
Posted by Michal Privoznik 5 years ago
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 <mprivozn@redhat.com>
---
 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(virConnectPtr conn,
     for (i = 0; i < vm->def->nnets; i++) {
         virDomainNetDefPtr net = vm->def->nets[i];
         unsigned int bootIndex = net->info.bootIndex;
-        char *model = NULL;
+        VIR_AUTOFREE(char *) model = NULL;
         virMacAddr mac = net->mac;
         char *script = net->script;
 
-        if (virDomainNetGetModelString(net) &&
-            VIR_STRDUP(model, virDomainNetGetModelString(net)) < 0)
+        if (VIR_STRDUP(model, virDomainNetGetModelString(net)) < 0)
             goto cleanup;
 
         net->script = NULL;
@@ -7428,11 +7427,8 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
         net->mac = mac;
         net->script = script;
 
-        if (model && virDomainNetSetModelString(net, model) < 0) {
-            VIR_FREE(model);
+        if (virDomainNetSetModelString(net, model) < 0)
             goto cleanup;
-        }
-        VIR_FREE(model);
     }
 
     if (!(cmd = qemuProcessCreatePretendCmd(driver, vm, NULL,
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: Simplify interface handling in qemuConnectDomainXMLToNative()
Posted by Ján Tomko 5 years ago
On Wed, Apr 17, 2019 at 10:18:50AM +0200, Michal Privoznik wrote:
>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 <mprivozn@redhat.com>
>---
> src/qemu/qemu_driver.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list