[libvirt PATCH] Fix incorrect g_new0 conversions

Ján Tomko posted 1 patch 3 years, 6 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/7c58c485e5fcbc6c3ee6eb3b6b222ab83b56a869.1601982893.git.jtomko@redhat.com
src/esx/esx_storage_backend_vmfs.c         | 1 -
src/libxl/libxl_capabilities.c             | 2 --
src/libxl/libxl_driver.c                   | 1 -
src/qemu/qemu_hotplug.c                    | 1 -
src/storage/storage_backend_iscsi_direct.c | 1 -
tools/virt-login-shell-helper.c            | 1 -
6 files changed, 7 deletions(-)
[libvirt PATCH] Fix incorrect g_new0 conversions
Posted by Ján Tomko 3 years, 6 months ago
I left in a 'return' or 'goto cleanup' in a few places that
where I did the conversion manually.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reported-by: John Ferlan <jferlan@redhat.com>
---
 src/esx/esx_storage_backend_vmfs.c         | 1 -
 src/libxl/libxl_capabilities.c             | 2 --
 src/libxl/libxl_driver.c                   | 1 -
 src/qemu/qemu_hotplug.c                    | 1 -
 src/storage/storage_backend_iscsi_direct.c | 1 -
 tools/virt-login-shell-helper.c            | 1 -
 6 files changed, 7 deletions(-)

diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c
index e397853bf7..c7a7863a61 100644
--- a/src/esx/esx_storage_backend_vmfs.c
+++ b/src/esx/esx_storage_backend_vmfs.c
@@ -1195,7 +1195,6 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool,
 
         if (priv->primary->hasQueryVirtualDiskUuid) {
             key = g_new0(char, VIR_UUID_STRING_BUFLEN);
-                goto cleanup;
 
             if (esxVI_QueryVirtualDiskUuid(priv->primary, datastorePath,
                                            priv->primary->datacenter->_reference,
diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c
index 622cba1bfc..2f3ed5bc83 100644
--- a/src/libxl/libxl_capabilities.c
+++ b/src/libxl/libxl_capabilities.c
@@ -284,7 +284,6 @@ libxlCapsInitNuma(libxl_ctx *ctx, virCapsPtr caps)
 
         if (nr_cpus_node[node] == 1) {
             cpus[node] = g_new0(virCapsHostNUMACellCPU, 1);
-                goto cleanup;
         } else {
             if (VIR_REALLOC_N(cpus[node], nr_cpus_node[node]) < 0)
                 goto cleanup;
@@ -323,7 +322,6 @@ libxlCapsInitNuma(libxl_ctx *ctx, virCapsPtr caps)
             size_t j;
 
             siblings = g_new0(virCapsHostNUMACellSiblingInfo, nr_siblings);
-                goto cleanup;
 
             for (j = 0; j < nr_siblings; j++) {
                 siblings[j].node = j;
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 446449fb33..e28c649688 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -2762,7 +2762,6 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat,
     }
 
     ret = g_new0(char, len);
-        goto cleanup;
 
     if (virConfWriteMem(ret, &len, conf) < 0) {
         VIR_FREE(ret);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 1aa8b497dd..7a54fcb221 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1280,7 +1280,6 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
         tapfd = g_new0(int, tapfdSize);
         memset(tapfd, -1, sizeof(*tapfd) * tapfdSize);
         vhostfd = g_new0(int, vhostfdSize);
-            goto cleanup;
         memset(vhostfd, -1, sizeof(*vhostfd) * vhostfdSize);
         if (qemuInterfaceEthernetConnect(vm->def, driver, net,
                                          tapfd, tapfdSize) < 0)
diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/storage_backend_iscsi_direct.c
index 66ceb48e6a..12b075db0b 100644
--- a/src/storage/storage_backend_iscsi_direct.c
+++ b/src/storage/storage_backend_iscsi_direct.c
@@ -626,7 +626,6 @@ virStorageBackendISCSIDirectVolWipeZero(virStorageVolDefPtr vol,
     if (virISCSIDirectGetVolumeCapacity(iscsi, lun, &block_size, &nb_block))
         return ret;
     data = g_new0(unsigned char, block_size * BLOCK_PER_PACKET);
-        return ret;
 
     while (lba < nb_block) {
         const uint64_t to_write = MIN(nb_block - lba + 1, BLOCK_PER_PACKET);
diff --git a/tools/virt-login-shell-helper.c b/tools/virt-login-shell-helper.c
index 0e7987bf82..0522896eee 100644
--- a/tools/virt-login-shell-helper.c
+++ b/tools/virt-login-shell-helper.c
@@ -100,7 +100,6 @@ static int virLoginShellGetShellArgv(virConfPtr conf,
 
     if (rv == 0) {
         *shargv = g_new0(char *, 2);
-            return -1;
         (*shargv)[0] = g_strdup("/bin/sh");
         *shargvlen = 1;
     } else {
-- 
2.26.2

Re: [libvirt PATCH] Fix incorrect g_new0 conversions
Posted by John Ferlan 3 years, 6 months ago

On 10/6/20 7:15 AM, Ján Tomko wrote:
> I left in a 'return' or 'goto cleanup' in a few places that
> where I did the conversion manually.
> 
> Signed-off-by: Ján Tomko <jtomko@redhat.com>
> Reported-by: John Ferlan <jferlan@redhat.com>
> ---
>  src/esx/esx_storage_backend_vmfs.c         | 1 -
>  src/libxl/libxl_capabilities.c             | 2 --
>  src/libxl/libxl_driver.c                   | 1 -
>  src/qemu/qemu_hotplug.c                    | 1 -
>  src/storage/storage_backend_iscsi_direct.c | 1 -
>  tools/virt-login-shell-helper.c            | 1 -
>  6 files changed, 7 deletions(-)
> 

Thanks -

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

Re: [libvirt PATCH] Fix incorrect g_new0 conversions
Posted by Martin Kletzander 3 years, 6 months ago
On Tue, Oct 06, 2020 at 01:15:01PM +0200, Ján Tomko wrote:
>I left in a 'return' or 'goto cleanup' in a few places that
>where I did the conversion manually.
>

Did you mean s/that// maybe?

>Signed-off-by: Ján Tomko <jtomko@redhat.com>
>Reported-by: John Ferlan <jferlan@redhat.com>
>---
> src/esx/esx_storage_backend_vmfs.c         | 1 -
> src/libxl/libxl_capabilities.c             | 2 --
> src/libxl/libxl_driver.c                   | 1 -
> src/qemu/qemu_hotplug.c                    | 1 -
> src/storage/storage_backend_iscsi_direct.c | 1 -
> tools/virt-login-shell-helper.c            | 1 -
> 6 files changed, 7 deletions(-)
>
>diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c
>index e397853bf7..c7a7863a61 100644
>--- a/src/esx/esx_storage_backend_vmfs.c
>+++ b/src/esx/esx_storage_backend_vmfs.c
>@@ -1195,7 +1195,6 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool,
>
>         if (priv->primary->hasQueryVirtualDiskUuid) {
>             key = g_new0(char, VIR_UUID_STRING_BUFLEN);
>-                goto cleanup;
>
>             if (esxVI_QueryVirtualDiskUuid(priv->primary, datastorePath,
>                                            priv->primary->datacenter->_reference,
>diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c
>index 622cba1bfc..2f3ed5bc83 100644
>--- a/src/libxl/libxl_capabilities.c
>+++ b/src/libxl/libxl_capabilities.c
>@@ -284,7 +284,6 @@ libxlCapsInitNuma(libxl_ctx *ctx, virCapsPtr caps)
>
>         if (nr_cpus_node[node] == 1) {
>             cpus[node] = g_new0(virCapsHostNUMACellCPU, 1);
>-                goto cleanup;
>         } else {
>             if (VIR_REALLOC_N(cpus[node], nr_cpus_node[node]) < 0)
>                 goto cleanup;
>@@ -323,7 +322,6 @@ libxlCapsInitNuma(libxl_ctx *ctx, virCapsPtr caps)
>             size_t j;
>
>             siblings = g_new0(virCapsHostNUMACellSiblingInfo, nr_siblings);
>-                goto cleanup;
>
>             for (j = 0; j < nr_siblings; j++) {
>                 siblings[j].node = j;
>diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
>index 446449fb33..e28c649688 100644
>--- a/src/libxl/libxl_driver.c
>+++ b/src/libxl/libxl_driver.c
>@@ -2762,7 +2762,6 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat,
>     }
>
>     ret = g_new0(char, len);
>-        goto cleanup;
>
>     if (virConfWriteMem(ret, &len, conf) < 0) {
>         VIR_FREE(ret);
>diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
>index 1aa8b497dd..7a54fcb221 100644
>--- a/src/qemu/qemu_hotplug.c
>+++ b/src/qemu/qemu_hotplug.c
>@@ -1280,7 +1280,6 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
>         tapfd = g_new0(int, tapfdSize);
>         memset(tapfd, -1, sizeof(*tapfd) * tapfdSize);
>         vhostfd = g_new0(int, vhostfdSize);
>-            goto cleanup;
>         memset(vhostfd, -1, sizeof(*vhostfd) * vhostfdSize);
>         if (qemuInterfaceEthernetConnect(vm->def, driver, net,
>                                          tapfd, tapfdSize) < 0)
>diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/storage_backend_iscsi_direct.c
>index 66ceb48e6a..12b075db0b 100644
>--- a/src/storage/storage_backend_iscsi_direct.c
>+++ b/src/storage/storage_backend_iscsi_direct.c
>@@ -626,7 +626,6 @@ virStorageBackendISCSIDirectVolWipeZero(virStorageVolDefPtr vol,
>     if (virISCSIDirectGetVolumeCapacity(iscsi, lun, &block_size, &nb_block))
>         return ret;
>     data = g_new0(unsigned char, block_size * BLOCK_PER_PACKET);
>-        return ret;
>
>     while (lba < nb_block) {
>         const uint64_t to_write = MIN(nb_block - lba + 1, BLOCK_PER_PACKET);
>diff --git a/tools/virt-login-shell-helper.c b/tools/virt-login-shell-helper.c
>index 0e7987bf82..0522896eee 100644
>--- a/tools/virt-login-shell-helper.c
>+++ b/tools/virt-login-shell-helper.c
>@@ -100,7 +100,6 @@ static int virLoginShellGetShellArgv(virConfPtr conf,
>
>     if (rv == 0) {
>         *shargv = g_new0(char *, 2);
>-            return -1;
>         (*shargv)[0] = g_strdup("/bin/sh");
>         *shargvlen = 1;
>     } else {
>-- 
>2.26.2
>
Re: [libvirt PATCH] Fix incorrect g_new0 conversions
Posted by Ján Tomko 3 years, 6 months ago
On a Tuesday in 2020, Martin Kletzander wrote:
>On Tue, Oct 06, 2020 at 01:15:01PM +0200, Ján Tomko wrote:
>>I left in a 'return' or 'goto cleanup' in a few places that
>>where I did the conversion manually.
>>
>
>Did you mean s/that// maybe?
>

Thanks, I fixed it before you pointed it out.

Did you incept the thought in my head before sending the e-mail?

Jano

>>Signed-off-by: Ján Tomko <jtomko@redhat.com>
>>Reported-by: John Ferlan <jferlan@redhat.com>
>>---
>>src/esx/esx_storage_backend_vmfs.c         | 1 -
>>src/libxl/libxl_capabilities.c             | 2 --
>>src/libxl/libxl_driver.c                   | 1 -
>>src/qemu/qemu_hotplug.c                    | 1 -
>>src/storage/storage_backend_iscsi_direct.c | 1 -
>>tools/virt-login-shell-helper.c            | 1 -
>>6 files changed, 7 deletions(-)
>>
Re: [libvirt PATCH] Fix incorrect g_new0 conversions
Posted by Martin Kletzander 3 years, 6 months ago
On Tue, Oct 06, 2020 at 03:05:11PM +0200, Ján Tomko wrote:
>On a Tuesday in 2020, Martin Kletzander wrote:
>>On Tue, Oct 06, 2020 at 01:15:01PM +0200, Ján Tomko wrote:
>>>I left in a 'return' or 'goto cleanup' in a few places that
>>>where I did the conversion manually.
>>>
>>
>>Did you mean s/that// maybe?
>>
>
>Thanks, I fixed it before you pointed it out.
>
>Did you incept the thought in my head before sending the e-mail?
>

Yeah, I just upgraded my telepathy => notify-send bridge 🤦

>Jano
>
>>>Signed-off-by: Ján Tomko <jtomko@redhat.com>
>>>Reported-by: John Ferlan <jferlan@redhat.com>
>>>---
>>>src/esx/esx_storage_backend_vmfs.c         | 1 -
>>>src/libxl/libxl_capabilities.c             | 2 --
>>>src/libxl/libxl_driver.c                   | 1 -
>>>src/qemu/qemu_hotplug.c                    | 1 -
>>>src/storage/storage_backend_iscsi_direct.c | 1 -
>>>tools/virt-login-shell-helper.c            | 1 -
>>>6 files changed, 7 deletions(-)
>>>