Skip to contentSkip to conversation

trivial unneeded labels cleanup

PATCH Applied Daniel Henrique Barboza 23 participants 113 messages Jan 6, 2020 – Jan 24, 2020

Subsystems (2)
lore
Share & tools
lore
#1 lore raw

PATCH 1/59 spapr.c: remove 'out' label in spapr_dt_cas_updates()

In reply to Daniel Henrique Barboza

'out' can be replaced by 'return' with the appropriate return value.

---
 hw/ppc/spapr.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
hw/ppc/spapr.c +3 -6
index f11422fc41..1bfe47337c 100644
@@ -878,7 +878,7 @@ static int spapr_dt_cas_updates(SpaprMachineState *spapr, void *fdt,
         g_assert(smc->dr_lmb_enabled);
         ret = spapr_populate_drconf_memory(spapr, fdt);
         if (ret) {
-            goto out;
+            return ret;
         }
     }
 
@@ -889,11 +889,8 @@ static int spapr_dt_cas_updates(SpaprMachineState *spapr, void *fdt,
             return offset;
         }
     }
-    ret = spapr_ovec_populate_dt(fdt, offset, spapr->ov5_cas,
-                                 "ibm,architecture-vec-5");
-
-out:
-    return ret;
+    return spapr_ovec_populate_dt(fdt, offset, spapr->ov5_cas,
+                                  "ibm,architecture-vec-5");
 }
 
 static void spapr_dt_rtas(SpaprMachineState *spapr, void *fdt)
Signature · 1 line
2.24.1
#3 lore raw

PATCH 2/59 ppc440_bamboo.c: remove label from bamboo_load_device_tree()

In reply to Daniel Henrique Barboza

'out' label can be replaced by 'return -1' in all cases.

---
 hw/ppc/ppc440_bamboo.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
hw/ppc/ppc440_bamboo.c +2 -6
index 4d95c0f8a8..b782641b23 100644
@@ -71,12 +71,12 @@ static int bamboo_load_device_tree(hwaddr addr,
 
     filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
     if (!filename) {
-        goto out;
+        return -1;
     }
     fdt = load_device_tree(filename, &fdt_size);
     g_free(filename);
     if (fdt == NULL) {
-        goto out;
+        return -1;
     }
 
     /* Manipulate device tree in memory. */
@@ -117,10 +117,6 @@ static int bamboo_load_device_tree(hwaddr addr,
     rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE, fdt, fdt_size, addr);
     g_free(fdt);
     return 0;
-
-out:
-
-    return ret;
 }
 
 /* Create reset TLB entries for BookE, spanning the 32bit addr space.  */
Signature · 1 line
2.24.1
#17 lore raw

PATCH 9/59 chardev/char-pipe.c: remove 'fail' label in win_chr_pipe_init()

In reply to Daniel Henrique Barboza

The 'fail' label is simply doing a 'return -1'.

CC Marc-André Lureau <[email protected]>
CC Paolo Bonzini <[email protected]>
---
 chardev/char-pipe.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
chardev/char-pipe.c +5 -8
index 94d714ffcd..65d52beb0d 100644
@@ -54,12 +54,12 @@ static int win_chr_pipe_init(Chardev *chr, const char *filename,
     s->hsend = CreateEvent(NULL, TRUE, FALSE, NULL);
     if (!s->hsend) {
         error_setg(errp, "Failed CreateEvent");
-        goto fail;
+        return -1;
     }
     s->hrecv = CreateEvent(NULL, TRUE, FALSE, NULL);
     if (!s->hrecv) {
         error_setg(errp, "Failed CreateEvent");
-        goto fail;
+        return -1;
     }
 
     openname = g_strdup_printf("\\\\.\\pipe\\%s", filename);
@@ -72,7 +72,7 @@ static int win_chr_pipe_init(Chardev *chr, const char *filename,
     if (s->file == INVALID_HANDLE_VALUE) {
         error_setg(errp, "Failed CreateNamedPipe (%lu)", GetLastError());
         s->file = NULL;
-        goto fail;
+        return -1;
     }
 
     ZeroMemory(&ov, sizeof(ov));
@@ -80,7 +80,7 @@ static int win_chr_pipe_init(Chardev *chr, const char *filename,
     ret = ConnectNamedPipe(s->file, &ov);
     if (ret) {
         error_setg(errp, "Failed ConnectNamedPipe");
-        goto fail;
+        return -1;
     }
 
     ret = GetOverlappedResult(s->file, &ov, &size, TRUE);
@@ -90,7 +90,7 @@ static int win_chr_pipe_init(Chardev *chr, const char *filename,
             CloseHandle(ov.hEvent);
             ov.hEvent = NULL;
         }
-        goto fail;
+        return -1;
     }
 
     if (ov.hEvent) {
@@ -99,9 +99,6 @@ static int win_chr_pipe_init(Chardev *chr, const char *filename,
     }
     qemu_add_polling_cb(win_chr_pipe_poll, chr);
     return 0;
-
- fail:
-    return -1;
 }
 
 static void qemu_chr_open_pipe(Chardev *chr,
Signature · 1 line
2.24.1
#0 lore raw

cover trivial unneeded labels cleanup

Hello,

This is the type of cleanup I've contributed to Libvirt during the last year. Figured QEMU also deserves the same care.

The idea here is remove unneeded labels. By 'unneeded' I mean labels that does nothing but a 'return' call. One common case is something like this:

if ()

    goto cleanup;
[...]
 cleanup:
    return 0;

This code can be simplified to:

if ()

    return 0;

Which is cleaner and requires less brain cycles to wonder whether the 'cleanup' label does anything special, such as a heap memory cleanup.

Another common case uses a variable to set a return value, generally an error, then return:

if () {
    ret = -ENOENT;
    goto out;
}
[..]
 out:
    return ret;

Likewise, it is clearer to just 'return -ENOENT' instead of jumping to a label. There are other cases being handled in these patches, but these are the most common.

There are still a handful of unneeded labels hanging around after this series. There are cases in which the label name is part of the code semantics and I judged not worth removing. search_chunk() in block/dmg.c has an example of an unneeded 'err' label that I decided to not remove.

No functional change was made. If any of these patches changes existing behavior it is unintended and an error from my part.

Daniel Henrique Barboza (59):
spapr.c: remove 'out' label in spapr_dt_cas_updates() ppc440_bamboo.c: remove label from bamboo_load_device_tree() kvm-all.c: remove unneeded labels
paaudio.c: remove unneeded labels
ram.c: remove unneeded labels
mips-semi.c: remove 'uhi_done' label in helper_do_semihosting() unicore32/softmmu.c: remove 'do_fault' label in get_phys_addr_ucv2() chardev/char-mux.c: remove 'send_char' label chardev/char-pipe.c: remove 'fail' label in win_chr_pipe_init() chardev/char-win.c: remove 'fail' label in win_chr_serial_init() exec.c: remove 'err' label in ram_block_discard_range() virtfs-proxy-helper.c: remove 'err_out' label in setugid() block/vdi.c: remove 'fail' label in vdi_open() block/file-posix.c: remove unneeded labels block/blkreplay.c: remove unneeded 'fail' label in blkreplay_open() block/gluster.c: remove unneeded 'exit' label block/dmg.c: remove unneeded 'fail' label in dmg_read_mish_block() qcow2-refcount.c: remove unneeded 'fail' label in
qcow2_refcount_init()
block/ssh.c: remove unneeded labels
block/vpc.c: remove unneeded 'fail' label in create_dynamic_disk() block/backup.c remove unneeded 'out' label in backup_run() block/vmdk.c: remove unneeded labels
block/vxhs.c: remove unneeded 'out' label in vxhs_iio_callback() block/vhdx-log.c: remove unneeded labels
block/vhdx.c: remove unneeded 'exit' labels block/replication.c: remove unneeded label in replication_co_writev crypto/block-luks.c: remove unneeded label in
qcrypto_block_luks_find_key
qga/commands-win32.c: remove 'out' label in get_pci_info cryptodev-vhost.c: remove unneeded 'err' label in
cryptodev_vhost_start
util/module.c: remove unneeded label in module_load_file() util/aio-posix.c: remove unneeded 'out' label in aio_epoll qemu-img.c: remove 'out4' label in img_compare ipmi/ipmi_bmc_sim.c: remove unneeded labels ipmi/ipmi_bt.c: remove unneeded label in ipmi_bt_handle_event ipmi_bmc_extern.c: remove unneeded label in
ipmi_bmc_extern_handle_command
ipmi/ipmi_kcs.c: remove unneeded label in ipmi_kcs_handle_event s390x/event-facility.c: remove unneeded labels s390x/sclp.c: remove unneeded label in sclp_service_call() usb/dev-mtp.c: remove unneeded label in write_retry() hsb/hcd-ehci.c: remove unneeded labels intc/s390_flic_kvm.c: remove unneeded label in kvm_flic_load() i386/intel_iommu.c: remove unneeded labels i386/amd_iommu.c: remove unneeded label in amdvi_int_remap_msi() 9p-local.c: remove unneeded label in local_unlinkat_common() 9pfs/9p.c: remove unneeded labels
alpha/typhoon.c: remove unneeded label in typhoon_translate_iommu() pvrdma_main.c: remove unneeded labels
pvrdma_dev_ring.c: remove unneeded label in pvrdma_ring_init() rdma/rdma_rm.c: remove unneeded label in rdma_rm_alloc_pd() rdma/rdma_backend.c: remove unneeded label in rdma_backend_init() virtio/vhost.c: remove unneeded labels
net/vhost_net.c: remove unneeded labels
net/net_tx_pkt.c: remove unneeded label in net_tx_pkt_get_gso_type() ivshmem-server/main.c: remove unneeded label in main() linux-user/flatload.c: remove unused 'out' label linux-user/signal.c: remove unneeded label in do_sigaltstack() linux-user/syscall.c: fix trailing whitespaces and style linux-user/syscall.c: remove unneeded labels linux-user/vm86.c: remove unneeded label in do_vm86()

 accel/kvm/kvm-all.c           | 30 +++++-------
 audio/paaudio.c               | 10 +---
 backends/cryptodev-vhost.c    |  4 +-
 block/backup.c                |  6 +--
 block/blkreplay.c             |  8 +---
 block/dmg.c                   | 10 +---
 block/file-posix.c            | 10 ++--
 block/gluster.c               |  3 +-
 block/qcow2-refcount.c        |  7 +--
 block/replication.c           |  9 ++--
 block/ssh.c                   | 61 ++++++++-----------------
 block/vdi.c                   | 40 ++++++----------
 block/vhdx-log.c              | 86 +++++++++++++----------------------
 block/vhdx.c                  | 10 ++--
 block/vmdk.c                  | 37 ++++++---------
 block/vpc.c                   | 12 ++---
 block/vxhs.c                  |  4 +-
 chardev/char-mux.c            |  3 +-
 chardev/char-pipe.c           | 13 ++----
 chardev/char-win.c            | 19 ++++----
 contrib/ivshmem-server/main.c |  9 ++--
 crypto/block-luks.c           |  3 +-
 exec.c                        | 13 +++---
 fsdev/virtfs-proxy-helper.c   |  4 +-
 hw/9pfs/9p-local.c            | 12 ++---
 hw/9pfs/9p.c                  |  9 ++--
 hw/alpha/typhoon.c            | 18 ++++----
 hw/i386/amd_iommu.c           | 13 ++----
 hw/i386/intel_iommu.c         |  8 ++--
 hw/intc/s390_flic_kvm.c       | 10 ++--
 hw/ipmi/ipmi_bmc_extern.c     |  5 +-
 hw/ipmi/ipmi_bmc_sim.c        |  9 +---
 hw/ipmi/ipmi_bt.c             |  8 ++--
 hw/ipmi/ipmi_kcs.c            |  4 +-
 hw/net/net_tx_pkt.c           | 11 ++---
 hw/net/vhost_net.c            |  7 ++-
 hw/ppc/ppc440_bamboo.c        |  8 +---
 hw/ppc/spapr.c                |  9 ++--
 hw/rdma/rdma_backend.c        |  4 +-
 hw/rdma/rdma_rm.c             | 11 ++---
 hw/rdma/vmw/pvrdma_dev_ring.c |  7 +--
 hw/rdma/vmw/pvrdma_main.c     | 10 ++--
 hw/s390x/event-facility.c     | 21 +++------
 hw/s390x/sclp.c               | 16 ++-----
 hw/usb/dev-mtp.c              | 13 ++----
 hw/usb/hcd-ehci.c             | 32 ++++---------
 hw/virtio/vhost.c             | 11 ++---
 linux-user/flatload.c         |  1 -
 linux-user/signal.c           | 20 +++-----
 linux-user/syscall.c          | 54 ++++++++++------------
 linux-user/vm86.c             |  7 +--
 migration/ram.c               | 18 ++------
 qemu-img.c                    |  7 +--
 qga/commands-win32.c          | 17 ++++---
 target/mips/mips-semi.c       | 15 +++---
 target/unicore32/softmmu.c    | 23 +++-------
 util/aio-posix.c              |  3 +-
 util/module.c                 | 11 ++---
 58 files changed, 293 insertions(+), 550 deletions(-)
Signature · 1 line
2.24.1
#5 lore raw

PATCH 3/59 kvm-all.c: remove unneeded labels

Labels 'err' and 'out' from kvm_destroy_vcpu(), kvm_init_vcpu() and kvm_physical_sync_dirty_bitmap() can be replaced by 'return' with the appropriate return value.

---
 accel/kvm/kvm-all.c | 30 +++++++++++-------------------
 1 file changed, 11 insertions(+), 19 deletions(-)
accel/kvm/kvm-all.c +11 -19
index b2f1a5bcb5..09ca99e082 100644
@@ -329,26 +329,24 @@ int kvm_destroy_vcpu(CPUState *cpu)
 
     ret = kvm_arch_destroy_vcpu(cpu);
     if (ret < 0) {
-        goto err;
+        return ret;
     }
 
     mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
     if (mmap_size < 0) {
-        ret = mmap_size;
         DPRINTF("KVM_GET_VCPU_MMAP_SIZE failed\n");
-        goto err;
+        return mmap_size;
     }
 
     ret = munmap(cpu->kvm_run, mmap_size);
     if (ret < 0) {
-        goto err;
+        return ret;
     }
 
     vcpu = g_malloc0(sizeof(*vcpu));
     vcpu->vcpu_id = kvm_arch_vcpu_id(cpu);
     vcpu->kvm_fd = cpu->kvm_fd;
     QLIST_INSERT_HEAD(&kvm_state->kvm_parked_vcpus, vcpu, node);
-err:
     return ret;
 }
 
@@ -381,7 +379,7 @@ int kvm_init_vcpu(CPUState *cpu)
     ret = kvm_get_vcpu(s, kvm_arch_vcpu_id(cpu));
     if (ret < 0) {
         DPRINTF("kvm_create_vcpu failed\n");
-        goto err;
+        return ret;
     }
 
     cpu->kvm_fd = ret;
@@ -390,17 +388,15 @@ int kvm_init_vcpu(CPUState *cpu)
 
     mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
     if (mmap_size < 0) {
-        ret = mmap_size;
         DPRINTF("KVM_GET_VCPU_MMAP_SIZE failed\n");
-        goto err;
+        return mmap_size;
     }
 
     cpu->kvm_run = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED,
                         cpu->kvm_fd, 0);
     if (cpu->kvm_run == MAP_FAILED) {
-        ret = -errno;
         DPRINTF("mmap'ing vcpu state failed\n");
-        goto err;
+        return -errno;
     }
 
     if (s->coalesced_mmio && !s->coalesced_mmio_ring) {
@@ -408,9 +404,7 @@ int kvm_init_vcpu(CPUState *cpu)
             (void *)cpu->kvm_run + s->coalesced_mmio * PAGE_SIZE;
     }
 
-    ret = kvm_arch_init_vcpu(cpu);
-err:
-    return ret;
+    return kvm_arch_init_vcpu(cpu);
 }
 
 /*
@@ -565,7 +559,6 @@ static int kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml,
     KVMSlot *mem;
     hwaddr start_addr, size;
     hwaddr slot_size, slot_offset = 0;
-    int ret = 0;
 
     size = kvm_align_section(section, &start_addr);
     while (size) {
@@ -575,7 +568,7 @@ static int kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml,
         mem = kvm_lookup_matching_slot(kml, start_addr, slot_size);
         if (!mem) {
             /* We don't have a slot if we want to trap every access. */
-            goto out;
+            return 0;
         }
 
         if (!mem->dirty_bmap) {
@@ -587,8 +580,7 @@ static int kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml,
         d.slot = mem->slot | (kml->as_id << 16);
         if (kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d) == -1) {
             DPRINTF("ioctl failed %d\n", errno);
-            ret = -1;
-            goto out;
+            return -1;
         }
 
         subsection.offset_within_region += slot_offset;
@@ -599,8 +591,8 @@ static int kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml,
         start_addr += slot_size;
         size -= slot_size;
     }
-out:
-    return ret;
+
+    return 0;
 }
 
 /* Alignment requirement for KVM_CLEAR_DIRTY_LOG - 64 pages */
Signature · 1 line
2.24.1
#6 lore raw

PATCH 4/59 paaudio.c: remove unneeded labels

In reply to Daniel Henrique Barboza

Label 'fail1' in qpa_init_out() and qpa_init_in() can be replaced by 'return -1'.

---
 audio/paaudio.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
audio/paaudio.c +2 -8
index 55a91f8980..8f42b2079c 100644
@@ -470,7 +470,7 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as,
         );
     if (!pa->stream) {
         qpa_logerr (error, "pa_simple_new for playback failed\n");
-        goto fail1;
+        return -1;
     }
 
     audio_pcm_init_info (&hw->info, &obt_as);
@@ -479,9 +479,6 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as,
         &obt_as, ppdo->buffer_length);
 
     return 0;
-
- fail1:
-    return -1;
 }
 
 static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
@@ -518,7 +515,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
         );
     if (!pa->stream) {
         qpa_logerr (error, "pa_simple_new for capture failed\n");
-        goto fail1;
+        return -1;
     }
 
     audio_pcm_init_info (&hw->info, &obt_as);
@@ -527,9 +524,6 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
         &obt_as, ppdo->buffer_length);
 
     return 0;
-
- fail1:
-    return -1;
 }
 
 static void qpa_simple_disconnect(PAConnection *c, pa_stream *stream)
Signature · 1 line
2.24.1
#31 lore raw

PATCH 14/59 block/file-posix.c: remove unneeded labels

In reply to Daniel Henrique Barboza

'out' label from cdrom_probe_device() can be removed, and its only instance replaced by 'return prio'.

In raw_co_create(), 'out' can be replaced by 'return -errno' in the error condition it is being called.

---
 block/file-posix.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
block/file-posix.c +4 -6
index 1b805bd938..b1a6549806 100644
@@ -2265,9 +2265,8 @@ raw_co_create(BlockdevCreateOptions *options, Error **errp)
     /* Create file */
     fd = qemu_open(file_opts->filename, O_RDWR | O_CREAT | O_BINARY, 0644);
     if (fd < 0) {
-        result = -errno;
-        error_setg_errno(errp, -result, "Could not create file");
-        goto out;
+        error_setg_errno(errp, errno, "Could not create file");
+        return -errno;
     }
 
     /* Take permissions: We want to discard everything, so we need
@@ -2342,7 +2341,7 @@ out_close:
         result = -errno;
         error_setg_errno(errp, -result, "Could not close the new file");
     }
-out:
+
     return result;
 }
 
@@ -3554,7 +3553,7 @@ static int cdrom_probe_device(const char *filename)
 
     fd = qemu_open(filename, O_RDONLY | O_NONBLOCK);
     if (fd < 0) {
-        goto out;
+        return prio;
     }
     ret = fstat(fd, &st);
     if (ret == -1 || !S_ISBLK(st.st_mode)) {
@@ -3568,7 +3567,6 @@ static int cdrom_probe_device(const char *filename)
 
 outc:
     qemu_close(fd);
-out:
     return prio;
 }
 
Signature · 1 line
2.24.1
#11 lore raw

PATCH 6/59 mips-semi.c: remove 'uhi_done' label in helper_do_semihosting()

In reply to Daniel Henrique Barboza

The label 'uhi_done' is a simple 'return' call and can be removed for a bit more clarity in the code.

CC Aurelien Jarno <[email protected]>
CC Aleksandar Markovic <[email protected]>
CC Aleksandar Rikalo <[email protected]>
---
 target/mips/mips-semi.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
target/mips/mips-semi.c +7 -8
index 35bdfd7c77..10a710c1e8 100644
@@ -218,7 +218,7 @@ static int copy_argn_to_target(CPUMIPSState *env, int arg_num,
         if (!p) {                               \
             gpr[2] = -1;                        \
             gpr[3] = EFAULT;                    \
-            goto uhi_done;                      \
+            return;                             \
         }                                       \
     } while (0)
 
@@ -228,14 +228,14 @@ static int copy_argn_to_target(CPUMIPSState *env, int arg_num,
         if (!p) {                                       \
             gpr[2] = -1;                                \
             gpr[3] = EFAULT;                            \
-            goto uhi_done;                              \
+            return;                                     \
         }                                               \
         p2 = lock_user_string(addr2);                   \
         if (!p2) {                                      \
             unlock_user(p, addr, 0);                    \
             gpr[2] = -1;                                \
             gpr[3] = EFAULT;                            \
-            goto uhi_done;                              \
+            return;                                     \
         }                                               \
     } while (0)
 
@@ -272,7 +272,7 @@ void helper_do_semihosting(CPUMIPSState *env)
         if (gpr[4] < 3) {
             /* ignore closing stdin/stdout/stderr */
             gpr[2] = 0;
-            goto uhi_done;
+            return;
         }
         gpr[2] = close(gpr[4]);
         gpr[3] = errno_mips(errno);
@@ -302,7 +302,7 @@ void helper_do_semihosting(CPUMIPSState *env)
             gpr[2] = fstat(gpr[4], &sbuf);
             gpr[3] = errno_mips(errno);
             if (gpr[2]) {
-                goto uhi_done;
+                return;
             }
             gpr[2] = copy_stat_to_target(env, &sbuf, gpr[5]);
             gpr[3] = errno_mips(errno);
@@ -314,14 +314,14 @@ void helper_do_semihosting(CPUMIPSState *env)
     case UHI_argnlen:
         if (gpr[4] >= semihosting_get_argc()) {
             gpr[2] = -1;
-            goto uhi_done;
+            return;
         }
         gpr[2] = strlen(semihosting_get_arg(gpr[4]));
         break;
     case UHI_argn:
         if (gpr[4] >= semihosting_get_argc()) {
             gpr[2] = -1;
-            goto uhi_done;
+            return;
         }
         gpr[2] = copy_argn_to_target(env, gpr[4], gpr[5]);
         break;
@@ -369,6 +369,5 @@ void helper_do_semihosting(CPUMIPSState *env)
         fprintf(stderr, "Unknown UHI operation %d\n", op);
         abort();
     }
-uhi_done:
     return;
 }
Signature · 1 line
2.24.1
#14 lore raw

PATCH 7/59 unicore32/softmmu.c: remove 'do_fault' label in get_phys_addr_ucv2()

In reply to Daniel Henrique Barboza

'do_fault' is a label that executes 'return code'. The 'code' variable is an integer that is set to zero, then in all instances it is set to another value right before 'do_fault'.

We can get rid of both the label and the variable to make the code a bit cleaner.

---
 target/unicore32/softmmu.c | 23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)
target/unicore32/softmmu.c +7 -16
index cbdaa500b7..3373400cba 100644
@@ -125,7 +125,6 @@ static int get_phys_addr_ucv2(CPUUniCore32State *env, uint32_t address,
         target_ulong *page_size)
 {
     CPUState *cs = env_cpu(env);
-    int code;
     uint32_t table;
     uint32_t desc;
     uint32_t phys_addr;
@@ -135,13 +134,11 @@ static int get_phys_addr_ucv2(CPUUniCore32State *env, uint32_t address,
     table = env->cp0.c2_base & 0xfffff000;
     table |= (address >> 20) & 0xffc;
     desc = ldl_phys(cs->as, table);
-    code = 0;
     switch (PAGETABLE_TYPE(desc)) {
     case 3:
         /* Superpage  */
         if (!(desc & UC32_PAGETABLE_EXIST)) {
-            code = 0x0b; /* superpage miss */
-            goto do_fault;
+            return 0x0b; /* superpage miss */
         }
         phys_addr = (desc & 0xffc00000) | (address & 0x003fffff);
         *page_size = SUPERPAGE_SIZE;
@@ -152,8 +149,7 @@ static int get_phys_addr_ucv2(CPUUniCore32State *env, uint32_t address,
             DPRINTF("PGD address %x, desc %x\n", table, desc);
         }
         if (!(desc & UC32_PAGETABLE_EXIST)) {
-            code = 0x05; /* second pagetable miss */
-            goto do_fault;
+            return 0x05; /* second pagetable miss */
         }
         table = (desc & 0xfffff000) | ((address >> 10) & 0xffc);
         desc = ldl_phys(cs->as, table);
@@ -162,8 +158,7 @@ static int get_phys_addr_ucv2(CPUUniCore32State *env, uint32_t address,
             DPRINTF("PTE address %x, desc %x\n", table, desc);
         }
         if (!(desc & UC32_PAGETABLE_EXIST)) {
-            code = 0x08; /* page miss */
-            goto do_fault;
+            return 0x08; /* page miss */
         }
         switch (PAGETABLE_TYPE(desc)) {
         case 0:
@@ -185,8 +180,7 @@ static int get_phys_addr_ucv2(CPUUniCore32State *env, uint32_t address,
         *prot |= PAGE_READ;
     } else {
         if (is_user && (access_type == 0)) {
-            code = 0x11; /* access unreadable area */
-            goto do_fault;
+            return 0x11; /* access unreadable area */
         }
     }
 
@@ -194,8 +188,7 @@ static int get_phys_addr_ucv2(CPUUniCore32State *env, uint32_t address,
         *prot |= PAGE_WRITE;
     } else {
         if (is_user && (access_type == 1)) {
-            code = 0x12; /* access unwritable area */
-            goto do_fault;
+            return 0x12; /* access unwritable area */
         }
     }
 
@@ -203,13 +196,11 @@ static int get_phys_addr_ucv2(CPUUniCore32State *env, uint32_t address,
         *prot |= PAGE_EXEC;
     } else {
         if (is_user && (access_type == 2)) {
-            code = 0x13; /* access unexecutable area */
-            goto do_fault;
+            return 0x13; /* access unexecutable area */
         }
     }
 
-do_fault:
-    return code;
+    return 0;
 }
 
 bool uc32_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
Signature · 1 line
2.24.1
#7 lore raw

PATCH 5/59 ram.c: remove unneeded labels

In reply to Daniel Henrique Barboza

ram_save_queue_pages() has an 'err' label that can be replaced by 'return -1' instead.

Same thing with ram_discard_range(), and in this case we can also get rid of the 'ret' variable and return either '-1' on error or the result of ram_block_discard_range().

CC Juan Quintela <[email protected]>
CC Dr. David Alan Gilbert <[email protected]>
---
 migration/ram.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
migration/ram.c +5 -13
index 96feb4062c..980cc644d7 100644
@@ -2434,7 +2434,7 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len)
              * it's the 1st request.
              */
             error_report("ram_save_queue_pages no previous block");
-            goto err;
+            return -1;
         }
     } else {
         ramblock = qemu_ram_block_by_name(rbname);
@@ -2442,7 +2442,7 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len)
         if (!ramblock) {
             /* We shouldn't be asked for a non-existent RAMBlock */
             error_report("ram_save_queue_pages no block '%s'", rbname);
-            goto err;
+            return -1;
         }
         rs->last_req_rb = ramblock;
     }
@@ -2451,7 +2451,7 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len)
         error_report("%s request overrun start=" RAM_ADDR_FMT " len="
                      RAM_ADDR_FMT " blocklen=" RAM_ADDR_FMT,
                      __func__, start, len, ramblock->used_length);
-        goto err;
+        return -1;
     }
 
     struct RAMSrcPageRequest *new_entry =
@@ -2467,9 +2467,6 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len)
     qemu_mutex_unlock(&rs->src_page_req_mutex);
 
     return 0;
-
-err:
-    return -1;
 }
 
 static bool save_page_use_compression(RAMState *rs)
@@ -3072,8 +3069,6 @@ int ram_postcopy_send_discard_bitmap(MigrationState *ms)
  */
 int ram_discard_range(const char *rbname, uint64_t start, size_t length)
 {
-    int ret = -1;
-
     trace_ram_discard_range(rbname, start, length);
 
     RCU_READ_LOCK_GUARD();
@@ -3081,7 +3076,7 @@ int ram_discard_range(const char *rbname, uint64_t start, size_t length)
 
     if (!rb) {
         error_report("ram_discard_range: Failed to find block '%s'", rbname);
-        goto err;
+        return -1;
     }
 
     /*
@@ -3093,10 +3088,7 @@ int ram_discard_range(const char *rbname, uint64_t start, size_t length)
                      length >> qemu_target_page_bits());
     }
 
-    ret = ram_block_discard_range(rb, start, length);
-
-err:
-    return ret;
+    return ram_block_discard_range(rb, start, length);
 }
 
 /*
Signature · 1 line
2.24.1
#40 lore raw

PATCH 20/59 block/vpc.c: remove unneeded 'fail' label in create_dynamic_disk()

In reply to Daniel Henrique Barboza

'fail' label can be replaced by 'return ret' on error and 'return 0' in the end of the function.

---
 block/vpc.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
block/vpc.c +5 -7
index a65550298e..2678b48dfd 100644
@@ -839,13 +839,13 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf,
 
     ret = blk_pwrite(blk, offset, buf, HEADER_SIZE, 0);
     if (ret < 0) {
-        goto fail;
+        return ret;
     }
 
     offset = 1536 + ((num_bat_entries * 4 + 511) & ~511);
     ret = blk_pwrite(blk, offset, buf, HEADER_SIZE, 0);
     if (ret < 0) {
-        goto fail;
+        return ret;
     }
 
     /* Write the initial BAT */
@@ -855,7 +855,7 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf,
     for (i = 0; i < DIV_ROUND_UP(num_bat_entries * 4, 512); i++) {
         ret = blk_pwrite(blk, offset, buf, 512, 0);
         if (ret < 0) {
-            goto fail;
+            return ret;
         }
         offset += 512;
     }
@@ -882,12 +882,10 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf,
 
     ret = blk_pwrite(blk, offset, buf, 1024, 0);
     if (ret < 0) {
-        goto fail;
+        return ret;
     }
 
-    ret = 0;
- fail:
-    return ret;
+    return 0;
 }
 
 static int create_fixed_disk(BlockBackend *blk, uint8_t *buf,
Signature · 1 line
2.24.1
#22 lore raw

PATCH 11/59 exec.c: remove 'err' label in ram_block_discard_range()

In reply to Daniel Henrique Barboza

'err' is a label that just executes 'return ret'. We can remove the label and simply 'return ret' on error.

---
 exec.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
exec.c +6 -7
index d4b769d0d4..7cfd80826e 100644
@@ -3898,7 +3898,7 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
     if ((uintptr_t)host_startaddr & (rb->page_size - 1)) {
         error_report("ram_block_discard_range: Unaligned start address: %p",
                      host_startaddr);
-        goto err;
+        return ret;
     }
 
     if ((start + length) <= rb->used_length) {
@@ -3906,7 +3906,7 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
         if (length & (rb->page_size - 1)) {
             error_report("ram_block_discard_range: Unaligned length: %zx",
                          length);
-            goto err;
+            return ret;
         }
 
         errno = ENOTSUP; /* If we are missing MADVISE etc */
@@ -3930,14 +3930,14 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
                 error_report("ram_block_discard_range: Failed to fallocate "
                              "%s:%" PRIx64 " +%zx (%d)",
                              rb->idstr, start, length, ret);
-                goto err;
+                return ret;
             }
 #else
             ret = -ENOSYS;
             error_report("ram_block_discard_range: fallocate not available/file"
                          "%s:%" PRIx64 " +%zx (%d)",
                          rb->idstr, start, length, ret);
-            goto err;
+            return ret;
 #endif
         }
         if (need_madvise) {
@@ -3953,14 +3953,14 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
                 error_report("ram_block_discard_range: Failed to discard range "
                              "%s:%" PRIx64 " +%zx (%d)",
                              rb->idstr, start, length, ret);
-                goto err;
+                return ret;
             }
 #else
             ret = -ENOSYS;
             error_report("ram_block_discard_range: MADVISE not available"
                          "%s:%" PRIx64 " +%zx (%d)",
                          rb->idstr, start, length, ret);
-            goto err;
+            return ret;
 #endif
         }
         trace_ram_block_discard_range(rb->idstr, host_startaddr, length,
@@ -3971,7 +3971,6 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
                      rb->idstr, start, length, rb->used_length);
     }
 
-err:
     return ret;
 }
 
Signature · 1 line
2.24.1
#15 lore raw

PATCH 8/59 chardev/char-mux.c: remove 'send_char' label

In reply to Daniel Henrique Barboza
CC Marc-André Lureau <[email protected]>
CC Paolo Bonzini <[email protected]>
---
 chardev/char-mux.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
chardev/char-mux.c +1 -2
index 200c62a0d0..edbaaf5cbf 100644
@@ -140,7 +140,7 @@ static int mux_proc_byte(Chardev *chr, MuxChardev *d, int ch)
     if (d->term_got_escape) {
         d->term_got_escape = 0;
         if (ch == term_escape_char) {
-            goto send_char;
+            return 1;
         }
         switch (ch) {
         case '?':
@@ -174,7 +174,6 @@ static int mux_proc_byte(Chardev *chr, MuxChardev *d, int ch)
     } else if (ch == term_escape_char) {
         d->term_got_escape = 1;
     } else {
-    send_char:
         return 1;
     }
     return 0;
Signature · 1 line
2.24.1
#23 lore raw

PATCH 12/59 virtfs-proxy-helper.c: remove 'err_out' label in setugid()

In reply to Daniel Henrique Barboza

'err_out' can be removed and be replaced by 'return -errno' in its only instance in the function.

---
 fsdev/virtfs-proxy-helper.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
fsdev/virtfs-proxy-helper.c +1 -3
index 0d4de49dcf..aa1ab2590d 100644
@@ -287,8 +287,7 @@ static int setugid(int uid, int gid, int *suid, int *sgid)
     *sgid = getegid();
 
     if (setresgid(-1, gid, *sgid) == -1) {
-        retval = -errno;
-        goto err_out;
+        return -errno;
     }
 
     if (setresuid(-1, uid, *suid) == -1) {
@@ -322,7 +321,6 @@ err_sgid:
     if (setresgid(-1, *sgid, *sgid) == -1) {
         abort();
     }
-err_out:
     return retval;
 }
 
Signature · 1 line
2.24.1
Reviewed-by on v1 19/59
#39 lore raw

Re: [PATCH v1 19/59] block/ssh.c: remove unneeded labels

In reply to Daniel Henrique Barboza
Quoted 156 lines · Daniel Henrique Barboza

The 'out' labels for check_host_key_knownhosts() and authenticate() functions can be removed and, instead, call 'return' with the appropriate return value. The 'ret' integer from both functions could also be removed.

---
 block/ssh.c | 61 +++++++++++++++++------------------------------------
 1 file changed, 19 insertions(+), 42 deletions(-)
block/ssh.c +18 -38
index b4375cf7d2..e0c56d002a 100644
@@ -276,7 +276,6 @@ static void ssh_parse_filename(const char *filename, QDict *options,
 
 static int check_host_key_knownhosts(BDRVSSHState *s, Error **errp)
 {
-    int ret;
 #ifdef HAVE_LIBSSH_0_8
     enum ssh_known_hosts_e state;
     int r;
@@ -295,7 +294,6 @@ static int check_host_key_knownhosts(BDRVSSHState *s, Error **errp)
         trace_ssh_check_host_key_knownhosts();
         break;
     case SSH_KNOWN_HOSTS_CHANGED:
-        ret = -EINVAL;
         r = ssh_get_server_publickey(s->session, &pubkey);
         if (r == 0) {
             r = ssh_get_publickey_hash(pubkey, SSH_PUBLICKEY_HASH_SHA256,
@@ -320,28 +318,23 @@ static int check_host_key_knownhosts(BDRVSSHState *s, Error **errp)
                        "host key does not match the one in known_hosts; this "
                        "may be a possible attack");
         }
-        goto out;
+        return -EINVAL;
     case SSH_KNOWN_HOSTS_OTHER:
-        ret = -EINVAL;
         error_setg(errp,
                    "host key for this server not found, another type exists");
-        goto out;
+        return -EINVAL;
     case SSH_KNOWN_HOSTS_UNKNOWN:
-        ret = -EINVAL;
         error_setg(errp, "no host key was found in known_hosts");
-        goto out;
+        return -EINVAL;
     case SSH_KNOWN_HOSTS_NOT_FOUND:
-        ret = -ENOENT;
         error_setg(errp, "known_hosts file not found");
-        goto out;
+        return -ENOENT;
     case SSH_KNOWN_HOSTS_ERROR:
-        ret = -EINVAL;
         error_setg(errp, "error while checking the host");
-        goto out;
+        return -EINVAL;
     default:
-        ret = -EINVAL;
         error_setg(errp, "error while checking for known server (%d)", state);
-        goto out;
+        return -EINVAL;
     }
 #else /* !HAVE_LIBSSH_0_8 */
     int state;
@@ -355,40 +348,31 @@ static int check_host_key_knownhosts(BDRVSSHState *s, Error **errp)
         trace_ssh_check_host_key_knownhosts();
         break;
     case SSH_SERVER_KNOWN_CHANGED:
-        ret = -EINVAL;
         error_setg(errp,
                    "host key does not match the one in known_hosts; this "
                    "may be a possible attack");
-        goto out;
+        return -EINVAL;
     case SSH_SERVER_FOUND_OTHER:
-        ret = -EINVAL;
         error_setg(errp,
                    "host key for this server not found, another type exists");
-        goto out;
+        return -EINVAL;
     case SSH_SERVER_FILE_NOT_FOUND:
-        ret = -ENOENT;
         error_setg(errp, "known_hosts file not found");
-        goto out;
+        return -ENOENT;
     case SSH_SERVER_NOT_KNOWN:
-        ret = -EINVAL;
         error_setg(errp, "no host key was found in known_hosts");
-        goto out;
+        return -EINVAL;
     case SSH_SERVER_ERROR:
-        ret = -EINVAL;
         error_setg(errp, "server error");
-        goto out;
+        return -EINVAL;
     default:
-        ret = -EINVAL;
         error_setg(errp, "error while checking for known server (%d)", state);
-        goto out;
+        return -EINVAL;
     }
 #endif /* !HAVE_LIBSSH_0_8 */
 
     /* known_hosts checking successful. */
-    ret = 0;
-
- out:
-    return ret;
+    return 0;
 }
 
 static unsigned hex2decimal(char ch)
@@ -501,20 +485,18 @@ static int check_host_key(BDRVSSHState *s, SshHostKeyCheck *hkc, Error **errp)
 
 static int authenticate(BDRVSSHState *s, Error **errp)
 {
-    int r, ret;
+    int r;
     int method;
 
     /* Try to authenticate with the "none" method. */
     r = ssh_userauth_none(s->session, NULL);
     if (r == SSH_AUTH_ERROR) {
-        ret = -EPERM;
         session_error_setg(errp, s, "failed to authenticate using none "
                                     "authentication");
-        goto out;
+        return -EPERM;
     } else if (r == SSH_AUTH_SUCCESS) {
         /* Authenticated! */
-        ret = 0;
-        goto out;
+        return 0;
     }
 
     method = ssh_userauth_list(s->session, NULL);
@@ -527,23 +509,18 @@ static int authenticate(BDRVSSHState *s, Error **errp)
     if (method & SSH_AUTH_METHOD_PUBLICKEY) {
         r = ssh_userauth_publickey_auto(s->session, NULL, NULL);
         if (r == SSH_AUTH_ERROR) {
-            ret = -EINVAL;
             session_error_setg(errp, s, "failed to authenticate using "
                                         "publickey authentication");
-            goto out;
+            return -EINVAL;
         } else if (r == SSH_AUTH_SUCCESS) {
             /* Authenticated! */
-            ret = 0;
-            goto out;
+            return 0;
         }
     }
 

block/ssh.c static int authenticate(BDRVSSHState *s, Error **errp) · line 526

Quoted 10 lines
block/ssh.c +1 -4
-    ret = -EPERM;
     error_setg(errp, "failed to authenticate using publickey authentication "
                "and the identities held by your ssh-agent");
-
- out:
-    return ret;
+    return -EPERM;
 }
 
 static QemuOptsList ssh_runtime_opts = {

I agree that the code is functionality the same after this change. Don't know whether or not one style or the other is preferred by qemu, but in any case:

Rich.

Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top
#43 lore raw

PATCH 23/59 block/vxhs.c: remove unneeded 'out' label in vxhs_iio_callback()

In reply to Daniel Henrique Barboza

'out' is just a 'return' call.

---
 block/vxhs.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
block/vxhs.c +1 -3
index d79fc97df6..e3db367918 100644
@@ -96,7 +96,7 @@ static void vxhs_iio_callback(void *ctx, uint32_t opcode, uint32_t error)
             acb = ctx;
         } else {
             trace_vxhs_iio_callback(error);
-            goto out;
+            return;
         }
 
         if (error) {
@@ -122,8 +122,6 @@ static void vxhs_iio_callback(void *ctx, uint32_t opcode, uint32_t error)
         }
         break;
     }
-out:
-    return;
 }
 
 static QemuOptsList runtime_opts = {
Signature · 1 line
2.24.1
#44 lore raw

PATCH 24/59 block/vhdx-log.c: remove unneeded labels

In reply to Daniel Henrique Barboza

Removing some 'exit' labels used in some functions that are unneeded, changing them for the adequate 'return' value for the context.

---
 block/vhdx-log.c | 86 ++++++++++++++++++------------------------------
 1 file changed, 32 insertions(+), 54 deletions(-)
block/vhdx-log.c +32 -54
index 13a49c2a33..ba89f0adc6 100644
@@ -64,8 +64,7 @@ static int vhdx_log_peek_hdr(BlockDriverState *bs, VHDXLogEntries *log,
 
     /* peek is only supported on sector boundaries */
     if (log->read % VHDX_LOG_SECTOR_SIZE) {
-        ret = -EFAULT;
-        goto exit;
+        return -EFAULT;
     }
 
     read = log->read;
@@ -77,19 +76,17 @@ static int vhdx_log_peek_hdr(BlockDriverState *bs, VHDXLogEntries *log,
     }
 
     if (read == log->write) {
-        ret = -EINVAL;
-        goto exit;
+        return -EINVAL;
     }
 
     offset = log->offset + read;
 
     ret = bdrv_pread(bs->file, offset, hdr, sizeof(VHDXLogEntryHeader));
     if (ret < 0) {
-        goto exit;
+        return ret;
     }
     vhdx_log_entry_hdr_le_import(hdr);
 
-exit:
     return ret;
 }
 
@@ -179,7 +176,7 @@ static int vhdx_log_write_sectors(BlockDriverState *bs, VHDXLogEntries *log,
 
     ret = vhdx_user_visible_write(bs, s);
     if (ret < 0) {
-        goto exit;
+        return ret;
     }
 
     write = log->write;
@@ -196,7 +193,7 @@ static int vhdx_log_write_sectors(BlockDriverState *bs, VHDXLogEntries *log,
         ret = bdrv_pwrite(bs->file, offset, buffer_tmp,
                           VHDX_LOG_SECTOR_SIZE);
         if (ret < 0) {
-            goto exit;
+            return ret;
         }
         buffer_tmp += VHDX_LOG_SECTOR_SIZE;
 
@@ -205,7 +202,6 @@ static int vhdx_log_write_sectors(BlockDriverState *bs, VHDXLogEntries *log,
         num_sectors--;
     }
 
-exit:
     return ret;
 }
 
@@ -214,42 +210,37 @@ exit:
 static bool vhdx_log_hdr_is_valid(VHDXLogEntries *log, VHDXLogEntryHeader *hdr,
                                   BDRVVHDXState *s)
 {
-    int valid = false;
-
     if (hdr->signature != VHDX_LOG_SIGNATURE) {
-        goto exit;
+        return false;
     }
 
     /* if the individual entry length is larger than the whole log
      * buffer, that is obviously invalid */
     if (log->length < hdr->entry_length) {
-        goto exit;
+        return false;
     }
 
     /* length of entire entry must be in units of 4KB (log sector size) */
     if (hdr->entry_length % (VHDX_LOG_SECTOR_SIZE)) {
-        goto exit;
+        return false;
     }
 
     /* per spec, sequence # must be > 0 */
     if (hdr->sequence_number == 0) {
-        goto exit;
+        return false;
     }
 
     /* log entries are only valid if they match the file-wide log guid
      * found in the active header */
     if (!guid_eq(hdr->log_guid, s->headers[s->curr_header]->log_guid)) {
-        goto exit;
+        return false;
     }
 
     if (hdr->descriptor_count * sizeof(VHDXLogDescriptor) > hdr->entry_length) {
-        goto exit;
+        return false;
     }
 
-    valid = true;
-
-exit:
-    return valid;
+    return true;
 }
 
 /*
@@ -274,10 +265,10 @@ static bool vhdx_log_desc_is_valid(VHDXLogDescriptor *desc,
     bool ret = false;
 
     if (desc->sequence_number != hdr->sequence_number) {
-        goto exit;
+        return false;
     }
     if (desc->file_offset % VHDX_LOG_SECTOR_SIZE) {
-        goto exit;
+        return false;
     }
 
     if (desc->signature == VHDX_LOG_ZERO_SIGNATURE) {
@@ -290,7 +281,6 @@ static bool vhdx_log_desc_is_valid(VHDXLogDescriptor *desc,
             ret = true;
     }
 
-exit:
     return ret;
 }
 
@@ -347,20 +337,18 @@ static int vhdx_log_read_desc(BlockDriverState *bs, BDRVVHDXState *s,
 
     ret = vhdx_log_peek_hdr(bs, log, &hdr);
     if (ret < 0) {
-        goto exit;
+        return ret;
     }
 
     if (vhdx_log_hdr_is_valid(log, &hdr, s) == false) {
-        ret = -EINVAL;
-        goto exit;
+        return -EINVAL;
     }
 
     desc_sectors = vhdx_compute_desc_sectors(hdr.descriptor_count);
     desc_entries = qemu_try_blockalign(bs->file->bs,
                                        desc_sectors * VHDX_LOG_SECTOR_SIZE);
     if (desc_entries == NULL) {
-        ret = -ENOMEM;
-        goto exit;
+        return -ENOMEM;
     }
 
     ret = vhdx_log_read_sectors(bs, log, &sectors_read, desc_entries,
@@ -390,11 +378,10 @@ static int vhdx_log_read_desc(BlockDriverState *bs, BDRVVHDXState *s,
     }
 
     *buffer = desc_entries;
-    goto exit;
+    return ret;
 
 free_and_exit:
     qemu_vfree(desc_entries);
-exit:
     return ret;
 }
 
@@ -688,7 +675,7 @@ static int vhdx_log_search(BlockDriverState *bs, BDRVVHDXState *s,
         ret = vhdx_validate_log_entry(bs, s, &curr_log, curr_seq,
                                       &seq_valid, &hdr);
         if (ret < 0) {
-            goto exit;
+            return ret;
         }
 
         if (seq_valid) {
@@ -704,7 +691,7 @@ static int vhdx_log_search(BlockDriverState *bs, BDRVVHDXState *s,
                 ret = vhdx_validate_log_entry(bs, s, &curr_log, curr_seq,
                                               &seq_valid, &hdr);
                 if (ret < 0) {
-                    goto exit;
+                    return ret;
                 }
                 if (seq_valid == false) {
                     break;
@@ -735,8 +722,6 @@ static int vhdx_log_search(BlockDriverState *bs, BDRVVHDXState *s,
         s->log.sequence = candidate.hdr.sequence_number + 1;
     }
 
-
-exit:
     return ret;
 }
 
@@ -766,29 +751,26 @@ int vhdx_parse_log(BlockDriverState *bs, BDRVVHDXState *s, bool *flushed,
 
     if (s->log.offset < VHDX_LOG_MIN_SIZE ||
         s->log.offset % VHDX_LOG_MIN_SIZE) {
-        ret = -EINVAL;
-        goto exit;
+        return -EINVAL;
     }
 
     /* per spec, only log version of 0 is supported */
     if (hdr->log_version != 0) {
-        ret = -EINVAL;
-        goto exit;
+        return -EINVAL;
     }
 
     /* If either the log guid, or log length is zero,
      * then a replay log is not present */
     if (guid_eq(hdr->log_guid, zero_guid)) {
-        goto exit;
+        return 0;
     }
 
     if (hdr->log_length == 0) {
-        goto exit;
+        return 0;
     }
 
     if (hdr->log_length % VHDX_LOG_MIN_SIZE) {
-        ret = -EINVAL;
-        goto exit;
+        return -EINVAL;
     }
 
 
@@ -797,13 +779,12 @@ int vhdx_parse_log(BlockDriverState *bs, BDRVVHDXState *s, bool *flushed,
 
     ret = vhdx_log_search(bs, s, &logs);
     if (ret < 0) {
-        goto exit;
+        return ret;
     }
 
     if (logs.valid) {
         if (bs->read_only) {
             bdrv_refresh_filename(bs);
-            ret = -EPERM;
             error_setg(errp,
                        "VHDX image file '%s' opened read-only, but "
                        "contains a log that needs to be replayed",
@@ -811,18 +792,16 @@ int vhdx_parse_log(BlockDriverState *bs, BDRVVHDXState *s, bool *flushed,
             error_append_hint(errp,  "To replay the log, run:\n"
                               "qemu-img check -r all '%s'\n",
                               bs->filename);
-            goto exit;
+            return -EPERM;
         }
         /* now flush the log */
         ret = vhdx_log_flush(bs, s, &logs);
         if (ret < 0) {
-            goto exit;
+            return ret;
         }
         *flushed = true;
     }
 
-
-exit:
     return ret;
 }
 
@@ -1048,29 +1027,28 @@ int vhdx_log_write_and_flush(BlockDriverState *bs, BDRVVHDXState *s,
      * on disk, before creating log entry */
     ret = bdrv_flush(bs);
     if (ret < 0) {
-        goto exit;
+        return ret;
     }
 
     ret = vhdx_log_write(bs, s, data, length, offset);
     if (ret < 0) {
-        goto exit;
+        return ret;
     }
     logs.log = s->log;
 
     /* Make sure log is stable on disk */
     ret = bdrv_flush(bs);
     if (ret < 0) {
-        goto exit;
+        return ret;
     }
 
     ret = vhdx_log_flush(bs, s, &logs);
     if (ret < 0) {
-        goto exit;
+        return ret;
     }
 
     s->log = logs.log;
 
-exit:
     return ret;
 }
 
Signature · 1 line
2.24.1
#19 lore raw

PATCH 10/59 chardev/char-win.c: remove 'fail' label in win_chr_serial_init()

In reply to Daniel Henrique Barboza

The 'fail' label is a simply call to 'return -1' on error. Remove it and do the return call instead.

CC Marc-André Lureau <[email protected]>
CC Paolo Bonzini <[email protected]>
---
 chardev/char-win.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
chardev/char-win.c +8 -11
index 34825f683d..72c232e6d9 100644
@@ -85,12 +85,12 @@ int win_chr_serial_init(Chardev *chr, const char *filename, Error **errp)
     s->hsend = CreateEvent(NULL, TRUE, FALSE, NULL);
     if (!s->hsend) {
         error_setg(errp, "Failed CreateEvent");
-        goto fail;
+        return -1;
     }
     s->hrecv = CreateEvent(NULL, TRUE, FALSE, NULL);
     if (!s->hrecv) {
         error_setg(errp, "Failed CreateEvent");
-        goto fail;
+        return -1;
     }
 
     s->file = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
@@ -98,12 +98,12 @@ int win_chr_serial_init(Chardev *chr, const char *filename, Error **errp)
     if (s->file == INVALID_HANDLE_VALUE) {
         error_setg(errp, "Failed CreateFile (%lu)", GetLastError());
         s->file = NULL;
-        goto fail;
+        return -1;
     }
 
     if (!SetupComm(s->file, NRECVBUF, NSENDBUF)) {
         error_setg(errp, "Failed SetupComm");
-        goto fail;
+        return -1;
     }
 
     ZeroMemory(&comcfg, sizeof(COMMCONFIG));
@@ -114,29 +114,26 @@ int win_chr_serial_init(Chardev *chr, const char *filename, Error **errp)
 
     if (!SetCommState(s->file, &comcfg.dcb)) {
         error_setg(errp, "Failed SetCommState");
-        goto fail;
+        return -1;
     }
 
     if (!SetCommMask(s->file, EV_ERR)) {
         error_setg(errp, "Failed SetCommMask");
-        goto fail;
+        return -1;
     }
 
     cto.ReadIntervalTimeout = MAXDWORD;
     if (!SetCommTimeouts(s->file, &cto)) {
         error_setg(errp, "Failed SetCommTimeouts");
-        goto fail;
+        return -1;
     }
 
     if (!ClearCommError(s->file, &err, &comstat)) {
         error_setg(errp, "Failed ClearCommError");
-        goto fail;
+        return -1;
     }
     qemu_add_polling_cb(win_chr_serial_poll, chr);
     return 0;
-
- fail:
-    return -1;
 }
 
 int win_chr_pipe_poll(void *opaque)
Signature · 1 line
2.24.1
#37 lore raw

PATCH 18/59 qcow2-refcount.c: remove unneeded 'fail' label in qcow2_refcount_init()

In reply to Daniel Henrique Barboza

'fail' label can be replaced by 'return ret' and 'return -ENOMEM' calls.

---
 block/qcow2-refcount.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
block/qcow2-refcount.c +2 -5
index f67ac6b2d8..1fe66677d1 100644
@@ -111,22 +111,19 @@ int qcow2_refcount_init(BlockDriverState *bs)
 
     if (s->refcount_table_size > 0) {
         if (s->refcount_table == NULL) {
-            ret = -ENOMEM;
-            goto fail;
+            return -ENOMEM;
         }
         BLKDBG_EVENT(bs->file, BLKDBG_REFTABLE_LOAD);
         ret = bdrv_pread(bs->file, s->refcount_table_offset,
                          s->refcount_table, refcount_table_size2);
         if (ret < 0) {
-            goto fail;
+            return ret;
         }
         for(i = 0; i < s->refcount_table_size; i++)
             be64_to_cpus(&s->refcount_table[i]);
         update_max_refcount_table_index(s);
     }
     return 0;
- fail:
-    return ret;
 }
 
 void qcow2_refcount_close(BlockDriverState *bs)
Signature · 1 line
2.24.1
#46 lore raw

PATCH 26/59 block/replication.c: remove unneeded label in replication_co_writev

In reply to Daniel Henrique Barboza

The label 'out' in replication_co_writev() can be replaced by 'return ret'. The other label, 'out1', was renamed to 'out' since the original 'out' label was removed.

---
 block/replication.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
block/replication.c +4 -5
index 99532ce521..3d5eb64d41 100644
@@ -258,7 +258,7 @@ static coroutine_fn int replication_co_writev(BlockDriverState *bs,
     assert(!flags);
     ret = replication_get_io_status(s);
     if (ret < 0) {
-        goto out;
+        return ret;
     }
 
     if (ret == 0) {
@@ -280,7 +280,7 @@ static coroutine_fn int replication_co_writev(BlockDriverState *bs,
                                       remaining_sectors * BDRV_SECTOR_SIZE,
                                       &count);
         if (ret < 0) {
-            goto out1;
+            goto out;
         }
 
         assert(QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE));
@@ -292,7 +292,7 @@ static coroutine_fn int replication_co_writev(BlockDriverState *bs,
         ret = bdrv_co_pwritev(target, sector_num * BDRV_SECTOR_SIZE,
                               n * BDRV_SECTOR_SIZE, &hd_qiov, 0);
         if (ret < 0) {
-            goto out1;
+            goto out;
         }
 
         remaining_sectors -= n;
@@ -300,9 +300,8 @@ static coroutine_fn int replication_co_writev(BlockDriverState *bs,
         bytes_done += count;
     }
 
-out1:
-    qemu_iovec_destroy(&hd_qiov);
 out:
+    qemu_iovec_destroy(&hd_qiov);
     return ret;
 }
 
Signature · 1 line
2.24.1
#29 lore raw

PATCH 13/59 block/vdi.c: remove 'fail' label in vdi_open()

In reply to Daniel Henrique Barboza

The 'fail' label can be replaced by 'return ret' or by a 'return' with the error code that was being set right before the 'goto' call.

---
 block/vdi.c | 40 +++++++++++++---------------------------
 1 file changed, 13 insertions(+), 27 deletions(-)
block/vdi.c +13 -27
index 0142da7233..6d486ffed9 100644
@@ -388,7 +388,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
 
     ret = bdrv_pread(bs->file, 0, &header, sizeof(header));
     if (ret < 0) {
-        goto fail;
+        return ret;
     }
 
     vdi_header_to_cpu(&header);
@@ -400,8 +400,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
         error_setg(errp, "Unsupported VDI image size (size is 0x%" PRIx64
                           ", max supported is 0x%" PRIx64 ")",
                           header.disk_size, VDI_DISK_SIZE_MAX);
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     }
 
     uuid_link = header.uuid_link;
@@ -418,58 +417,48 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
     if (header.signature != VDI_SIGNATURE) {
         error_setg(errp, "Image not in VDI format (bad signature %08" PRIx32
                    ")", header.signature);
-        ret = -EINVAL;
-        goto fail;
+        return -EINVAL;
     } else if (header.version != VDI_VERSION_1_1) {
         error_setg(errp, "unsupported VDI image (version %" PRIu32 ".%" PRIu32
                    ")", header.version >> 16, header.version & 0xffff);
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     } else if (header.offset_bmap % SECTOR_SIZE != 0) {
         /* We only support block maps which start on a sector boundary. */
         error_setg(errp, "unsupported VDI image (unaligned block map offset "
                    "0x%" PRIx32 ")", header.offset_bmap);
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     } else if (header.offset_data % SECTOR_SIZE != 0) {
         /* We only support data blocks which start on a sector boundary. */
         error_setg(errp, "unsupported VDI image (unaligned data offset 0x%"
                    PRIx32 ")", header.offset_data);
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     } else if (header.sector_size != SECTOR_SIZE) {
         error_setg(errp, "unsupported VDI image (sector size %" PRIu32
                    " is not %u)", header.sector_size, SECTOR_SIZE);
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     } else if (header.block_size != DEFAULT_CLUSTER_SIZE) {
         error_setg(errp, "unsupported VDI image (block size %" PRIu32
                          " is not %" PRIu32 ")",
                    header.block_size, DEFAULT_CLUSTER_SIZE);
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     } else if (header.disk_size >
                (uint64_t)header.blocks_in_image * header.block_size) {
         error_setg(errp, "unsupported VDI image (disk size %" PRIu64 ", "
                    "image bitmap has room for %" PRIu64 ")",
                    header.disk_size,
                    (uint64_t)header.blocks_in_image * header.block_size);
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     } else if (!qemu_uuid_is_null(&uuid_link)) {
         error_setg(errp, "unsupported VDI image (non-NULL link UUID)");
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     } else if (!qemu_uuid_is_null(&uuid_parent)) {
         error_setg(errp, "unsupported VDI image (non-NULL parent UUID)");
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     } else if (header.blocks_in_image > VDI_BLOCKS_IN_IMAGE_MAX) {
         error_setg(errp, "unsupported VDI image "
                          "(too many blocks %u, max is %u)",
                           header.blocks_in_image, VDI_BLOCKS_IN_IMAGE_MAX);
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     }
 
     bs->total_sectors = header.disk_size / SECTOR_SIZE;
@@ -482,8 +471,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
     bmap_size = DIV_ROUND_UP(bmap_size, SECTOR_SIZE);
     s->bmap = qemu_try_blockalign(bs->file->bs, bmap_size * SECTOR_SIZE);
     if (s->bmap == NULL) {
-        ret = -ENOMEM;
-        goto fail;
+        return -ENOMEM;
     }
 
     ret = bdrv_pread(bs->file, header.offset_bmap, s->bmap,
@@ -509,8 +497,6 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
 
  fail_free_bmap:
     qemu_vfree(s->bmap);
-
- fail:
     return ret;
 }
 
Signature · 1 line
2.24.1
#49 lore raw

PATCH 29/59 cryptodev-vhost.c: remove unneeded 'err' label in cryptodev_vhost_start

In reply to Daniel Henrique Barboza

'err' can be replaced by 'return r'.

---
 backends/cryptodev-vhost.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
backends/cryptodev-vhost.c +2 -2
index 8337c9a495..907ca21fa7 100644
@@ -201,7 +201,7 @@ int cryptodev_vhost_start(VirtIODevice *dev, int total_queues)
     r = k->set_guest_notifiers(qbus->parent, total_queues, true);
     if (r < 0) {
         error_report("error binding guest notifier: %d", -r);
-        goto err;
+        return r;
     }
 
     for (i = 0; i < total_queues; i++) {
@@ -236,7 +236,7 @@ err_start:
     if (e < 0) {
         error_report("vhost guest notifier cleanup failed: %d", e);
     }
-err:
+
     return r;
 }
 
Signature · 1 line
2.24.1
#52 lore raw

PATCH 30/59 util/module.c: remove unneeded label in module_load_file()

In reply to Daniel Henrique Barboza

'out' can be replaced by the apropriate return values set in 'ret' for each case.

---
 util/module.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
util/module.c +4 -7
index e9fe3e5422..9b5453f878 100644
@@ -111,12 +111,10 @@ static int module_load_file(const char *fname)
 
     if (len <= suf_len || strcmp(&fname[len - suf_len], dsosuf)) {
         /* wrong suffix */
-        ret = -EINVAL;
-        goto out;
+        return -EINVAL;
     }
     if (access(fname, F_OK)) {
-        ret = -ENOENT;
-        goto out;
+        return -ENOENT;
     }
 
     assert(QTAILQ_EMPTY(&dso_init_list));
@@ -125,8 +123,7 @@ static int module_load_file(const char *fname)
     if (!g_module) {
         fprintf(stderr, "Failed to open module: %s\n",
                 g_module_error());
-        ret = -EINVAL;
-        goto out;
+        return -EINVAL;
     }
     if (!g_module_symbol(g_module, DSO_STAMP_FUN_STR, (gpointer *)&sym)) {
         fprintf(stderr, "Failed to initialize module: %s\n",
@@ -151,7 +148,7 @@ static int module_load_file(const char *fname)
         QTAILQ_REMOVE(&dso_init_list, e, node);
         g_free(e);
     }
-out:
+
     return ret;
 }
 #endif
Signature · 1 line
2.24.1
#47 lore raw

PATCH 27/59 crypto/block-luks.c: remove unneeded label in qcrypto_block_luks_find_key

In reply to Daniel Henrique Barboza

'error' can be replaced by 'return -1' directly.

---
 crypto/block-luks.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
crypto/block-luks.c +1 -2
index 4861db810c..9742d4bdd9 100644
@@ -1057,7 +1057,7 @@ qcrypto_block_luks_find_key(QCryptoBlock *block,
                                          opaque,
                                          errp);
         if (rv < 0) {
-            goto error;
+            return -1;
         }
         if (rv == 1) {
             return 0;
@@ -1065,7 +1065,6 @@ qcrypto_block_luks_find_key(QCryptoBlock *block,
     }
 
     error_setg(errp, "Invalid password, cannot unlock any keyslot");
- error:
     return -1;
 }
 
Signature · 1 line
2.24.1
#32 lore raw

PATCH 15/59 block/blkreplay.c: remove unneeded 'fail' label in blkreplay_open()

In reply to Daniel Henrique Barboza

Both the 'fail' label and the 'ret' variable can be removed. Use 'return -EINVAL' in the error condition and 'return 0' in the end of the function.

CC Pavel Dovgalyuk <[email protected]>
CC Paolo Bonzini <[email protected]>
---
 block/blkreplay.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
block/blkreplay.c +2 -6
index c96ac8f4bc..d8c4c311f3 100644
@@ -24,23 +24,19 @@ static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags,
                           Error **errp)
 {
     Error *local_err = NULL;
-    int ret;
 
     /* Open the image file */
     bs->file = bdrv_open_child(NULL, options, "image",
                                bs, &child_file, false, &local_err);
     if (local_err) {
-        ret = -EINVAL;
         error_propagate(errp, local_err);
-        goto fail;
+        return -EINVAL;
     }
 
     bs->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED;
     bs->supported_zero_flags = BDRV_REQ_WRITE_UNCHANGED;
 
-    ret = 0;
-fail:
-    return ret;
+    return 0;
 }
 
 static int64_t blkreplay_getlength(BlockDriverState *bs)
Signature · 1 line
2.24.1
#54 lore raw

PATCH 31/59 util/aio-posix.c: remove unneeded 'out' label in aio_epoll

In reply to Daniel Henrique Barboza

'out' can be replaced by 'return ret'.

---
 util/aio-posix.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
util/aio-posix.c +1 -2
index a4977f538e..7c4cfea8ce 100644
@@ -121,7 +121,7 @@ static int aio_epoll(AioContext *ctx, GPollFD *pfds,
                          ARRAY_SIZE(events),
                          timeout);
         if (ret <= 0) {
-            goto out;
+            return ret;
         }
         for (i = 0; i < ret; i++) {
             int ev = events[i].events;
@@ -132,7 +132,6 @@ static int aio_epoll(AioContext *ctx, GPollFD *pfds,
                 (ev & EPOLLERR ? G_IO_ERR : 0);
         }
     }
-out:
     return ret;
 }
 
Signature · 1 line
2.24.1
#58 lore raw

PATCH 34/59 ipmi/ipmi_bt.c: remove unneeded label in ipmi_bt_handle_event

In reply to Daniel Henrique Barboza

'out' can be replaced by 'return'.

---
 hw/ipmi/ipmi_bt.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
hw/ipmi/ipmi_bt.c +3 -5
index 22f94fb98d..8173551d7d 100644
@@ -98,14 +98,14 @@ static void ipmi_bt_handle_event(IPMIInterface *ii)
     IPMIBT *ib = iic->get_backend_data(ii);
 
     if (ib->inlen < 4) {
-        goto out;
+        return;
     }
     /* Note that overruns are handled by handle_command */
     if (ib->inmsg[0] != (ib->inlen - 1)) {
         /* Length mismatch, just ignore. */
         IPMI_BT_SET_BBUSY(ib->control_reg, 1);
         ib->inlen = 0;
-        goto out;
+        return;
     }
     if ((ib->inmsg[1] == (IPMI_NETFN_APP << 2)) &&
                         (ib->inmsg[3] == IPMI_CMD_GET_BT_INTF_CAP)) {
@@ -136,7 +136,7 @@ static void ipmi_bt_handle_event(IPMIInterface *ii)
             IPMI_BT_SET_B2H_IRQ(ib->mask_reg, 1);
             ipmi_bt_raise_irq(ib);
         }
-        goto out;
+        return;
     }
     ib->waiting_seq = ib->inmsg[2];
     ib->inmsg[2] = ib->inmsg[1];
@@ -145,8 +145,6 @@ static void ipmi_bt_handle_event(IPMIInterface *ii)
         bk->handle_command(ib->bmc, ib->inmsg + 2, ib->inlen - 2,
                            sizeof(ib->inmsg), ib->waiting_rsp);
     }
- out:
-    return;
 }
 
 static void ipmi_bt_handle_rsp(IPMIInterface *ii, uint8_t msg_id,
Signature · 1 line
2.24.1
#57 lore raw

PATCH 33/59 ipmi/ipmi_bmc_sim.c: remove unneeded labels

In reply to Daniel Henrique Barboza

Label 'out' from ipmi_bmc_gen_event() and gen_event() can be replaced by 'return'.

---
 hw/ipmi/ipmi_bmc_sim.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
hw/ipmi/ipmi_bmc_sim.c +2 -7
index 6670cf039d..1e06fd1de9 100644
@@ -461,14 +461,12 @@ void ipmi_bmc_gen_event(IPMIBmc *b, uint8_t *evt, bool log)
     }
 
     if (ibs->msg_flags & IPMI_BMC_MSG_FLAG_EVT_BUF_FULL) {
-        goto out;
+        return;
     }
 
     memcpy(ibs->evtbuf, evt, 16);
     ibs->msg_flags |= IPMI_BMC_MSG_FLAG_EVT_BUF_FULL;
     k->set_atn(s, 1, attn_irq_enabled(ibs));
- out:
-    return;
 }
 static void gen_event(IPMIBmcSim *ibs, unsigned int sens_num, uint8_t deassert,
                       uint8_t evd1, uint8_t evd2, uint8_t evd3)
@@ -978,7 +976,7 @@ static void get_msg(IPMIBmcSim *ibs,
 
     if (QTAILQ_EMPTY(&ibs->rcvbufs)) {
         rsp_buffer_set_error(rsp, 0x80); /* Queue empty */
-        goto out;
+        return;
     }
     rsp_buffer_push(rsp, 0); /* Channel 0 */
     msg = QTAILQ_FIRST(&ibs->rcvbufs);
@@ -993,9 +991,6 @@ static void get_msg(IPMIBmcSim *ibs,
         ibs->msg_flags &= ~IPMI_BMC_MSG_FLAG_RCV_MSG_QUEUE;
         k->set_atn(s, attn_set(ibs), attn_irq_enabled(ibs));
     }
-
-out:
-    return;
 }
 
 static unsigned char
Signature · 1 line
2.24.1
#34 lore raw

PATCH 16/59 block/gluster.c: remove unneeded 'exit' label

In reply to Daniel Henrique Barboza

'exit' label in find_allocation() can be replaced by a 'return -ENOTSUP' call.

---
 block/gluster.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
block/gluster.c +1 -2
index 4fa4a77a47..43bf76eed7 100644
@@ -1381,7 +1381,7 @@ static int find_allocation(BlockDriverState *bs, off_t start,
     BDRVGlusterState *s = bs->opaque;
 
     if (!s->supports_seek_data) {
-        goto exit;
+        return -ENOTSUP;
     }
 
 #if defined SEEK_HOLE && defined SEEK_DATA
@@ -1466,7 +1466,6 @@ static int find_allocation(BlockDriverState *bs, off_t start,
     return -EBUSY;
 #endif
 
-exit:
     return -ENOTSUP;
 }
 
Signature · 1 line
2.24.1
#60 lore raw

PATCH 36/59 ipmi/ipmi_kcs.c: remove unneeded label in ipmi_kcs_handle_event

In reply to Daniel Henrique Barboza

'out_noibf' can be replaced by 'return'.

---
 hw/ipmi/ipmi_kcs.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/ipmi/ipmi_kcs.c +1 -3
index a77612946a..83009baddb 100644
@@ -168,7 +168,7 @@ static void ipmi_kcs_handle_event(IPMIInterface *ii)
             ik->outpos = 0;
             bk->handle_command(ik->bmc, ik->inmsg, ik->inlen, sizeof(ik->inmsg),
                                ik->waiting_rsp);
-            goto out_noibf;
+            return;
         } else if (ik->cmd_reg == IPMI_KCS_WRITE_END_CMD) {
             ik->cmd_reg = -1;
             ik->write_end = 1;
@@ -197,8 +197,6 @@ static void ipmi_kcs_handle_event(IPMIInterface *ii)
     ik->cmd_reg = -1;
     ik->data_in_reg = -1;
     IPMI_KCS_SET_IBF(ik->status_reg, 0);
- out_noibf:
-    return;
 }
 
 static void ipmi_kcs_handle_rsp(IPMIInterface *ii, uint8_t msg_id,
Signature · 1 line
2.24.1
#87 lore raw

PATCH 48/59 pvrdma_dev_ring.c: remove unneeded label in pvrdma_ring_init()

In reply to Daniel Henrique Barboza

'out' label can be replaced by 'return' with the right return value. Since the 'rc' var was being used just to set -ENOMEM in a single error condition, get rid of the var and set the return value directly in the 'return' call.

---
 hw/rdma/vmw/pvrdma_dev_ring.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
hw/rdma/vmw/pvrdma_dev_ring.c +2 -5
index d7bc7f5ccc..c2ecce3b41 100644
@@ -28,7 +28,6 @@ int pvrdma_ring_init(PvrdmaRing *ring, const char *name, PCIDevice *dev,
                      size_t elem_sz, dma_addr_t *tbl, uint32_t npages)
 {
     int i;
-    int rc = 0;
 
     strncpy(ring->name, name, MAX_RING_NAME_SZ);
     ring->name[MAX_RING_NAME_SZ - 1] = 0;
@@ -51,14 +50,13 @@ int pvrdma_ring_init(PvrdmaRing *ring, const char *name, PCIDevice *dev,
 
         ring->pages[i] = rdma_pci_dma_map(dev, tbl[i], TARGET_PAGE_SIZE);
         if (!ring->pages[i]) {
-            rc = -ENOMEM;
             rdma_error_report("Failed to map to page %d in ring %s", i, name);
             goto out_free;
         }
         memset(ring->pages[i], 0, TARGET_PAGE_SIZE);
     }
 
-    goto out;
+    return 0;
 
 out_free:
     while (i--) {
@@ -66,8 +64,7 @@ out_free:
     }
     g_free(ring->pages);
 
-out:
-    return rc;
+    return -ENOMEM;
 }
 
 void *pvrdma_ring_next_elem_read(PvrdmaRing *ring)
Signature · 1 line
2.24.1
#61 lore raw

PATCH 37/59 s390x/event-facility.c: remove unneeded labels

In reply to Daniel Henrique Barboza

'out' label from write_event_mask(), handle_sccb_read_events() and write_event_data() can be replaced by 'return'.

CC Cornelia Huck <[email protected]>
CC Halil Pasic <[email protected]>
CC Christian Borntraeger <[email protected]>
---
 hw/s390x/event-facility.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)
hw/s390x/event-facility.c +6 -15
index 6afe278cad..f3b9661f32 100644
@@ -182,11 +182,11 @@ static void write_event_data(SCLPEventFacility *ef, SCCB *sccb)
 {
     if (sccb->h.function_code != SCLP_FC_NORMAL_WRITE) {
         sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_FUNCTION);
-        goto out;
+        return;
     }
     if (be16_to_cpu(sccb->h.length) < 8) {
         sccb->h.response_code = cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LENGTH);
-        goto out;
+        return;
     }
     /* first do a sanity check of the write events */
     sccb->h.response_code = cpu_to_be16(write_event_length_check(sccb));
@@ -196,9 +196,6 @@ static void write_event_data(SCLPEventFacility *ef, SCCB *sccb)
         sccb->h.response_code =
                 cpu_to_be16(handle_sccb_write_events(ef, sccb));
     }
-
-out:
-    return;
 }
 
 static uint16_t handle_sccb_read_events(SCLPEventFacility *ef, SCCB *sccb,
@@ -262,7 +259,7 @@ static void read_event_data(SCLPEventFacility *ef, SCCB *sccb)
 
     if (be16_to_cpu(sccb->h.length) != SCCB_SIZE) {
         sccb->h.response_code = cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LENGTH);
-        goto out;
+        return;
     }
 
     sclp_cp_receive_mask = ef->receive_mask;
@@ -280,18 +277,15 @@ static void read_event_data(SCLPEventFacility *ef, SCCB *sccb)
             (sclp_active_selection_mask & ~sclp_cp_receive_mask)) {
             sccb->h.response_code =
                     cpu_to_be16(SCLP_RC_INVALID_SELECTION_MASK);
-            goto out;
+            return;
         }
         break;
     default:
         sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_FUNCTION);
-        goto out;
+        return;
     }
     sccb->h.response_code = cpu_to_be16(
             handle_sccb_read_events(ef, sccb, sclp_active_selection_mask));
-
-out:
-    return;
 }
 
 static void write_event_mask(SCLPEventFacility *ef, SCCB *sccb)
@@ -303,7 +297,7 @@ static void write_event_mask(SCLPEventFacility *ef, SCCB *sccb)
     if (!mask_length || (mask_length > SCLP_EVENT_MASK_LEN_MAX) ||
         ((mask_length != 4) && !ef->allow_all_mask_sizes)) {
         sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_MASK_LENGTH);
-        goto out;
+        return;
     }
 
     /*
@@ -328,9 +322,6 @@ static void write_event_mask(SCLPEventFacility *ef, SCCB *sccb)
 
     sccb->h.response_code = cpu_to_be16(SCLP_RC_NORMAL_COMPLETION);
     ef->mask_length = mask_length;
-
-out:
-    return;
 }
 
 /* qemu object creation and initialization functions */
Signature · 1 line
2.24.1
#35 lore raw

PATCH 17/59 block/dmg.c: remove unneeded 'fail' label in dmg_read_mish_block()

In reply to Daniel Henrique Barboza

Both the 'fail' label and 'ret' variable can be removed from the function. Instead, call 'return -EINVAL' in the error conditions.

---
 block/dmg.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
block/dmg.c +2 -8
index 4a045f2b3e..ce39a87864 100644
@@ -217,7 +217,6 @@ static int dmg_read_mish_block(BDRVDMGState *s, DmgHeaderState *ds,
                                uint8_t *buffer, uint32_t count)
 {
     uint32_t type, i;
-    int ret;
     size_t new_size;
     uint32_t chunk_count;
     int64_t offset = 0;
@@ -273,8 +272,7 @@ static int dmg_read_mish_block(BDRVDMGState *s, DmgHeaderState *ds,
             error_report("sector count %" PRIu64 " for chunk %" PRIu32
                          " is larger than max (%u)",
                          s->sectorcounts[i], i, DMG_SECTORCOUNTS_MAX);
-            ret = -EINVAL;
-            goto fail;
+            return -EINVAL;
         }
 
         /* offset in (compressed) data fork */
@@ -288,8 +286,7 @@ static int dmg_read_mish_block(BDRVDMGState *s, DmgHeaderState *ds,
             error_report("length %" PRIu64 " for chunk %" PRIu32
                          " is larger than max (%u)",
                          s->lengths[i], i, DMG_LENGTHS_MAX);
-            ret = -EINVAL;
-            goto fail;
+            return -EINVAL;
         }
 
         update_max_chunk_size(s, i, &ds->max_compressed_size,
@@ -298,9 +295,6 @@ static int dmg_read_mish_block(BDRVDMGState *s, DmgHeaderState *ds,
     }
     s->n_chunks += chunk_count;
     return 0;
-
-fail:
-    return ret;
 }
 
 static int dmg_read_resource_fork(BlockDriverState *bs, DmgHeaderState *ds,
Signature · 1 line
2.24.1
#65 lore raw

PATCH 38/59 s390x/sclp.c: remove unneeded label in sclp_service_call()

In reply to Daniel Henrique Barboza

'out' label can be replaced by 'return' with the appropriate value. The 'r' integer, which is used solely to set the return value for this label, can also be removed.

CC Cornelia Huck <[email protected]>
CC Halil Pasic <[email protected]>
CC Christian Borntraeger <[email protected]>
---
 hw/s390x/sclp.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
hw/s390x/sclp.c +5 -11
index f57ce7b739..af0bfbc2ec 100644
@@ -197,24 +197,20 @@ int sclp_service_call(CPUS390XState *env, uint64_t sccb, uint32_t code)
 {
     SCLPDevice *sclp = get_sclp_device();
     SCLPDeviceClass *sclp_c = SCLP_GET_CLASS(sclp);
-    int r = 0;
     SCCB work_sccb;
 
     hwaddr sccb_len = sizeof(SCCB);
 
     /* first some basic checks on program checks */
     if (env->psw.mask & PSW_MASK_PSTATE) {
-        r = -PGM_PRIVILEGED;
-        goto out;
+        return -PGM_PRIVILEGED;
     }
     if (cpu_physical_memory_is_io(sccb)) {
-        r = -PGM_ADDRESSING;
-        goto out;
+        return -PGM_ADDRESSING;
     }
     if ((sccb & ~0x1fffUL) == 0 || (sccb & ~0x1fffUL) == env->psa
         || (sccb & ~0x7ffffff8UL) != 0) {
-        r = -PGM_SPECIFICATION;
-        goto out;
+        return -PGM_SPECIFICATION;
     }
 
     /*
@@ -226,8 +222,7 @@ int sclp_service_call(CPUS390XState *env, uint64_t sccb, uint32_t code)
 
     /* Valid sccb sizes */
     if (be16_to_cpu(work_sccb.h.length) < sizeof(SCCBHeader)) {
-        r = -PGM_SPECIFICATION;
-        goto out;
+        return -PGM_SPECIFICATION;
     }
 
     switch (code & SCLP_CMD_CODE_MASK) {
@@ -257,8 +252,7 @@ out_write:
 
     sclp_c->service_interrupt(sclp, sccb);
 
-out:
-    return r;
+    return 0;
 }
 
 static void service_interrupt(SCLPDevice *sclp, uint32_t sccb)
Signature · 1 line
2.24.1
#89 lore raw

PATCH 50/59 rdma/rdma_backend.c: remove unneeded label in rdma_backend_init()

In reply to Daniel Henrique Barboza

'out' label can be replaced by 'return -EIO' in the single goto jump.

---
 hw/rdma/rdma_backend.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/rdma/rdma_backend.c +1 -3
index c346407cd3..20c4c9fc3a 100644
@@ -1335,8 +1335,7 @@ int rdma_backend_init(RdmaBackendDev *backend_dev, PCIDevice *pdev,
     if (!backend_dev->context) {
         rdma_error_report("Failed to open IB device %s",
                           ibv_get_device_name(backend_dev->ib_dev));
-        ret = -EIO;
-        goto out;
+        return -EIO;
     }
 
     backend_dev->channel = ibv_create_comp_channel(backend_dev->context);
@@ -1377,7 +1376,6 @@ out_close_device:
 out_free_dev_list:
     ibv_free_device_list(dev_list);
 
-out:
     return ret;
 }
 
Signature · 1 line
2.24.1
#68 lore raw

PATCH 39/59 usb/dev-mtp.c: remove unneeded label in write_retry()

In reply to Daniel Henrique Barboza

'done' can be replaced by 'return 0'. The 'ret' variable can be removed since it's only set in qemu_write_full(), which is now the returned value of the function.

write_retry() body also has an extra layer of identation. Let's fix that to make it compliant with the other functions in the file.

---
 hw/usb/dev-mtp.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
hw/usb/dev-mtp.c +4 -9
index 7c07295519..818aa066c9 100644
@@ -1576,16 +1576,11 @@ static char *utf16_to_str(uint8_t len, uint8_t *str16)
 /* Wrapper around write, returns 0 on failure */
 static uint64_t write_retry(int fd, void *buf, uint64_t size, off_t offset)
 {
-        uint64_t ret = 0;
-
-        if (lseek(fd, offset, SEEK_SET) < 0) {
-            goto done;
-        }
-
-        ret = qemu_write_full(fd, buf, size);
+    if (lseek(fd, offset, SEEK_SET) < 0) {
+        return 0;
+    }
 
-done:
-        return ret;
+    return qemu_write_full(fd, buf, size);
 }
 
 static int usb_mtp_update_object(MTPObject *parent, char *name)
Signature · 1 line
2.24.1
#38 lore raw

PATCH 19/59 block/ssh.c: remove unneeded labels

In reply to Daniel Henrique Barboza

The 'out' labels for check_host_key_knownhosts() and authenticate() functions can be removed and, instead, call 'return' with the appropriate return value. The 'ret' integer from both functions could also be removed.

---
 block/ssh.c | 61 +++++++++++++++++------------------------------------
 1 file changed, 19 insertions(+), 42 deletions(-)
block/ssh.c +19 -42
index b4375cf7d2..e0c56d002a 100644
@@ -276,7 +276,6 @@ static void ssh_parse_filename(const char *filename, QDict *options,
 
 static int check_host_key_knownhosts(BDRVSSHState *s, Error **errp)
 {
-    int ret;
 #ifdef HAVE_LIBSSH_0_8
     enum ssh_known_hosts_e state;
     int r;
@@ -295,7 +294,6 @@ static int check_host_key_knownhosts(BDRVSSHState *s, Error **errp)
         trace_ssh_check_host_key_knownhosts();
         break;
     case SSH_KNOWN_HOSTS_CHANGED:
-        ret = -EINVAL;
         r = ssh_get_server_publickey(s->session, &pubkey);
         if (r == 0) {
             r = ssh_get_publickey_hash(pubkey, SSH_PUBLICKEY_HASH_SHA256,
@@ -320,28 +318,23 @@ static int check_host_key_knownhosts(BDRVSSHState *s, Error **errp)
                        "host key does not match the one in known_hosts; this "
                        "may be a possible attack");
         }
-        goto out;
+        return -EINVAL;
     case SSH_KNOWN_HOSTS_OTHER:
-        ret = -EINVAL;
         error_setg(errp,
                    "host key for this server not found, another type exists");
-        goto out;
+        return -EINVAL;
     case SSH_KNOWN_HOSTS_UNKNOWN:
-        ret = -EINVAL;
         error_setg(errp, "no host key was found in known_hosts");
-        goto out;
+        return -EINVAL;
     case SSH_KNOWN_HOSTS_NOT_FOUND:
-        ret = -ENOENT;
         error_setg(errp, "known_hosts file not found");
-        goto out;
+        return -ENOENT;
     case SSH_KNOWN_HOSTS_ERROR:
-        ret = -EINVAL;
         error_setg(errp, "error while checking the host");
-        goto out;
+        return -EINVAL;
     default:
-        ret = -EINVAL;
         error_setg(errp, "error while checking for known server (%d)", state);
-        goto out;
+        return -EINVAL;
     }
 #else /* !HAVE_LIBSSH_0_8 */
     int state;
@@ -355,40 +348,31 @@ static int check_host_key_knownhosts(BDRVSSHState *s, Error **errp)
         trace_ssh_check_host_key_knownhosts();
         break;
     case SSH_SERVER_KNOWN_CHANGED:
-        ret = -EINVAL;
         error_setg(errp,
                    "host key does not match the one in known_hosts; this "
                    "may be a possible attack");
-        goto out;
+        return -EINVAL;
     case SSH_SERVER_FOUND_OTHER:
-        ret = -EINVAL;
         error_setg(errp,
                    "host key for this server not found, another type exists");
-        goto out;
+        return -EINVAL;
     case SSH_SERVER_FILE_NOT_FOUND:
-        ret = -ENOENT;
         error_setg(errp, "known_hosts file not found");
-        goto out;
+        return -ENOENT;
     case SSH_SERVER_NOT_KNOWN:
-        ret = -EINVAL;
         error_setg(errp, "no host key was found in known_hosts");
-        goto out;
+        return -EINVAL;
     case SSH_SERVER_ERROR:
-        ret = -EINVAL;
         error_setg(errp, "server error");
-        goto out;
+        return -EINVAL;
     default:
-        ret = -EINVAL;
         error_setg(errp, "error while checking for known server (%d)", state);
-        goto out;
+        return -EINVAL;
     }
 #endif /* !HAVE_LIBSSH_0_8 */
 
     /* known_hosts checking successful. */
-    ret = 0;
-
- out:
-    return ret;
+    return 0;
 }
 
 static unsigned hex2decimal(char ch)
@@ -501,20 +485,18 @@ static int check_host_key(BDRVSSHState *s, SshHostKeyCheck *hkc, Error **errp)
 
 static int authenticate(BDRVSSHState *s, Error **errp)
 {
-    int r, ret;
+    int r;
     int method;
 
     /* Try to authenticate with the "none" method. */
     r = ssh_userauth_none(s->session, NULL);
     if (r == SSH_AUTH_ERROR) {
-        ret = -EPERM;
         session_error_setg(errp, s, "failed to authenticate using none "
                                     "authentication");
-        goto out;
+        return -EPERM;
     } else if (r == SSH_AUTH_SUCCESS) {
         /* Authenticated! */
-        ret = 0;
-        goto out;
+        return 0;
     }
 
     method = ssh_userauth_list(s->session, NULL);
@@ -527,23 +509,18 @@ static int authenticate(BDRVSSHState *s, Error **errp)
     if (method & SSH_AUTH_METHOD_PUBLICKEY) {
         r = ssh_userauth_publickey_auto(s->session, NULL, NULL);
         if (r == SSH_AUTH_ERROR) {
-            ret = -EINVAL;
             session_error_setg(errp, s, "failed to authenticate using "
                                         "publickey authentication");
-            goto out;
+            return -EINVAL;
         } else if (r == SSH_AUTH_SUCCESS) {
             /* Authenticated! */
-            ret = 0;
-            goto out;
+            return 0;
         }
     }
 
-    ret = -EPERM;
     error_setg(errp, "failed to authenticate using publickey authentication "
                "and the identities held by your ssh-agent");
-
- out:
-    return ret;
+    return -EPERM;
 }
 
 static QemuOptsList ssh_runtime_opts = {
Signature · 1 line
2.24.1
#71 lore raw

PATCH 41/59 intc/s390_flic_kvm.c: remove unneeded label in kvm_flic_load()

In reply to Daniel Henrique Barboza

'out' label can be replaced by 'return' with the apropriate value that is set by 'r' right before the jump.

Christian Borntraeger <[email protected]>

---
 hw/intc/s390_flic_kvm.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
hw/intc/s390_flic_kvm.c +3 -7
index dddd33ea61..2e1e70c61d 100644
@@ -439,17 +439,14 @@ static int kvm_flic_load(QEMUFile *f, void *opaque, size_t size,
     count = qemu_get_be64(f);
     len = count * sizeof(struct kvm_s390_irq);
     if (count == FLIC_FAILED) {
-        r = -EINVAL;
-        goto out;
+        return -EINVAL;
     }
     if (count == 0) {
-        r = 0;
-        goto out;
+        return 0;
     }
     buf = g_try_malloc0(len);
     if (!buf) {
-        r = -ENOMEM;
-        goto out;
+        return -ENOMEM;
     }
 
     if (qemu_get_buffer(f, (uint8_t *) buf, len) != len) {
@@ -460,7 +457,6 @@ static int kvm_flic_load(QEMUFile *f, void *opaque, size_t size,
 
 out_free:
     g_free(buf);
-out:
     return r;
 }
 
Signature · 1 line
2.24.1
#90 lore raw

PATCH 51/59 virtio/vhost.c: remove unneeded labels

In reply to Daniel Henrique Barboza

The label 'err_features' in vhost_dev_set_log(), 'out' in vhost_device_iotlb_miss() and 'fail' in vhost_dev_enable_notifiers() can be replaced by 'return' with the appropriate value.

---
 hw/virtio/vhost.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
hw/virtio/vhost.c +4 -7
index 4da0d5a6c5..7b36839221 100644
@@ -774,7 +774,7 @@ static int vhost_dev_set_log(struct vhost_dev *dev, bool enable_log)
     int r, i, idx;
     r = vhost_dev_set_features(dev, enable_log);
     if (r < 0) {
-        goto err_features;
+        return r;
     }
     for (i = 0; i < dev->nvqs; ++i) {
         idx = dev->vhost_ops->vhost_get_vq_index(dev, dev->vq_index + i);
@@ -792,7 +792,6 @@ err_vq:
                                  dev->log_enabled);
     }
     vhost_dev_set_features(dev, dev->log_enabled);
-err_features:
     return r;
 }
 
@@ -938,7 +937,7 @@ int vhost_device_iotlb_miss(struct vhost_dev *dev, uint64_t iova, int write)
             trace_vhost_iotlb_miss(dev, 3);
             error_report("Fail to lookup the translated address "
                          "%"PRIx64, iotlb.translated_addr);
-            goto out;
+            return ret;
         }
 
         len = MIN(iotlb.addr_mask + 1, len);
@@ -949,13 +948,12 @@ int vhost_device_iotlb_miss(struct vhost_dev *dev, uint64_t iova, int write)
         if (ret) {
             trace_vhost_iotlb_miss(dev, 4);
             error_report("Fail to update device iotlb");
-            goto out;
+            return ret;
         }
     }
 
     trace_vhost_iotlb_miss(dev, 2);
 
-out:
     return ret;
 }
 
@@ -1356,7 +1354,7 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
     r = virtio_device_grab_ioeventfd(vdev);
     if (r < 0) {
         error_report("binding does not support host notifiers");
-        goto fail;
+        return r;
     }
 
     for (i = 0; i < hdev->nvqs; ++i) {
@@ -1380,7 +1378,6 @@ fail_vq:
         virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i);
     }
     virtio_device_release_ioeventfd(vdev);
-fail:
     return r;
 }
 
Signature · 1 line
2.24.1
#69 lore raw

PATCH 40/59 hsb/hcd-ehci.c: remove unneeded labels

In reply to Daniel Henrique Barboza

Label 'out' in ehci_state_fetchentry(), ehci_state_waitlisthead(), ehci_state_fetchqh() and ehci_state_execute() can be replaced by 'return' with the appropriate value.

---
 hw/usb/hcd-ehci.c | 32 ++++++++++----------------------
 1 file changed, 10 insertions(+), 22 deletions(-)
hw/usb/hcd-ehci.c +10 -22
index 56ab2f457f..d8103102d6 100644
@@ -1511,7 +1511,6 @@ static int ehci_state_waitlisthead(EHCIState *ehci,  int async)
 {
     EHCIqh qh;
     int i = 0;
-    int again = 0;
     uint32_t entry = ehci->asynclistaddr;
 
     /* set reclamation flag at start event (4.8.6) */
@@ -1536,8 +1535,7 @@ static int ehci_state_waitlisthead(EHCIState *ehci,  int async)
 
             ehci_set_fetch_addr(ehci, async, entry);
             ehci_set_state(ehci, async, EST_FETCHENTRY);
-            again = 1;
-            goto out;
+            return 1;
         }
 
         entry = qh.next;
@@ -1550,8 +1548,7 @@ static int ehci_state_waitlisthead(EHCIState *ehci,  int async)
 
     ehci_set_state(ehci, async, EST_ACTIVE);
 
-out:
-    return again;
+    return 0;
 }
 
 
@@ -1565,7 +1562,7 @@ static int ehci_state_fetchentry(EHCIState *ehci, int async)
 
     if (NLPTR_TBIT(entry)) {
         ehci_set_state(ehci, async, EST_ACTIVE);
-        goto out;
+        return 0;
     }
 
     /* section 4.8, only QH in async schedule */
@@ -1597,7 +1594,6 @@ static int ehci_state_fetchentry(EHCIState *ehci, int async)
         return -1;
     }
 
-out:
     return again;
 }
 
@@ -1617,14 +1613,12 @@ static EHCIQueue *ehci_state_fetchqh(EHCIState *ehci, int async)
     if (q->seen > 1) {
         /* we are going in circles -- stop processing */
         ehci_set_state(ehci, async, EST_ACTIVE);
-        q = NULL;
-        goto out;
+        return NULL;
     }
 
     if (get_dwords(ehci, NLPTR_GET(q->qhaddr),
                    (uint32_t *) &qh, sizeof(EHCIqh) >> 2) < 0) {
-        q = NULL;
-        goto out;
+        return NULL;
     }
     ehci_trace_qh(q, NLPTR_GET(q->qhaddr), &qh);
 
@@ -1658,8 +1652,7 @@ static EHCIQueue *ehci_state_fetchqh(EHCIState *ehci, int async)
             DPRINTF("FETCHQH:  QH 0x%08x. H-bit set, reclamation status reset"
                        " - done processing\n", q->qhaddr);
             ehci_set_state(ehci, async, EST_ACTIVE);
-            q = NULL;
-            goto out;
+            return NULL;
         }
     }
 
@@ -1688,7 +1681,6 @@ static EHCIQueue *ehci_state_fetchqh(EHCIState *ehci, int async)
         ehci_set_state(ehci, async, EST_ADVANCEQUEUE);
     }
 
-out:
     return q;
 }
 
@@ -1932,8 +1924,7 @@ static int ehci_state_execute(EHCIQueue *q)
     /* 4.10.3, bottom of page 82, go horizontal on transaction counter == 0 */
     if (!q->async && q->transact_ctr == 0) {
         ehci_set_state(q->ehci, q->async, EST_HORIZONTALQH);
-        again = 1;
-        goto out;
+        return 1;
     }
 
     if (q->async) {
@@ -1942,7 +1933,7 @@ static int ehci_state_execute(EHCIQueue *q)
 
     again = ehci_execute(p, "process");
     if (again == -1) {
-        goto out;
+        return -1;
     }
     if (p->packet.status == USB_RET_ASYNC) {
         ehci_flush_qh(q);
@@ -1954,14 +1945,11 @@ static int ehci_state_execute(EHCIQueue *q)
         } else {
             again = 1;
         }
-        goto out;
+        return again;
     }
 
     ehci_set_state(q->ehci, q->async, EST_EXECUTING);
-    again = 1;
-
-out:
-    return again;
+    return 1;
 }
 
 static int ehci_state_executing(EHCIQueue *q)
Signature · 1 line
2.24.1
#41 lore raw

PATCH 21/59 block/backup.c remove unneeded 'out' label in backup_run()

In reply to Daniel Henrique Barboza

'out' can be replaced by 'return ret' and 'return -ECANCELED'.

---
 block/backup.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
block/backup.c +2 -4
index cf62b1a38c..e73294872c 100644
@@ -254,13 +254,12 @@ static int coroutine_fn backup_run(Job *job, Error **errp)
 
         for (offset = 0; offset < s->len; ) {
             if (yield_and_check(s)) {
-                ret = -ECANCELED;
-                goto out;
+                return -ECANCELED;
             }
 
             ret = block_copy_reset_unallocated(s->bcs, offset, &count);
             if (ret < 0) {
-                goto out;
+                return ret;
             }
 
             offset += count;
@@ -284,7 +283,6 @@ static int coroutine_fn backup_run(Job *job, Error **errp)
         ret = backup_loop(s);
     }
 
- out:
     return ret;
 }
 
Signature · 1 line
2.24.1
#75 lore raw

PATCH 42/59 i386/intel_iommu.c: remove unneeded labels

In reply to Daniel Henrique Barboza

'out' label in vtd_lookup_iotlb() and 'done' label in vtd_process_device_iotlb_desc() can be replaced by 'return' with the apropriate value.

CC Michael S. Tsirkin <[email protected]>
CC Marcel Apfelbaum <[email protected]>
---
 hw/i386/intel_iommu.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
hw/i386/intel_iommu.c +3 -5
index 43c94b993b..e0dd987851 100644
@@ -304,11 +304,10 @@ static VTDIOTLBEntry *vtd_lookup_iotlb(IntelIOMMUState *s, uint16_t source_id,
                                 source_id, level);
         entry = g_hash_table_lookup(s->iotlb, &key);
         if (entry) {
-            goto out;
+            return entry;
         }
     }
 
-out:
     return entry;
 }
 
@@ -2380,12 +2379,12 @@ static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s,
 
     vtd_bus = vtd_find_as_from_bus_num(s, bus_num);
     if (!vtd_bus) {
-        goto done;
+        return true;
     }
 
     vtd_dev_as = vtd_bus->dev_as[devfn];
     if (!vtd_dev_as) {
-        goto done;
+        return true;
     }
 
     /* According to ATS spec table 2.4:
@@ -2410,7 +2409,6 @@ static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s,
     entry.translated_addr = 0;
     memory_region_notify_iommu(&vtd_dev_as->iommu, 0, entry);
 
-done:
     return true;
 }
 
Signature · 1 line
2.24.1
Reviewed-by on v1 5/59
#8 lore raw

Re: [PATCH v1 05/59] ram.c: remove unneeded labels

In reply to Daniel Henrique Barboza
Quoted 10 lines · * Daniel Henrique Barboza ([email protected]) wrote:

ram_save_queue_pages() has an 'err' label that can be replaced by 'return -1' instead.

Same thing with ram_discard_range(), and in this case we can also get rid of the 'ret' variable and return either '-1' on error or the result of ram_block_discard_range().

CC Juan Quintela <[email protected]>
CC Dr. David Alan Gilbert <[email protected]>
Quoted 78 lines
---
 migration/ram.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
migration/ram.c +5 -13
index 96feb4062c..980cc644d7 100644
@@ -2434,7 +2434,7 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len)
              * it's the 1st request.
              */
             error_report("ram_save_queue_pages no previous block");
-            goto err;
+            return -1;
         }
     } else {
         ramblock = qemu_ram_block_by_name(rbname);
@@ -2442,7 +2442,7 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len)
         if (!ramblock) {
             /* We shouldn't be asked for a non-existent RAMBlock */
             error_report("ram_save_queue_pages no block '%s'", rbname);
-            goto err;
+            return -1;
         }
         rs->last_req_rb = ramblock;
     }
@@ -2451,7 +2451,7 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len)
         error_report("%s request overrun start=" RAM_ADDR_FMT " len="
                      RAM_ADDR_FMT " blocklen=" RAM_ADDR_FMT,
                      __func__, start, len, ramblock->used_length);
-        goto err;
+        return -1;
     }
 
     struct RAMSrcPageRequest *new_entry =
@@ -2467,9 +2467,6 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len)
     qemu_mutex_unlock(&rs->src_page_req_mutex);
 
     return 0;
-
-err:
-    return -1;
 }
 
 static bool save_page_use_compression(RAMState *rs)
@@ -3072,8 +3069,6 @@ int ram_postcopy_send_discard_bitmap(MigrationState *ms)
  */
 int ram_discard_range(const char *rbname, uint64_t start, size_t length)
 {
-    int ret = -1;
-
     trace_ram_discard_range(rbname, start, length);
 
     RCU_READ_LOCK_GUARD();
@@ -3081,7 +3076,7 @@ int ram_discard_range(const char *rbname, uint64_t start, size_t length)
 
     if (!rb) {
         error_report("ram_discard_range: Failed to find block '%s'", rbname);
-        goto err;
+        return -1;
     }
 
     /*
@@ -3093,10 +3088,7 @@ int ram_discard_range(const char *rbname, uint64_t start, size_t length)
                      length >> qemu_target_page_bits());
     }
 
-    ret = ram_block_discard_range(rb, start, length);
-
-err:
-    return ret;
+    return ram_block_discard_range(rb, start, length);
 }
 
 /*
Signature · 1 line
2.24.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#91 lore raw

PATCH 52/59 net/vhost_net.c: remove unneeded labels

In reply to Daniel Henrique Barboza

Label 'fail_notifiers' in vhost_net_start_one() and 'err' in vhost_net_start() can be replaced by 'return r'.

---
 hw/net/vhost_net.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
hw/net/vhost_net.c +3 -4
index 6b82803fa7..272519f970 100644
@@ -230,7 +230,7 @@ static int vhost_net_start_one(struct vhost_net *net,
 
     r = vhost_dev_enable_notifiers(&net->dev, dev);
     if (r < 0) {
-        goto fail_notifiers;
+        return r;
     }
 
     r = vhost_dev_start(&net->dev, dev);
@@ -278,7 +278,6 @@ fail:
     vhost_dev_stop(&net->dev, dev);
 fail_start:
     vhost_dev_disable_notifiers(&net->dev, dev);
-fail_notifiers:
     return r;
 }
 
@@ -331,7 +330,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
     r = k->set_guest_notifiers(qbus->parent, total_queues * 2, true);
     if (r < 0) {
         error_report("Error binding guest notifier: %d", -r);
-        goto err;
+        return r;
     }
 
     for (i = 0; i < total_queues; i++) {
@@ -362,7 +361,7 @@ err_start:
         fprintf(stderr, "vhost guest notifier cleanup failed: %d\n", e);
         fflush(stderr);
     }
-err:
+
     return r;
 }
 
Signature · 1 line
2.24.1
#82 lore raw

PATCH 45/59 9pfs/9p.c: remove unneeded labels

In reply to Daniel Henrique Barboza

'out' label in v9fs_xattr_write() and 'out_nofid' label in v9fs_complete_rename() can be replaced by appropriate return calls.

---
 hw/9pfs/9p.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
hw/9pfs/9p.c +3 -6
index 520177f40c..be2beba4cd 100644
@@ -2464,8 +2464,7 @@ static int v9fs_xattr_write(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
 
 
     if (fidp->fs.xattr.len < off) {
-        err = -ENOSPC;
-        goto out;
+        return -ENOSPC;
     }
     write_count = fidp->fs.xattr.len - off;
     if (write_count > count) {
@@ -2491,7 +2490,7 @@ static int v9fs_xattr_write(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
         off += to_copy;
         write_count -= to_copy;
     }
-out:
+
     return err;
 }
 
@@ -3056,8 +3055,7 @@ static int coroutine_fn v9fs_complete_rename(V9fsPDU *pdu, V9fsFidState *fidp,
     if (newdirfid != -1) {
         dirfidp = get_fid(pdu, newdirfid);
         if (dirfidp == NULL) {
-            err = -ENOENT;
-            goto out_nofid;
+            return -ENOENT;
         }
         if (fidp->fid_type != P9_FID_NONE) {
             err = -EINVAL;
@@ -3100,7 +3098,6 @@ out:
         put_fid(pdu, dirfidp);
     }
     v9fs_path_free(&new_path);
-out_nofid:
     return err;
 }
 
Signature · 1 line
2.24.1
#42 lore raw

PATCH 22/59 block/vmdk.c: remove unneeded labels

In reply to Daniel Henrique Barboza

'exit' label from vmdk_open_desc_file() can be replaced by 'return' calls with the appropriate value. Same thing with the 'out' label from vmdk_co_create().

---
 block/vmdk.c | 37 +++++++++++++------------------------
 1 file changed, 13 insertions(+), 24 deletions(-)
block/vmdk.c +13 -24
index 20e909d997..d1491486de 100644
@@ -1222,14 +1222,12 @@ out:
 static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf,
                                QDict *options, Error **errp)
 {
-    int ret;
     char ct[128];
     BDRVVmdkState *s = bs->opaque;
 
     if (vmdk_parse_description(buf, "createType", ct, sizeof(ct))) {
         error_setg(errp, "invalid VMDK image descriptor");
-        ret = -EINVAL;
-        goto exit;
+        return -EINVAL;
     }
     if (strcmp(ct, "monolithicFlat") &&
         strcmp(ct, "vmfs") &&
@@ -1238,14 +1236,11 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf,
         strcmp(ct, "twoGbMaxExtentSparse") &&
         strcmp(ct, "twoGbMaxExtentFlat")) {
         error_setg(errp, "Unsupported image type '%s'", ct);
-        ret = -ENOTSUP;
-        goto exit;
+        return -ENOTSUP;
     }
     s->create_type = g_strdup(ct);
     s->desc_offset = 0;
-    ret = vmdk_parse_extents(buf, bs, options, errp);
-exit:
-    return ret;
+    return vmdk_parse_extents(buf, bs, options, errp);
 }
 
 static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
@@ -2738,7 +2733,6 @@ static BlockBackend *vmdk_co_create_cb(int64_t size, int idx,
 static int coroutine_fn vmdk_co_create(BlockdevCreateOptions *create_options,
                                        Error **errp)
 {
-    int ret;
     BlockdevCreateOptionsVmdk *opts;
 
     opts = &create_options->u.vmdk;
@@ -2746,23 +2740,18 @@ static int coroutine_fn vmdk_co_create(BlockdevCreateOptions *create_options,
     /* Validate options */
     if (!QEMU_IS_ALIGNED(opts->size, BDRV_SECTOR_SIZE)) {
         error_setg(errp, "Image size must be a multiple of 512 bytes");
-        ret = -EINVAL;
-        goto out;
+        return -EINVAL;
     }
 
-    ret = vmdk_co_do_create(opts->size,
-                            opts->subformat,
-                            opts->adapter_type,
-                            opts->backing_file,
-                            opts->hwversion,
-                            false,
-                            opts->zeroed_grain,
-                            vmdk_co_create_cb,
-                            opts, errp);
-    return ret;
-
-out:
-    return ret;
+    return vmdk_co_do_create(opts->size,
+                             opts->subformat,
+                             opts->adapter_type,
+                             opts->backing_file,
+                             opts->hwversion,
+                             false,
+                             opts->zeroed_grain,
+                             vmdk_co_create_cb,
+                             opts, errp);
 }
 
 static void vmdk_close(BlockDriverState *bs)
Signature · 1 line
2.24.1
#85 lore raw

PATCH 46/59 alpha/typhoon.c: remove unneeded label in typhoon_translate_iommu()

In reply to Daniel Henrique Barboza

Label 'success' can be replaced by 'return ret'.

As a bonus, existing trailing whitespaces were automatically deleted by the text editor while making this patch.

---
 hw/alpha/typhoon.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
hw/alpha/typhoon.c +8 -10
index 179e1f7658..af992883c7 100644
@@ -34,7 +34,7 @@ typedef struct TyphoonWindow {
     uint64_t wsm;
     uint64_t tba;
 } TyphoonWindow;
- 
+
 typedef struct TyphoonPchip {
     MemoryRegion region;
     MemoryRegion reg_iack;
@@ -190,7 +190,7 @@ static MemTxResult cchip_read(void *opaque, hwaddr addr,
     case 0x0780:
         /* PWR: Power Management Control.   */
         break;
-    
+
     case 0x0c00: /* CMONCTLA */
     case 0x0c40: /* CMONCTLB */
     case 0x0c80: /* CMONCNT01 */
@@ -442,7 +442,7 @@ static MemTxResult cchip_write(void *opaque, hwaddr addr,
     case 0x0780:
         /* PWR: Power Management Control.   */
         break;
-    
+
     case 0x0c00: /* CMONCTLA */
     case 0x0c40: /* CMONCTLB */
     case 0x0c80: /* CMONCNT01 */
@@ -694,14 +694,14 @@ static IOMMUTLBEntry typhoon_translate_iommu(IOMMUMemoryRegion *iommu,
         /* Check the first three windows.  */
         for (i = 0; i < 3; ++i) {
             if (window_translate(&pchip->win[i], addr, &ret)) {
-                goto success;
+                return ret;
             }
         }
 
         /* Check the fourth window for DAC disable.  */
         if ((pchip->win[3].wba & 0x80000000000ull) == 0
             && window_translate(&pchip->win[3], addr, &ret)) {
-            goto success;
+            return ret;
         }
     } else {
         /* Double-address cycle.  */
@@ -711,7 +711,7 @@ static IOMMUTLBEntry typhoon_translate_iommu(IOMMUMemoryRegion *iommu,
             if (pchip->ctl & 0x40) {
                 /* See 10.1.4.4; in particular <39:35> is ignored.  */
                 make_iommu_tlbe(0, 0x007ffffffffull, &ret);
-                goto success;
+                return ret;
             }
         }
 
@@ -723,16 +723,14 @@ static IOMMUTLBEntry typhoon_translate_iommu(IOMMUMemoryRegion *iommu,
                 pte_addr  = pchip->win[3].tba & 0x7ffc00000ull;
                 pte_addr |= (addr & 0xffffe000u) >> 10;
                 if (pte_translate(pte_addr, &ret)) {
-                        goto success;
+                    return ret;
                 }
             }
         }
     }
 
  failure:
-    ret = (IOMMUTLBEntry) { .perm = IOMMU_NONE };
- success:
-    return ret;
+    return (IOMMUTLBEntry) { .perm = IOMMU_NONE };
 }
 
 static AddressSpace *typhoon_pci_dma_iommu(PCIBus *bus, void *opaque, int devfn)
Signature · 1 line
2.24.1
#92 lore raw

PATCH 53/59 net/net_tx_pkt.c: remove unneeded label in net_tx_pkt_get_gso_type()

In reply to Daniel Henrique Barboza

'func_exit' can be replaced by 'return' with the appropriate return value. 'rc' also becomes unnecessary after this change, thus let's remove it as well.

---
 hw/net/net_tx_pkt.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
hw/net/net_tx_pkt.c +4 -7
index 162f802dd7..3cd6aa1d0e 100644
@@ -287,21 +287,18 @@ struct virtio_net_hdr *net_tx_pkt_get_vhdr(struct NetTxPkt *pkt)
 static uint8_t net_tx_pkt_get_gso_type(struct NetTxPkt *pkt,
                                           bool tso_enable)
 {
-    uint8_t rc = VIRTIO_NET_HDR_GSO_NONE;
     uint16_t l3_proto;
 
     l3_proto = eth_get_l3_proto(&pkt->vec[NET_TX_PKT_L2HDR_FRAG], 1,
         pkt->vec[NET_TX_PKT_L2HDR_FRAG].iov_len);
 
     if (!tso_enable) {
-        goto func_exit;
+        return VIRTIO_NET_HDR_GSO_NONE;
     }
 
-    rc = eth_get_gso_type(l3_proto, pkt->vec[NET_TX_PKT_L3HDR_FRAG].iov_base,
-                          pkt->l4proto);
-
-func_exit:
-    return rc;
+    return eth_get_gso_type(l3_proto,
+                            pkt->vec[NET_TX_PKT_L3HDR_FRAG].iov_base,
+                            pkt->l4proto);
 }
 
 void net_tx_pkt_build_vheader(struct NetTxPkt *pkt, bool tso_enable,
Signature · 1 line
2.24.1
Reviewed-by on v1 10/59
#20 lore raw

Re: [PATCH v1 10/59] chardev/char-win.c: remove 'fail' label in win_chr_serial_init()

In reply to Daniel Henrique Barboza
Quoted 7 lines · Daniel Henrique Barboza

The 'fail' label is a simply call to 'return -1' on error. Remove it and do the return call instead.

CC Marc-André Lureau <[email protected]>
CC Paolo Bonzini <[email protected]>
Quoted 75 lines
---
 chardev/char-win.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
chardev/char-win.c +8 -12
index 34825f683d..72c232e6d9 100644
@@ -85,12 +85,12 @@ int win_chr_serial_init(Chardev *chr, const char *filename, Error **errp)
     s->hsend = CreateEvent(NULL, TRUE, FALSE, NULL);
     if (!s->hsend) {
         error_setg(errp, "Failed CreateEvent");
-        goto fail;
+        return -1;
     }
     s->hrecv = CreateEvent(NULL, TRUE, FALSE, NULL);
     if (!s->hrecv) {
         error_setg(errp, "Failed CreateEvent");
-        goto fail;
+        return -1;
     }
 
     s->file = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
@@ -98,12 +98,12 @@ int win_chr_serial_init(Chardev *chr, const char *filename, Error **errp)
     if (s->file == INVALID_HANDLE_VALUE) {
         error_setg(errp, "Failed CreateFile (%lu)", GetLastError());
         s->file = NULL;
-        goto fail;
+        return -1;
     }
 
     if (!SetupComm(s->file, NRECVBUF, NSENDBUF)) {
         error_setg(errp, "Failed SetupComm");
-        goto fail;
+        return -1;
     }
 
     ZeroMemory(&comcfg, sizeof(COMMCONFIG));
@@ -114,29 +114,26 @@ int win_chr_serial_init(Chardev *chr, const char *filename, Error **errp)
 
     if (!SetCommState(s->file, &comcfg.dcb)) {
         error_setg(errp, "Failed SetCommState");
-        goto fail;
+        return -1;
     }
 
     if (!SetCommMask(s->file, EV_ERR)) {
         error_setg(errp, "Failed SetCommMask");
-        goto fail;
+        return -1;
     }
 
     cto.ReadIntervalTimeout = MAXDWORD;
     if (!SetCommTimeouts(s->file, &cto)) {
         error_setg(errp, "Failed SetCommTimeouts");
-        goto fail;
+        return -1;
     }
 
     if (!ClearCommError(s->file, &err, &comstat)) {
         error_setg(errp, "Failed ClearCommError");
-        goto fail;
+        return -1;
     }
     qemu_add_polling_cb(win_chr_serial_poll, chr);
     return 0;
-
- fail:
-    return -1;
 }
 
 int win_chr_pipe_poll(void *opaque)
--

2.24.1

#86 lore raw

PATCH 47/59 pvrdma_main.c: remove unneeded labels

In reply to Daniel Henrique Barboza

Label 'out' from init_dev_ring() and load_dsr() can be replaced by 'return' with the adequate value.

---
 hw/rdma/vmw/pvrdma_main.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
hw/rdma/vmw/pvrdma_main.c +3 -7
index 6f0fc405c7..fcaf829e30 100644
@@ -94,8 +94,7 @@ static int init_dev_ring(PvrdmaRing *ring, struct pvrdma_ring **ring_state,
     dir = rdma_pci_dma_map(pci_dev, dir_addr, TARGET_PAGE_SIZE);
     if (!dir) {
         rdma_error_report("Failed to map to page directory (ring %s)", name);
-        rc = -ENOMEM;
-        goto out;
+        return -ENOMEM;
     }
     tbl = rdma_pci_dma_map(pci_dev, dir[0], TARGET_PAGE_SIZE);
     if (!tbl) {
@@ -134,7 +133,6 @@ out_free_tbl:
 out_free_dir:
     rdma_pci_dma_unmap(pci_dev, dir, TARGET_PAGE_SIZE);
 
-out:
     return rc;
 }
 
@@ -177,8 +175,7 @@ static int load_dsr(PVRDMADev *dev)
                               sizeof(struct pvrdma_device_shared_region));
     if (!dev->dsr_info.dsr) {
         rdma_error_report("Failed to map to DSR");
-        rc = -ENOMEM;
-        goto out;
+        return -ENOMEM;
     }
 
     /* Shortcuts */
@@ -221,7 +218,7 @@ static int load_dsr(PVRDMADev *dev)
         goto out_free_rsp;
     }
 
-    goto out;
+    return rc;
 
 out_free_rsp:
     rdma_pci_dma_unmap(pci_dev, dsr_info->rsp, sizeof(union pvrdma_cmd_resp));
@@ -234,7 +231,6 @@ out_free_dsr:
                        sizeof(struct pvrdma_device_shared_region));
     dsr_info->dsr = NULL;
 
-out:
     return rc;
 }
 
Signature · 1 line
2.24.1
Reviewed-by on v1 9/59
#18 lore raw

Re: [PATCH v1 09/59] chardev/char-pipe.c: remove 'fail' label in win_chr_pipe_init()

In reply to Daniel Henrique Barboza
Quoted 6 lines · Daniel Henrique Barboza

The 'fail' label is simply doing a 'return -1'.

CC Marc-André Lureau <[email protected]>
CC Paolo Bonzini <[email protected]>
Quoted 63 lines
---
 chardev/char-pipe.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
chardev/char-pipe.c +5 -9
index 94d714ffcd..65d52beb0d 100644
@@ -54,12 +54,12 @@ static int win_chr_pipe_init(Chardev *chr, const char *filename,
     s->hsend = CreateEvent(NULL, TRUE, FALSE, NULL);
     if (!s->hsend) {
         error_setg(errp, "Failed CreateEvent");
-        goto fail;
+        return -1;
     }
     s->hrecv = CreateEvent(NULL, TRUE, FALSE, NULL);
     if (!s->hrecv) {
         error_setg(errp, "Failed CreateEvent");
-        goto fail;
+        return -1;
     }
 
     openname = g_strdup_printf("\\\\.\\pipe\\%s", filename);
@@ -72,7 +72,7 @@ static int win_chr_pipe_init(Chardev *chr, const char *filename,
     if (s->file == INVALID_HANDLE_VALUE) {
         error_setg(errp, "Failed CreateNamedPipe (%lu)", GetLastError());
         s->file = NULL;
-        goto fail;
+        return -1;
     }
 
     ZeroMemory(&ov, sizeof(ov));
@@ -80,7 +80,7 @@ static int win_chr_pipe_init(Chardev *chr, const char *filename,
     ret = ConnectNamedPipe(s->file, &ov);
     if (ret) {
         error_setg(errp, "Failed ConnectNamedPipe");
-        goto fail;
+        return -1;
     }
 
     ret = GetOverlappedResult(s->file, &ov, &size, TRUE);
@@ -90,7 +90,7 @@ static int win_chr_pipe_init(Chardev *chr, const char *filename,
             CloseHandle(ov.hEvent);
             ov.hEvent = NULL;
         }
-        goto fail;
+        return -1;
     }
 
     if (ov.hEvent) {
@@ -99,9 +99,6 @@ static int win_chr_pipe_init(Chardev *chr, const char *filename,
     }
     qemu_add_polling_cb(win_chr_pipe_poll, chr);
     return 0;
-
- fail:
-    return -1;
 }
 
 static void qemu_chr_open_pipe(Chardev *chr,
--

2.24.1

Reviewed-by on v1 8/59
#16 lore raw

Re: [PATCH v1 08/59] chardev/char-mux.c: remove 'send_char' label

In reply to Daniel Henrique Barboza
Quoted 4 lines · Daniel Henrique Barboza
CC Marc-André Lureau <[email protected]>
CC Paolo Bonzini <[email protected]>
Quoted 28 lines
---
 chardev/char-mux.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
chardev/char-mux.c +1 -3
index 200c62a0d0..edbaaf5cbf 100644
@@ -140,7 +140,7 @@ static int mux_proc_byte(Chardev *chr, MuxChardev *d, int ch)
     if (d->term_got_escape) {
         d->term_got_escape = 0;
         if (ch == term_escape_char) {
-            goto send_char;
+            return 1;
         }
         switch (ch) {
         case '?':
@@ -174,7 +174,6 @@ static int mux_proc_byte(Chardev *chr, MuxChardev *d, int ch)
     } else if (ch == term_escape_char) {
         d->term_got_escape = 1;
     } else {
-    send_char:
         return 1;
     }
     return 0;
--

2.24.1

#94 lore raw

PATCH 55/59 linux-user/flatload.c: remove unused 'out' label

In reply to Daniel Henrique Barboza

'out' label in out_free_buf() is not used at all.

---
 linux-user/flatload.c | 1 -
 1 file changed, 1 deletion(-)
linux-user/flatload.c +0 -1
index 0122ab3afe..3945c40ee1 100644
@@ -247,7 +247,6 @@ out_free_buf:
 	kfree(buf);
 out_free:
 	kfree(strm.workspace);
-out:
 	return retval;
 }
 
Signature · 1 line
2.24.1
#45 lore raw

PATCH 25/59 block/vhdx.c: remove unneeded 'exit' labels

In reply to Daniel Henrique Barboza

'exit' label of vhdx_region_check() and vhdx_update_header() can be replaced by 'return' statements.

---
 block/vhdx.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
block/vhdx.c +3 -7
index f02d2611be..7a1ea312ed 100644
@@ -229,7 +229,6 @@ void vhdx_guid_generate(MSGUID *guid)
 /* Check for region overlaps inside the VHDX image */
 static int vhdx_region_check(BDRVVHDXState *s, uint64_t start, uint64_t length)
 {
-    int ret = 0;
     uint64_t end;
     VHDXRegionEntry *r;
 
@@ -239,13 +238,11 @@ static int vhdx_region_check(BDRVVHDXState *s, uint64_t start, uint64_t length)
             error_report("VHDX region %" PRIu64 "-%" PRIu64 " overlaps with "
                          "region %" PRIu64 "-%." PRIu64, start, end, r->start,
                          r->end);
-            ret = -EINVAL;
-            goto exit;
+            return -EINVAL;
         }
     }
 
-exit:
-    return ret;
+    return 0;
 }
 
 /* Register a region for future checks */
@@ -390,11 +387,10 @@ static int vhdx_update_header(BlockDriverState *bs, BDRVVHDXState *s,
 
     ret = vhdx_write_header(bs->file, inactive_header, header_offset, true);
     if (ret < 0) {
-        goto exit;
+        return ret;
     }
     s->curr_header = hdr_idx;
 
-exit:
     return ret;
 }
 
Signature · 1 line
2.24.1
#93 lore raw

PATCH 54/59 ivshmem-server/main.c: remove unneeded label in main()

In reply to Daniel Henrique Barboza

'err' can be replaced by 'return 1'.

---
 contrib/ivshmem-server/main.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
contrib/ivshmem-server/main.c +4 -5
index e4cd35f74c..b491e8237f 100644
@@ -217,7 +217,7 @@ main(int argc, char *argv[])
     if (sigemptyset(&sa.sa_mask) == -1 ||
         sigaction(SIGPIPE, &sa, 0) == -1) {
         perror("failed to ignore SIGPIPE; sigaction");
-        goto err;
+        return 1;
     }
 
     sa_quit.sa_handler = ivshmem_server_quit_cb;
@@ -226,7 +226,7 @@ main(int argc, char *argv[])
         sigaction(SIGTERM, &sa_quit, 0) == -1 ||
         sigaction(SIGINT, &sa_quit, 0) == -1) {
         perror("failed to add signal handler; sigaction");
-        goto err;
+        return 1;
     }
 
     /* init the ivshms structure */
@@ -234,13 +234,13 @@ main(int argc, char *argv[])
                             args.shm_path, args.use_shm_open,
                             args.shm_size, args.n_vectors, args.verbose) < 0) {
         fprintf(stderr, "cannot init server\n");
-        goto err;
+        return 1;
     }
 
     /* start the ivshmem server (open shm & unix socket) */
     if (ivshmem_server_start(&server) < 0) {
         fprintf(stderr, "cannot bind\n");
-        goto err;
+        return 1;
     }
 
     /* daemonize if asked to */
@@ -269,6 +269,5 @@ main(int argc, char *argv[])
 
 err_close:
     ivshmem_server_close(&server);
-err:
     return ret;
 }
Signature · 1 line
2.24.1
#99 lore raw

PATCH 58/59 linux-user/syscall.c: remove unneeded labels

In reply to Daniel Henrique Barboza

'out2' label in do_sendrecvmsg_locked() can be replaced by 'return' with the adequate exit value. Same thing with the label 'out' in do_ioctl_blkpg(), and in that function we can get rid of the 'ret' variable as well.

---
 linux-user/syscall.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
linux-user/syscall.c +7 -17
index 49c6151c2d..5db066921e 100644
@@ -2941,7 +2941,7 @@ static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp,
              */
             msg.msg_name = (void *)-1;
         } else if (ret) {
-            goto out2;
+            return ret;
         }
     } else {
         msg.msg_name = NULL;
@@ -2960,15 +2960,13 @@ static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp,
         /* sendrcvmsg returns a different errno for this condition than
          * readv/writev, so we must catch it here before lock_iovec() does.
          */
-        ret = -TARGET_EMSGSIZE;
-        goto out2;
+        return -TARGET_EMSGSIZE;
     }
 
     vec = lock_iovec(send ? VERIFY_READ : VERIFY_WRITE,
                      target_vec, count, send);
     if (vec == NULL) {
-        ret = -host_to_target_errno(errno);
-        goto out2;
+        return -host_to_target_errno(errno);
     }
     msg.msg_iovlen = count;
     msg.msg_iov = vec;
@@ -3020,7 +3018,6 @@ static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp,
 
 out:
     unlock_iovec(vec, target_vec, count, !send);
-out2:
     return ret;
 }
 
@@ -4952,7 +4949,6 @@ static abi_long do_ioctl_blkpg(const IOCTLEntry *ie, uint8_t *buf_temp, int fd,
     int target_size;
     const argtype *arg_type = ie->arg_type;
     const argtype part_arg_type[] = { MK_STRUCT(STRUCT_blkpg_partition) };
-    abi_long ret;
 
     struct blkpg_ioctl_arg *host_blkpg = (void*)buf_temp;
     struct blkpg_partition host_part;
@@ -4962,8 +4958,7 @@ static abi_long do_ioctl_blkpg(const IOCTLEntry *ie, uint8_t *buf_temp, int fd,
     target_size = thunk_type_size(arg_type, 0);
     argptr = lock_user(VERIFY_READ, arg, target_size, 1);
     if (!argptr) {
-        ret = -TARGET_EFAULT;
-        goto out;
+        return -TARGET_EFAULT;
     }
     thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST);
     unlock_user(argptr, arg, 0);
@@ -4975,8 +4970,7 @@ static abi_long do_ioctl_blkpg(const IOCTLEntry *ie, uint8_t *buf_temp, int fd,
         break;
     default:
         /* Unknown opcode */
-        ret = -TARGET_EINVAL;
-        goto out;
+        return -TARGET_EINVAL;
     }
 
     /* Read and convert blkpg->data */
@@ -4984,18 +4978,14 @@ static abi_long do_ioctl_blkpg(const IOCTLEntry *ie, uint8_t *buf_temp, int fd,
     target_size = thunk_type_size(part_arg_type, 0);
     argptr = lock_user(VERIFY_READ, arg, target_size, 1);
     if (!argptr) {
-        ret = -TARGET_EFAULT;
-        goto out;
+        return -TARGET_EFAULT;
     }
     thunk_convert(&host_part, argptr, part_arg_type, THUNK_HOST);
     unlock_user(argptr, arg, 0);
 
     /* Swizzle the data pointer to our local copy and call! */
     host_blkpg->data = &host_part;
-    ret = get_errno(safe_ioctl(fd, ie->host_cmd, host_blkpg));
-
-out:
-    return ret;
+    return get_errno(safe_ioctl(fd, ie->host_cmd, host_blkpg));
 }
 
 static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp,
Signature · 1 line
2.24.1
#48 lore raw

PATCH 28/59 qga/commands-win32.c: remove 'out' label in get_pci_info

In reply to Daniel Henrique Barboza

'out' can be replaced by 'return pci' instead.

---
 qga/commands-win32.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
qga/commands-win32.c +8 -9
index 2461fd19bf..c520a341df 100644
@@ -513,7 +513,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp)
                                    DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
     if (dev_info == INVALID_HANDLE_VALUE) {
         error_setg_win32(errp, GetLastError(), "failed to get devices tree");
-        goto out;
+        return pci;
     }
 
     g_debug("enumerating devices");
@@ -584,7 +584,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp)
                 } else {
                     error_setg_win32(errp, GetLastError(),
                                      "failed to get device instance ID");
-                    goto out;
+                    return pci;
                 }
             }
 
@@ -598,14 +598,14 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp)
                 g_error("CM_Locate_DevInst failed with code %lx", cr);
                 error_setg_win32(errp, GetLastError(),
                                  "failed to get device instance");
-                goto out;
+                return pci;
             }
             cr = CM_Get_Parent(&parent_dev_inst, dev_inst, 0);
             if (cr != CR_SUCCESS) {
                 g_error("CM_Get_Parent failed with code %lx", cr);
                 error_setg_win32(errp, GetLastError(),
                                  "failed to get parent device instance");
-                goto out;
+                return pci;
             }
 
             cr = CM_Get_Device_ID_Size(&dev_id_size, parent_dev_inst, 0);
@@ -613,7 +613,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp)
                 g_error("CM_Get_Device_ID_Size failed with code %lx", cr);
                 error_setg_win32(errp, GetLastError(),
                                  "failed to get parent device ID length");
-                goto out;
+                return pci;
             }
 
             ++dev_id_size;
@@ -628,7 +628,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp)
                 g_error("CM_Get_Device_ID failed with code %lx", cr);
                 error_setg_win32(errp, GetLastError(),
                                  "failed to get parent device ID");
-                goto out;
+                return pci;
             }
         }
 
@@ -642,14 +642,14 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp)
         if (parent_dev_info == INVALID_HANDLE_VALUE) {
             error_setg_win32(errp, GetLastError(),
                              "failed to get parent device");
-            goto out;
+            return pci;
         }
 
         parent_dev_info_data.cbSize = sizeof(SP_DEVINFO_DATA);
         if (!SetupDiEnumDeviceInfo(parent_dev_info, 0, &parent_dev_info_data)) {
             error_setg_win32(errp, GetLastError(),
                            "failed to get parent device data");
-            goto out;
+            return pci;
         }
 
         for (j = 0;
@@ -731,7 +731,6 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp)
 
 free_dev_info:
     SetupDiDestroyDeviceInfoList(dev_info);
-out:
     return pci;
 }
 
Signature · 1 line
2.24.1
#56 lore raw

PATCH 32/59 qemu-img.c: remove 'out4' label in img_compare

In reply to Daniel Henrique Barboza

'out4' can be replaced by 'return 2'.

---
 qemu-img.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
qemu-img.c +2 -5
index 6233b8ca56..fc7b08e7ee 100644
@@ -1346,8 +1346,7 @@ static int img_compare(int argc, char **argv)
             opts = qemu_opts_parse_noisily(&qemu_object_opts,
                                            optarg, true);
             if (!opts) {
-                ret = 2;
-                goto out4;
+                return 2;
             }
         }   break;
         case OPTION_IMAGE_OPTS:
@@ -1371,8 +1370,7 @@ static int img_compare(int argc, char **argv)
     if (qemu_opts_foreach(&qemu_object_opts,
                           user_creatable_add_opts_foreach,
                           qemu_img_object_print_help, &error_fatal)) {
-        ret = 2;
-        goto out4;
+        return 2;
     }
 
     /* Initialize before goto out */
@@ -1559,7 +1557,6 @@ out2:
     blk_unref(blk1);
 out3:
     qemu_progress_end();
-out4:
     return ret;
 }
 
Signature · 1 line
2.24.1
#59 lore raw

PATCH 35/59 ipmi_bmc_extern.c: remove unneeded label in ipmi_bmc_extern_handle_command

In reply to Daniel Henrique Barboza

'out' label can be replaced by 'return'.

---
 hw/ipmi/ipmi_bmc_extern.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
hw/ipmi/ipmi_bmc_extern.c +1 -4
index 87da9ff99c..16d9114725 100644
@@ -217,7 +217,7 @@ static void ipmi_bmc_extern_handle_command(IPMIBmc *b,
         rsp[2] = err;
         ibe->waiting_rsp = false;
         k->handle_rsp(s, msg_id, rsp, 3);
-        goto out;
+        return;
     }
 
     addchar(ibe, msg_id);
@@ -232,9 +232,6 @@ static void ipmi_bmc_extern_handle_command(IPMIBmc *b,
 
     /* Start the transmit */
     continue_send(ibe);
-
- out:
-    return;
 }
 
 static void handle_hw_op(IPMIBmcExtern *ibe, unsigned char hw_op)
Signature · 1 line
2.24.1
#76 lore raw

PATCH 43/59 i386/amd_iommu.c: remove unneeded label in amdvi_int_remap_msi()

In reply to Daniel Henrique Barboza

'remap_fail' label can be replaced by 'return' with the adequate error value.

CC Michael S. Tsirkin <[email protected]>
CC Marcel Apfelbaum <[email protected]>
---
 hw/i386/amd_iommu.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
hw/i386/amd_iommu.c +4 -9
index b1175e52c7..711e1f6e40 100644
@@ -1268,7 +1268,7 @@ static int amdvi_int_remap_msi(AMDVIState *iommu,
         trace_amdvi_ir_delivery_mode("fixed/arbitrated");
         ret = __amdvi_int_remap_msi(iommu, origin, translated, dte, &irq, sid);
         if (ret < 0) {
-            goto remap_fail;
+            return ret;
         } else {
             /* Translate IRQ to MSI messages */
             x86_iommu_irq_to_msi_message(&irq, translated);
@@ -1298,7 +1298,7 @@ static int amdvi_int_remap_msi(AMDVIState *iommu,
     }
 
     if (ret < 0) {
-        goto remap_fail;
+        return ret;
     }
 
     /*
@@ -1309,25 +1309,20 @@ static int amdvi_int_remap_msi(AMDVIState *iommu,
     dest_mode = (origin->address >> MSI_ADDR_DEST_MODE_SHIFT) & 1;
     if (dest_mode) {
         trace_amdvi_ir_err("invalid dest_mode");
-        ret = -AMDVI_IR_ERR;
-        goto remap_fail;
+        return -AMDVI_IR_ERR;
     }
 
     if (pass) {
         memcpy(translated, origin, sizeof(*origin));
     } else {
         trace_amdvi_ir_err("passthrough is not enabled");
-        ret = -AMDVI_IR_ERR;
-        goto remap_fail;
+        return -AMDVI_IR_ERR;
     }
 
 out:
     trace_amdvi_ir_remap_msi(origin->address, origin->data,
                              translated->address, translated->data);
     return 0;
-
-remap_fail:
-    return ret;
 }
 
 static int amdvi_int_remap(X86IOMMUState *iommu,
Signature · 1 line
2.24.1
#77 lore raw

PATCH 44/59 9p-local.c: remove unneeded label in local_unlinkat_common()

In reply to Daniel Henrique Barboza

'err_out' can be replaced by 'return ret' in the error conditions the jump was being made.

---
 hw/9pfs/9p-local.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
hw/9pfs/9p-local.c +5 -7
index ca641390fb..f9bdd2ad7c 100644
@@ -1094,12 +1094,12 @@ static int local_unlinkat_common(FsContext *ctx, int dirfd, const char *name,
 
             fd = openat_dir(dirfd, name);
             if (fd == -1) {
-                goto err_out;
+                return ret;
             }
             ret = unlinkat(fd, VIRTFS_META_DIR, AT_REMOVEDIR);
             close_preserve_errno(fd);
             if (ret < 0 && errno != ENOENT) {
-                goto err_out;
+                return ret;
             }
         }
         map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR);
@@ -1107,16 +1107,14 @@ static int local_unlinkat_common(FsContext *ctx, int dirfd, const char *name,
             ret = unlinkat(map_dirfd, name, 0);
             close_preserve_errno(map_dirfd);
             if (ret < 0 && errno != ENOENT) {
-                goto err_out;
+                return ret;
             }
         } else if (errno != ENOENT) {
-            goto err_out;
+            return ret;
         }
     }
 
-    ret = unlinkat(dirfd, name, flags);
-err_out:
-    return ret;
+    return unlinkat(dirfd, name, flags);
 }
 
 static int local_remove(FsContext *ctx, const char *path)
Signature · 1 line
2.24.1
#88 lore raw

PATCH 49/59 rdma/rdma_rm.c: remove unneeded label in rdma_rm_alloc_pd()

In reply to Daniel Henrique Barboza

'out' label can be replaced by 'return ret'. Since 'ret' will be set to -ENOMEM in 'goto' time, we can replace it to 'return -ENOMEM'.

After this change, the 'ret' var is used to store the result of rdma_backend_create_pd(), see if it's not zero, then 'ret' is set to -EIO before the jump to out_tbl_dealloc. -EIO is the only error being thrown by out_tbl_dealloc too. This means we can go a step further in the code simplification by also removing the 'ret' variable and making out_tbl_dealloc return -EIO directly.

---
 hw/rdma/rdma_rm.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
hw/rdma/rdma_rm.c +3 -8
index 1524dfaeaa..f049fda38a 100644
@@ -161,16 +161,13 @@ int rdma_rm_alloc_pd(RdmaDeviceResources *dev_res, RdmaBackendDev *backend_dev,
                      uint32_t *pd_handle, uint32_t ctx_handle)
 {
     RdmaRmPD *pd;
-    int ret = -ENOMEM;
 
     pd = rdma_res_tbl_alloc(&dev_res->pd_tbl, pd_handle);
     if (!pd) {
-        goto out;
+        return -ENOMEM;
     }
 
-    ret = rdma_backend_create_pd(backend_dev, &pd->backend_pd);
-    if (ret) {
-        ret = -EIO;
+    if (rdma_backend_create_pd(backend_dev, &pd->backend_pd)) {
         goto out_tbl_dealloc;
     }
 
@@ -180,9 +177,7 @@ int rdma_rm_alloc_pd(RdmaDeviceResources *dev_res, RdmaBackendDev *backend_dev,
 
 out_tbl_dealloc:
     rdma_res_tbl_dealloc(&dev_res->pd_tbl, *pd_handle);
-
-out:
-    return ret;
+    return -EIO;
 }
 
 RdmaRmPD *rdma_rm_get_pd(RdmaDeviceResources *dev_res, uint32_t pd_handle)
Signature · 1 line
2.24.1
#95 lore raw

PATCH 56/59 linux-user/signal.c: remove unneeded label in do_sigaltstack()

In reply to Daniel Henrique Barboza

'out' can be replaced by 'return ret'. Since 'ret' is used just to set the return value, drop the 'ret' variable and use 'return' with the appropriate value instead.

---
 linux-user/signal.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)
linux-user/signal.c +6 -14
index 5ca6d62b15..5efb1b79d9 100644
@@ -708,7 +708,6 @@ static void host_signal_handler(int host_signum, siginfo_t *info,
 /* compare linux/kernel/signal.c:do_sigaltstack() */
 abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp)
 {
-    int ret;
     struct target_sigaltstack oss;
     TaskState *ts = (TaskState *)thread_cpu->opaque;
 
@@ -734,32 +733,28 @@ abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp)
         }
 #endif
 
-        ret = -TARGET_EFAULT;
         if (!lock_user_struct(VERIFY_READ, uss, uss_addr, 1)) {
-            goto out;
+            return -TARGET_EFAULT;
         }
         __get_user(ss.ss_sp, &uss->ss_sp);
         __get_user(ss.ss_size, &uss->ss_size);
         __get_user(ss.ss_flags, &uss->ss_flags);
         unlock_user_struct(uss, uss_addr, 0);
 
-        ret = -TARGET_EPERM;
         if (on_sig_stack(sp))
-            goto out;
+            return -TARGET_EPERM;
 
-        ret = -TARGET_EINVAL;
         if (ss.ss_flags != TARGET_SS_DISABLE
             && ss.ss_flags != TARGET_SS_ONSTACK
             && ss.ss_flags != 0)
-            goto out;
+            return -TARGET_EINVAL;
 
         if (ss.ss_flags == TARGET_SS_DISABLE) {
             ss.ss_size = 0;
             ss.ss_sp = 0;
         } else {
-            ret = -TARGET_ENOMEM;
             if (ss.ss_size < minstacksize) {
-                goto out;
+                return -TARGET_ENOMEM;
             }
         }
 
@@ -768,14 +763,11 @@ abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp)
     }
 
     if (uoss_addr) {
-        ret = -TARGET_EFAULT;
         if (copy_to_user(uoss_addr, &oss, sizeof(oss)))
-            goto out;
+            return -TARGET_EFAULT;
     }
 
-    ret = 0;
-out:
-    return ret;
+    return 0;
 }
 
 /* do_sigaction() return target values and host errnos */
Signature · 1 line
2.24.1
#96 lore raw

PATCH 57/59 linux-user/syscall.c: fix trailing whitespaces and style

In reply to Daniel Henrique Barboza

There are trailing whitespaces in this file that, if removed by a text editor that refuses to let the traiing whitespace alone, which happens to be the editor I am using, will cause checkpatch.pl to warn about styling problems in the resulting patch. This happens because the trailing whitespace lines are using a deprecated style.

To keep the intended change I wanted to do (remove unneeded labels in do_ioctl_blkpg() and do_sendrecvmsg_locked()) trivial, this patch is another trivial change to fix the trailing whitespaces and the code style errors that checkpatch.pl warns about. Doing this change beforehand will keep the next patch focused just on the label removal changes.

---
 linux-user/syscall.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)
linux-user/syscall.c +17 -13
index 171c0caef3..49c6151c2d 100644
@@ -1062,7 +1062,7 @@ static inline rlim_t target_to_host_rlim(abi_ulong target_rlim)
 {
     abi_ulong target_rlim_swap;
     rlim_t result;
-    
+
     target_rlim_swap = tswapal(target_rlim);
     if (target_rlim_swap == TARGET_RLIM_INFINITY)
         return RLIM_INFINITY;
@@ -1070,7 +1070,7 @@ static inline rlim_t target_to_host_rlim(abi_ulong target_rlim)
     result = target_rlim_swap;
     if (target_rlim_swap != (rlim_t)result)
         return RLIM_INFINITY;
-    
+
     return result;
 }
 
@@ -1078,13 +1078,13 @@ static inline abi_ulong host_to_target_rlim(rlim_t rlim)
 {
     abi_ulong target_rlim_swap;
     abi_ulong result;
-    
+
     if (rlim == RLIM_INFINITY || rlim != (abi_long)rlim)
         target_rlim_swap = TARGET_RLIM_INFINITY;
     else
         target_rlim_swap = rlim;
     result = tswapal(target_rlim_swap);
-    
+
     return result;
 }
 
@@ -1526,10 +1526,11 @@ static inline abi_long target_to_host_cmsg(struct msghdr *msgh,
     abi_ulong target_cmsg_addr;
     struct target_cmsghdr *target_cmsg, *target_cmsg_start;
     socklen_t space = 0;
-    
+
     msg_controllen = tswapal(target_msgh->msg_controllen);
-    if (msg_controllen < sizeof (struct target_cmsghdr)) 
+    if (msg_controllen < sizeof(struct target_cmsghdr)) {
         goto the_end;
+    }
     target_cmsg_addr = tswapal(target_msgh->msg_control);
     target_cmsg = lock_user(VERIFY_READ, target_cmsg_addr, msg_controllen, 1);
     target_cmsg_start = target_cmsg;
@@ -1610,8 +1611,9 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
     socklen_t space = 0;
 
     msg_controllen = tswapal(target_msgh->msg_controllen);
-    if (msg_controllen < sizeof (struct target_cmsghdr)) 
+    if (msg_controllen < sizeof(struct target_cmsghdr)) {
         goto the_end;
+    }
     target_cmsg_addr = tswapal(target_msgh->msg_control);
     target_cmsg = lock_user(VERIFY_WRITE, target_cmsg_addr, msg_controllen, 0);
     target_cmsg_start = target_cmsg;
@@ -5592,9 +5594,9 @@ abi_long do_set_thread_area(CPUX86State *env, abi_ulong ptr)
     }
     unlock_user_struct(target_ldt_info, ptr, 1);
 
-    if (ldt_info.entry_number < TARGET_GDT_ENTRY_TLS_MIN || 
+    if (ldt_info.entry_number < TARGET_GDT_ENTRY_TLS_MIN ||
         ldt_info.entry_number > TARGET_GDT_ENTRY_TLS_MAX)
-           return -TARGET_EINVAL;
+        return -TARGET_EINVAL;
     seg_32bit = ldt_info.flags & 1;
     contents = (ldt_info.flags >> 1) & 3;
     read_exec_only = (ldt_info.flags >> 3) & 1;
@@ -5670,7 +5672,7 @@ static abi_long do_get_thread_area(CPUX86State *env, abi_ulong ptr)
     lp = (uint32_t *)(gdt_table + idx);
     entry_1 = tswap32(lp[0]);
     entry_2 = tswap32(lp[1]);
-    
+
     read_exec_only = ((entry_2 >> 9) & 1) ^ 1;
     contents = (entry_2 >> 10) & 3;
     seg_not_present = ((entry_2 >> 15) & 1) ^ 1;
@@ -5686,8 +5688,8 @@ static abi_long do_get_thread_area(CPUX86State *env, abi_ulong ptr)
         (read_exec_only << 3) | (limit_in_pages << 4) |
         (seg_not_present << 5) | (useable << 6) | (lm << 7);
     limit = (entry_1 & 0xffff) | (entry_2  & 0xf0000);
-    base_addr = (entry_1 >> 16) | 
-        (entry_2 & 0xff000000) | 
+    base_addr = (entry_1 >> 16) |
+        (entry_2 & 0xff000000) |
         ((entry_2 & 0xff) << 16);
     target_ldt_info->base_addr = tswapal(base_addr);
     target_ldt_info->limit = tswap32(limit);
@@ -10554,8 +10556,10 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
         return get_errno(fchown(arg1, low2highuid(arg2), low2highgid(arg3)));
 #if defined(TARGET_NR_fchownat)
     case TARGET_NR_fchownat:
-        if (!(p = lock_user_string(arg2))) 
+        p = lock_user_string(arg2);
+        if (!p) {
             return -TARGET_EFAULT;
+        }
         ret = get_errno(fchownat(arg1, p, low2highuid(arg3),
                                  low2highgid(arg4), arg5));
         unlock_user(p, arg2, 0);
Signature · 1 line
2.24.1
#100 lore raw

PATCH 59/59 linux-user/vm86.c: remove unneeded label in do_vm86()

In reply to Daniel Henrique Barboza

'out' can be replaced by 'return' calls with the adequate return value.

---
 linux-user/vm86.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
linux-user/vm86.c +2 -5
index 2fa7a89edc..eceddd05df 100644
@@ -403,16 +403,14 @@ int do_vm86(CPUX86State *env, long subfunction, abi_ulong vm86_addr)
     case TARGET_VM86_GET_IRQ_BITS:
     case TARGET_VM86_GET_AND_RESET_IRQ:
         gemu_log("qemu: unsupported vm86 subfunction (%ld)\n", subfunction);
-        ret = -TARGET_EINVAL;
-        goto out;
+        return -TARGET_EINVAL;
     case TARGET_VM86_PLUS_INSTALL_CHECK:
         /* NOTE: on old vm86 stuff this will return the error
            from verify_area(), because the subfunction is
            interpreted as (invalid) address to vm86_struct.
            So the installation check works.
             */
-        ret = 0;
-        goto out;
+        return 0;
     }
 
     /* save current CPU regs */
@@ -485,6 +483,5 @@ int do_vm86(CPUX86State *env, long subfunction, abi_ulong vm86_addr)
     LOG_VM86("do_vm86: cs:ip=%04x:%04x\n",
              env->segs[R_CS].selector, env->eip);
     /* now the virtual CPU is ready for vm86 execution ! */
- out:
     return ret;
 }
Signature · 1 line
2.24.1
#101 lore raw
In reply to Daniel Henrique Barboza
Quoted 18 lines · Daniel Henrique Barboza

Hello,

This is the type of cleanup I've contributed to Libvirt during the last year. Figured QEMU also deserves the same care.

The idea here is remove unneeded labels. By 'unneeded' I mean labels that does nothing but a 'return' call. One common case is something like this:

if ()

    goto cleanup;
[...]
 cleanup:
    return 0;

This code can be simplified to:

Quoted 7 lines

if ()

    return 0;

Which is cleaner and requires less brain cycles to wonder whether the 'cleanup' label does anything special, such as a heap memory cleanup.

I would disagree with this analysis. To me, I often wonder when I have to add cleanup code to a routine whether there is some hidden return in the middle of the function. That's a lot harder to spot than just looking for the cleanup label at the end of the function to see what it does. For non-trivial functions I prefer to have one point of return at the end (and maybe some minor checks with returns right at the beginning). I'm not adamant about this, just my opinion.

But if we are going to fix things like this, it might be best to add them to the coding style document and checkpatch script. Otherwise these sorts of things will just continue.

-corey

Quoted 157 lines

Another common case uses a variable to set a return value, generally an error, then return:

if () {
    ret = -ENOENT;
    goto out;
}
[..]
 out:
    return ret;

Likewise, it is clearer to just 'return -ENOENT' instead of jumping to a label. There are other cases being handled in these patches, but these are the most common.

There are still a handful of unneeded labels hanging around after this series. There are cases in which the label name is part of the code semantics and I judged not worth removing. search_chunk() in block/dmg.c has an example of an unneeded 'err' label that I decided to not remove.

No functional change was made. If any of these patches changes existing behavior it is unintended and an error from my part.

Daniel Henrique Barboza (59):
spapr.c: remove 'out' label in spapr_dt_cas_updates() ppc440_bamboo.c: remove label from bamboo_load_device_tree() kvm-all.c: remove unneeded labels
paaudio.c: remove unneeded labels
ram.c: remove unneeded labels
mips-semi.c: remove 'uhi_done' label in helper_do_semihosting() unicore32/softmmu.c: remove 'do_fault' label in get_phys_addr_ucv2() chardev/char-mux.c: remove 'send_char' label chardev/char-pipe.c: remove 'fail' label in win_chr_pipe_init() chardev/char-win.c: remove 'fail' label in win_chr_serial_init() exec.c: remove 'err' label in ram_block_discard_range() virtfs-proxy-helper.c: remove 'err_out' label in setugid() block/vdi.c: remove 'fail' label in vdi_open() block/file-posix.c: remove unneeded labels block/blkreplay.c: remove unneeded 'fail' label in blkreplay_open() block/gluster.c: remove unneeded 'exit' label block/dmg.c: remove unneeded 'fail' label in dmg_read_mish_block() qcow2-refcount.c: remove unneeded 'fail' label in
qcow2_refcount_init()
block/ssh.c: remove unneeded labels
block/vpc.c: remove unneeded 'fail' label in create_dynamic_disk() block/backup.c remove unneeded 'out' label in backup_run() block/vmdk.c: remove unneeded labels
block/vxhs.c: remove unneeded 'out' label in vxhs_iio_callback() block/vhdx-log.c: remove unneeded labels
block/vhdx.c: remove unneeded 'exit' labels block/replication.c: remove unneeded label in replication_co_writev crypto/block-luks.c: remove unneeded label in
qcrypto_block_luks_find_key
qga/commands-win32.c: remove 'out' label in get_pci_info cryptodev-vhost.c: remove unneeded 'err' label in
cryptodev_vhost_start
util/module.c: remove unneeded label in module_load_file() util/aio-posix.c: remove unneeded 'out' label in aio_epoll qemu-img.c: remove 'out4' label in img_compare ipmi/ipmi_bmc_sim.c: remove unneeded labels ipmi/ipmi_bt.c: remove unneeded label in ipmi_bt_handle_event ipmi_bmc_extern.c: remove unneeded label in
ipmi_bmc_extern_handle_command
ipmi/ipmi_kcs.c: remove unneeded label in ipmi_kcs_handle_event s390x/event-facility.c: remove unneeded labels s390x/sclp.c: remove unneeded label in sclp_service_call() usb/dev-mtp.c: remove unneeded label in write_retry() hsb/hcd-ehci.c: remove unneeded labels intc/s390_flic_kvm.c: remove unneeded label in kvm_flic_load() i386/intel_iommu.c: remove unneeded labels i386/amd_iommu.c: remove unneeded label in amdvi_int_remap_msi() 9p-local.c: remove unneeded label in local_unlinkat_common() 9pfs/9p.c: remove unneeded labels
alpha/typhoon.c: remove unneeded label in typhoon_translate_iommu() pvrdma_main.c: remove unneeded labels
pvrdma_dev_ring.c: remove unneeded label in pvrdma_ring_init() rdma/rdma_rm.c: remove unneeded label in rdma_rm_alloc_pd() rdma/rdma_backend.c: remove unneeded label in rdma_backend_init() virtio/vhost.c: remove unneeded labels
net/vhost_net.c: remove unneeded labels
net/net_tx_pkt.c: remove unneeded label in net_tx_pkt_get_gso_type() ivshmem-server/main.c: remove unneeded label in main() linux-user/flatload.c: remove unused 'out' label linux-user/signal.c: remove unneeded label in do_sigaltstack() linux-user/syscall.c: fix trailing whitespaces and style linux-user/syscall.c: remove unneeded labels linux-user/vm86.c: remove unneeded label in do_vm86()

 accel/kvm/kvm-all.c           | 30 +++++-------
 audio/paaudio.c               | 10 +---
 backends/cryptodev-vhost.c    |  4 +-
 block/backup.c                |  6 +--
 block/blkreplay.c             |  8 +---
 block/dmg.c                   | 10 +---
 block/file-posix.c            | 10 ++--
 block/gluster.c               |  3 +-
 block/qcow2-refcount.c        |  7 +--
 block/replication.c           |  9 ++--
 block/ssh.c                   | 61 ++++++++-----------------
 block/vdi.c                   | 40 ++++++----------
 block/vhdx-log.c              | 86 +++++++++++++----------------------
 block/vhdx.c                  | 10 ++--
 block/vmdk.c                  | 37 ++++++---------
 block/vpc.c                   | 12 ++---
 block/vxhs.c                  |  4 +-
 chardev/char-mux.c            |  3 +-
 chardev/char-pipe.c           | 13 ++----
 chardev/char-win.c            | 19 ++++----
 contrib/ivshmem-server/main.c |  9 ++--
 crypto/block-luks.c           |  3 +-
 exec.c                        | 13 +++---
 fsdev/virtfs-proxy-helper.c   |  4 +-
 hw/9pfs/9p-local.c            | 12 ++---
 hw/9pfs/9p.c                  |  9 ++--
 hw/alpha/typhoon.c            | 18 ++++----
 hw/i386/amd_iommu.c           | 13 ++----
 hw/i386/intel_iommu.c         |  8 ++--
 hw/intc/s390_flic_kvm.c       | 10 ++--
 hw/ipmi/ipmi_bmc_extern.c     |  5 +-
 hw/ipmi/ipmi_bmc_sim.c        |  9 +---
 hw/ipmi/ipmi_bt.c             |  8 ++--
 hw/ipmi/ipmi_kcs.c            |  4 +-
 hw/net/net_tx_pkt.c           | 11 ++---
 hw/net/vhost_net.c            |  7 ++-
 hw/ppc/ppc440_bamboo.c        |  8 +---
 hw/ppc/spapr.c                |  9 ++--
 hw/rdma/rdma_backend.c        |  4 +-
 hw/rdma/rdma_rm.c             | 11 ++---
 hw/rdma/vmw/pvrdma_dev_ring.c |  7 +--
 hw/rdma/vmw/pvrdma_main.c     | 10 ++--
 hw/s390x/event-facility.c     | 21 +++------
 hw/s390x/sclp.c               | 16 ++-----
 hw/usb/dev-mtp.c              | 13 ++----
 hw/usb/hcd-ehci.c             | 32 ++++---------
 hw/virtio/vhost.c             | 11 ++---
 linux-user/flatload.c         |  1 -
 linux-user/signal.c           | 20 +++-----
 linux-user/syscall.c          | 54 ++++++++++------------
 linux-user/vm86.c             |  7 +--
 migration/ram.c               | 18 ++------
 qemu-img.c                    |  7 +--
 qga/commands-win32.c          | 17 ++++---
 target/mips/mips-semi.c       | 15 +++---
 target/unicore32/softmmu.c    | 23 +++-------
 util/aio-posix.c              |  3 +-
 util/module.c                 | 11 ++---
 58 files changed, 293 insertions(+), 550 deletions(-)
Signature · 1 line
2.24.1
#102 lore raw
Quoted 2 lines · Corey Minyard
Quoted 1 line · Daniel Henrique Barboza

Hello,

[...]

Quoted 5 lines
Quoted 4 lines

Which is cleaner and requires less brain cycles to wonder whether the 'cleanup' label does anything special, such as a heap memory cleanup.

Quoted 8 lines

I would disagree with this analysis. To me, I often wonder when I have to add cleanup code to a routine whether there is some hidden return in the middle of the function. That's a lot harder to spot than just looking for the cleanup label at the end of the function to see what it does. For non-trivial functions I prefer to have one point of return at the end (and maybe some minor checks with returns right at the beginning). I'm not adamant about this, just my opinion.

I agree that what I'm doing here isn't a one rule fits all situation. This is why I didn't purge all the 'unused' labels I found. The criteria used to remove/spare labels will differ from person to person (although I believe that cases such as patch 15 isn't too much of a debate), thus I'd rather leave to each maintainer to accept/deny the changes based on the context of the code.

And for this same reason I don't think that a checkpatch rule is necessary. The review process can take care of these situations and allow 'good unneeded labels' to be in the code.

Thanks,

DHB

Quoted 7 lines

But if we are going to fix things like this, it might be best to add them to the coding style document and checkpatch script. Otherwise these sorts of things will just continue.

-corey

#30 lore raw

Re: [PATCH v1 13/59] block/vdi.c: remove 'fail' label in vdi_open()

In reply to Daniel Henrique Barboza

Am 06.01.20 um 19:23 schrieb Daniel Henrique Barboza:

Quoted 114 lines

The 'fail' label can be replaced by 'return ret' or by a 'return' with the error code that was being set right before the 'goto' call.

---
 block/vdi.c | 40 +++++++++++++---------------------------
 1 file changed, 13 insertions(+), 27 deletions(-)
block/vdi.c +13 -25
index 0142da7233..6d486ffed9 100644
@@ -388,7 +388,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
 
     ret = bdrv_pread(bs->file, 0, &header, sizeof(header));
     if (ret < 0) {
-        goto fail;
+        return ret;
     }
 
     vdi_header_to_cpu(&header);
@@ -400,8 +400,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
         error_setg(errp, "Unsupported VDI image size (size is 0x%" PRIx64
                           ", max supported is 0x%" PRIx64 ")",
                           header.disk_size, VDI_DISK_SIZE_MAX);
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     }
 
     uuid_link = header.uuid_link;
@@ -418,58 +417,48 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
     if (header.signature != VDI_SIGNATURE) {
         error_setg(errp, "Image not in VDI format (bad signature %08" PRIx32
                    ")", header.signature);
-        ret = -EINVAL;
-        goto fail;
+        return -EINVAL;
     } else if (header.version != VDI_VERSION_1_1) {
         error_setg(errp, "unsupported VDI image (version %" PRIu32 ".%" PRIu32
                    ")", header.version >> 16, header.version & 0xffff);
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     } else if (header.offset_bmap % SECTOR_SIZE != 0) {
         /* We only support block maps which start on a sector boundary. */
         error_setg(errp, "unsupported VDI image (unaligned block map offset "
                    "0x%" PRIx32 ")", header.offset_bmap);
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     } else if (header.offset_data % SECTOR_SIZE != 0) {
         /* We only support data blocks which start on a sector boundary. */
         error_setg(errp, "unsupported VDI image (unaligned data offset 0x%"
                    PRIx32 ")", header.offset_data);
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     } else if (header.sector_size != SECTOR_SIZE) {
         error_setg(errp, "unsupported VDI image (sector size %" PRIu32
                    " is not %u)", header.sector_size, SECTOR_SIZE);
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     } else if (header.block_size != DEFAULT_CLUSTER_SIZE) {
         error_setg(errp, "unsupported VDI image (block size %" PRIu32
                          " is not %" PRIu32 ")",
                    header.block_size, DEFAULT_CLUSTER_SIZE);
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     } else if (header.disk_size >
                (uint64_t)header.blocks_in_image * header.block_size) {
         error_setg(errp, "unsupported VDI image (disk size %" PRIu64 ", "
                    "image bitmap has room for %" PRIu64 ")",
                    header.disk_size,
                    (uint64_t)header.blocks_in_image * header.block_size);
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     } else if (!qemu_uuid_is_null(&uuid_link)) {
         error_setg(errp, "unsupported VDI image (non-NULL link UUID)");
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     } else if (!qemu_uuid_is_null(&uuid_parent)) {
         error_setg(errp, "unsupported VDI image (non-NULL parent UUID)");
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     } else if (header.blocks_in_image > VDI_BLOCKS_IN_IMAGE_MAX) {
         error_setg(errp, "unsupported VDI image "
                          "(too many blocks %u, max is %u)",
                           header.blocks_in_image, VDI_BLOCKS_IN_IMAGE_MAX);
-        ret = -ENOTSUP;
-        goto fail;
+        return -ENOTSUP;
     }
 
     bs->total_sectors = header.disk_size / SECTOR_SIZE;
@@ -482,8 +471,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
     bmap_size = DIV_ROUND_UP(bmap_size, SECTOR_SIZE);
     s->bmap = qemu_try_blockalign(bs->file->bs, bmap_size * SECTOR_SIZE);
     if (s->bmap == NULL) {
-        ret = -ENOMEM;
-        goto fail;
+        return -ENOMEM;
     }
 
     ret = bdrv_pread(bs->file, header.offset_bmap, s->bmap,

block/vdi.c static int vdi_open(BlockDriverState *bs, QDict *options, int flags, · line 502

Quoted 8 lines
block/vdi.c +0 -2
@@ -509,8 +497,6 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
 
  fail_free_bmap:
     qemu_vfree(s->bmap);
-
- fail:
     return ret;
 }
 

Technically these changes are fine. Personally I prefer functions having a single return statement, even if that requires a goto statement. But if there is a consense to change the code, that can be done of course.

Regards,
Stefan Weil

Reviewed-by on v1 5/59
#9 lore raw

Re: [PATCH v1 05/59] ram.c: remove unneeded labels

In reply to Daniel Henrique Barboza
Quoted 10 lines · Daniel Henrique Barboza

ram_save_queue_pages() has an 'err' label that can be replaced by 'return -1' instead.

Same thing with ram_discard_range(), and in this case we can also get rid of the 'ret' variable and return either '-1' on error or the result of ram_block_discard_range().

CC Juan Quintela <[email protected]>
CC Dr. David Alan Gilbert <[email protected]>
Applied
#2 lore raw

Re: [PATCH v1 01/59] spapr.c: remove 'out' label in spapr_dt_cas_updates()

In reply to Daniel Henrique Barboza
Quoted 6 lines · Daniel Henrique Barboza

'out' can be replaced by 'return' with the appropriate return value.

Applied to ppc-for-5.0. I see this is part of a larged series which might have a different merge plan, but it should be an easy conflict to resolve if that happens.

Quoted 31 lines
---
 hw/ppc/spapr.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
hw/ppc/spapr.c +3 -6
index f11422fc41..1bfe47337c 100644
@@ -878,7 +878,7 @@ static int spapr_dt_cas_updates(SpaprMachineState *spapr, void *fdt,
         g_assert(smc->dr_lmb_enabled);
         ret = spapr_populate_drconf_memory(spapr, fdt);
         if (ret) {
-            goto out;
+            return ret;
         }
     }
 
@@ -889,11 +889,8 @@ static int spapr_dt_cas_updates(SpaprMachineState *spapr, void *fdt,
             return offset;
         }
     }
-    ret = spapr_ovec_populate_dt(fdt, offset, spapr->ov5_cas,
-                                 "ibm,architecture-vec-5");
-
-out:
-    return ret;
+    return spapr_ovec_populate_dt(fdt, offset, spapr->ov5_cas,
+                                  "ibm,architecture-vec-5");
 }
 
 static void spapr_dt_rtas(SpaprMachineState *spapr, void *fdt)
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
Applied
#4 lore raw

Re: [PATCH v1 02/59] ppc440_bamboo.c: remove label from bamboo_load_device_tree()

In reply to Daniel Henrique Barboza
Quoted 5 lines · Daniel Henrique Barboza

'out' label can be replaced by 'return -1' in all cases.

Applied to ppc-for-5.0.

Quoted 34 lines
---
 hw/ppc/ppc440_bamboo.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
hw/ppc/ppc440_bamboo.c +2 -6
index 4d95c0f8a8..b782641b23 100644
@@ -71,12 +71,12 @@ static int bamboo_load_device_tree(hwaddr addr,
 
     filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
     if (!filename) {
-        goto out;
+        return -1;
     }
     fdt = load_device_tree(filename, &fdt_size);
     g_free(filename);
     if (fdt == NULL) {
-        goto out;
+        return -1;
     }
 
     /* Manipulate device tree in memory. */
@@ -117,10 +117,6 @@ static int bamboo_load_device_tree(hwaddr addr,
     rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE, fdt, fdt_size, addr);
     g_free(fdt);
     return 0;
-
-out:
-
-    return ret;
 }
 
 /* Create reset TLB entries for BookE, spanning the 32bit addr space.  */
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#103 lore raw
In reply to Daniel Henrique Barboza

Am 06.01.2020 um 21:35 hat Daniel Henrique Barboza geschrieben:

Quoted 11 lines · Corey Minyard
Quoted 2 lines · Daniel Henrique Barboza
Quoted 1 line

Hello,

[...]

Quoted 5 lines
Quoted 4 lines

Which is cleaner and requires less brain cycles to wonder whether the 'cleanup' label does anything special, such as a heap memory cleanup.

Quoted 8 lines
Quoted 8 lines

I would disagree with this analysis. To me, I often wonder when I have to add cleanup code to a routine whether there is some hidden return in the middle of the function. That's a lot harder to spot than just looking for the cleanup label at the end of the function to see what it does. For non-trivial functions I prefer to have one point of return at the end (and maybe some minor checks with returns right at the beginning). I'm not adamant about this, just my opinion.

It depends on the case, but yes, I had similar thoughts, at least when we're talking about non-trivial parts of a function. (Very short functions of just some initial checks returning directly are usually fine.)

Quoted 5 lines

I agree that what I'm doing here isn't a one rule fits all situation. This is why I didn't purge all the 'unused' labels I found. The criteria used to remove/spare labels will differ from person to person (although I believe that cases such as patch 15 isn't too much of a debate), thus I'd rather leave to each maintainer to accept/deny the changes based on the context of the code.

So what is your plan for getting the series merged? Should maintainers just picks patches from the series, or do you want to collect Acked-by tags and then merge it through a single tree? If the latter, which one?

Kevin

Reviewed-by on v1 10/59
#21 lore raw

Re: [PATCH v1 10/59] chardev/char-win.c: remove 'fail' label in win_chr_serial_init()

In reply to Daniel Henrique Barboza
Quoted 6 lines · Daniel Henrique Barboza

The 'fail' label is a simply call to 'return -1' on error. Remove it and do the return call instead.

CC Marc-André Lureau <[email protected]>
CC Paolo Bonzini <[email protected]>
Quoted 73 lines
---
  chardev/char-win.c | 19 ++++++++-----------
  1 file changed, 8 insertions(+), 11 deletions(-)
chardev/char-win.c +8 -11
index 34825f683d..72c232e6d9 100644
@@ -85,12 +85,12 @@ int win_chr_serial_init(Chardev *chr, const char *filename, Error **errp)
      s->hsend = CreateEvent(NULL, TRUE, FALSE, NULL);
      if (!s->hsend) {
          error_setg(errp, "Failed CreateEvent");
-        goto fail;
+        return -1;
      }
      s->hrecv = CreateEvent(NULL, TRUE, FALSE, NULL);
      if (!s->hrecv) {
          error_setg(errp, "Failed CreateEvent");
-        goto fail;
+        return -1;
      }
 
      s->file = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
@@ -98,12 +98,12 @@ int win_chr_serial_init(Chardev *chr, const char *filename, Error **errp)
      if (s->file == INVALID_HANDLE_VALUE) {
          error_setg(errp, "Failed CreateFile (%lu)", GetLastError());
          s->file = NULL;
-        goto fail;
+        return -1;
      }
 
      if (!SetupComm(s->file, NRECVBUF, NSENDBUF)) {
          error_setg(errp, "Failed SetupComm");
-        goto fail;
+        return -1;
      }
 
      ZeroMemory(&comcfg, sizeof(COMMCONFIG));
@@ -114,29 +114,26 @@ int win_chr_serial_init(Chardev *chr, const char *filename, Error **errp)
 
      if (!SetCommState(s->file, &comcfg.dcb)) {
          error_setg(errp, "Failed SetCommState");
-        goto fail;
+        return -1;
      }
 
      if (!SetCommMask(s->file, EV_ERR)) {
          error_setg(errp, "Failed SetCommMask");
-        goto fail;
+        return -1;
      }
 
      cto.ReadIntervalTimeout = MAXDWORD;
      if (!SetCommTimeouts(s->file, &cto)) {
          error_setg(errp, "Failed SetCommTimeouts");
-        goto fail;
+        return -1;
      }
 
      if (!ClearCommError(s->file, &err, &comstat)) {
          error_setg(errp, "Failed ClearCommError");
-        goto fail;
+        return -1;
      }
      qemu_add_polling_cb(win_chr_serial_poll, chr);
      return 0;
-
- fail:
-    return -1;
  }
 
  int win_chr_pipe_poll(void *opaque)
Reviewed-by on v1 29/59
#50 lore raw

Re: [PATCH v1 29/59] cryptodev-vhost.c: remove unneeded 'err' label in cryptodev_vhost_start

In reply to Daniel Henrique Barboza
Quoted 4 lines · Daniel Henrique Barboza

'err' can be replaced by 'return r'.

Quoted 27 lines
---
  backends/cryptodev-vhost.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
backends/cryptodev-vhost.c +2 -2
index 8337c9a495..907ca21fa7 100644
@@ -201,7 +201,7 @@ int cryptodev_vhost_start(VirtIODevice *dev, int total_queues)
      r = k->set_guest_notifiers(qbus->parent, total_queues, true);
      if (r < 0) {
          error_report("error binding guest notifier: %d", -r);
-        goto err;
+        return r;
      }
 
      for (i = 0; i < total_queues; i++) {
@@ -236,7 +236,7 @@ err_start:
      if (e < 0) {
          error_report("vhost guest notifier cleanup failed: %d", e);
      }
-err:
+
      return r;
  }
 
#97 lore raw

Re: [PATCH v1 57/59] linux-user/syscall.c: fix trailing whitespaces and style

In reply to Daniel Henrique Barboza
Quoted 2 lines · Daniel Henrique Barboza

There are trailing whitespaces in this file that, if removed by a text editor that refuses to let the traiing whitespace

typo "trailing"

Quoted 4 lines

alone, which happens to be the editor I am using, will cause checkpatch.pl to warn about styling problems in the resulting patch. This happens because the trailing whitespace lines are using a deprecated style.

Maybe you can use 'git add -p' to only add the lines with relevant changes.

Quoted 122 lines

To keep the intended change I wanted to do (remove unneeded labels in do_ioctl_blkpg() and do_sendrecvmsg_locked()) trivial, this patch is another trivial change to fix the trailing whitespaces and the code style errors that checkpatch.pl warns about. Doing this change beforehand will keep the next patch focused just on the label removal changes.

---
  linux-user/syscall.c | 30 +++++++++++++++++-------------
  1 file changed, 17 insertions(+), 13 deletions(-)
linux-user/syscall.c +17 -13
index 171c0caef3..49c6151c2d 100644
@@ -1062,7 +1062,7 @@ static inline rlim_t target_to_host_rlim(abi_ulong target_rlim)
  {
      abi_ulong target_rlim_swap;
      rlim_t result;
-
+
      target_rlim_swap = tswapal(target_rlim);
      if (target_rlim_swap == TARGET_RLIM_INFINITY)
          return RLIM_INFINITY;
@@ -1070,7 +1070,7 @@ static inline rlim_t target_to_host_rlim(abi_ulong target_rlim)
      result = target_rlim_swap;
      if (target_rlim_swap != (rlim_t)result)
          return RLIM_INFINITY;
-
+
      return result;
  }
 
@@ -1078,13 +1078,13 @@ static inline abi_ulong host_to_target_rlim(rlim_t rlim)
  {
      abi_ulong target_rlim_swap;
      abi_ulong result;
-
+
      if (rlim == RLIM_INFINITY || rlim != (abi_long)rlim)
          target_rlim_swap = TARGET_RLIM_INFINITY;
      else
          target_rlim_swap = rlim;
      result = tswapal(target_rlim_swap);
-
+
      return result;
  }
 
@@ -1526,10 +1526,11 @@ static inline abi_long target_to_host_cmsg(struct msghdr *msgh,
      abi_ulong target_cmsg_addr;
      struct target_cmsghdr *target_cmsg, *target_cmsg_start;
      socklen_t space = 0;
-
+
      msg_controllen = tswapal(target_msgh->msg_controllen);
-    if (msg_controllen < sizeof (struct target_cmsghdr))
+    if (msg_controllen < sizeof(struct target_cmsghdr)) {
          goto the_end;
+    }
      target_cmsg_addr = tswapal(target_msgh->msg_control);
      target_cmsg = lock_user(VERIFY_READ, target_cmsg_addr, msg_controllen, 1);
      target_cmsg_start = target_cmsg;
@@ -1610,8 +1611,9 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
      socklen_t space = 0;
 
      msg_controllen = tswapal(target_msgh->msg_controllen);
-    if (msg_controllen < sizeof (struct target_cmsghdr))
+    if (msg_controllen < sizeof(struct target_cmsghdr)) {
          goto the_end;
+    }
      target_cmsg_addr = tswapal(target_msgh->msg_control);
      target_cmsg = lock_user(VERIFY_WRITE, target_cmsg_addr, msg_controllen, 0);
      target_cmsg_start = target_cmsg;
@@ -5592,9 +5594,9 @@ abi_long do_set_thread_area(CPUX86State *env, abi_ulong ptr)
      }
      unlock_user_struct(target_ldt_info, ptr, 1);
 
-    if (ldt_info.entry_number < TARGET_GDT_ENTRY_TLS_MIN ||
+    if (ldt_info.entry_number < TARGET_GDT_ENTRY_TLS_MIN ||
          ldt_info.entry_number > TARGET_GDT_ENTRY_TLS_MAX)
-           return -TARGET_EINVAL;
+        return -TARGET_EINVAL;
      seg_32bit = ldt_info.flags & 1;
      contents = (ldt_info.flags >> 1) & 3;
      read_exec_only = (ldt_info.flags >> 3) & 1;
@@ -5670,7 +5672,7 @@ static abi_long do_get_thread_area(CPUX86State *env, abi_ulong ptr)
      lp = (uint32_t *)(gdt_table + idx);
      entry_1 = tswap32(lp[0]);
      entry_2 = tswap32(lp[1]);
-
+
      read_exec_only = ((entry_2 >> 9) & 1) ^ 1;
      contents = (entry_2 >> 10) & 3;
      seg_not_present = ((entry_2 >> 15) & 1) ^ 1;
@@ -5686,8 +5688,8 @@ static abi_long do_get_thread_area(CPUX86State *env, abi_ulong ptr)
          (read_exec_only << 3) | (limit_in_pages << 4) |
          (seg_not_present << 5) | (useable << 6) | (lm << 7);
      limit = (entry_1 & 0xffff) | (entry_2  & 0xf0000);
-    base_addr = (entry_1 >> 16) |
-        (entry_2 & 0xff000000) |
+    base_addr = (entry_1 >> 16) |
+        (entry_2 & 0xff000000) |
          ((entry_2 & 0xff) << 16);
      target_ldt_info->base_addr = tswapal(base_addr);
      target_ldt_info->limit = tswap32(limit);
@@ -10554,8 +10556,10 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
          return get_errno(fchown(arg1, low2highuid(arg2), low2highgid(arg3)));
  #if defined(TARGET_NR_fchownat)
      case TARGET_NR_fchownat:
-        if (!(p = lock_user_string(arg2)))
+        p = lock_user_string(arg2);
+        if (!p) {
              return -TARGET_EFAULT;
+        }
          ret = get_errno(fchownat(arg1, p, low2highuid(arg3),
                                   low2highgid(arg4), arg5));
          unlock_user(p, arg2, 0);
#104 lore raw
In reply to Kevin Wolf
Quoted 19 lines · Kevin Wolf

Am 06.01.2020 um 21:35 hat Daniel Henrique Barboza geschrieben:

Quoted 9 lines · Corey Minyard
Quoted 2 lines · Daniel Henrique Barboza
Quoted 1 line

Hello,

[...]

Quoted 5 lines
Quoted 4 lines

Which is cleaner and requires less brain cycles to wonder whether the 'cleanup' label does anything special, such as a heap memory cleanup.

Quoted 8 lines
Quoted 8 lines

I would disagree with this analysis. To me, I often wonder when I have to add cleanup code to a routine whether there is some hidden return in the middle of the function. That's a lot harder to spot than just looking for the cleanup label at the end of the function to see what it does. For non-trivial functions I prefer to have one point of return at the end (and maybe some minor checks with returns right at the beginning). I'm not adamant about this, just my opinion.

Quoted 4 lines

It depends on the case, but yes, I had similar thoughts, at least when we're talking about non-trivial parts of a function. (Very short functions of just some initial checks returning directly are usually fine.)

From a debugging point of view, and when adding trace-events, it is easier to have a single function exit path.

In various functions modified by your patches, we can split big functions in smaller ones and avoid the goto label.

Reviewed-by on v1 29/59
#51 lore raw

RE: [PATCH v1 29/59] cryptodev-vhost.c: remove unneeded 'err' label in cryptodev_vhost_start

In reply to Daniel Henrique Barboza
Quoted 10 lines

-----Original Message-----
From: Daniel Henrique Barboza [mailto:[email protected]]
Sent: Tuesday, January 7, 2020 2:24 AM
To: [email protected]
Cc: [email protected]; Daniel Henrique Barboza <[email protected]>; Gonglei (Arei) <[email protected]>
Subject: [PATCH v1 29/59] cryptodev-vhost.c: remove unneeded 'err' label in cryptodev_vhost_start

Quoted 8 lines

'err' can be replaced by 'return r'.

---
 backends/cryptodev-vhost.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 24 lines
backends/cryptodev-vhost.c index renamed from backends/cryptodev-vhost.c +0 -0

8337c9a495..907ca21fa7 100644

backends/cryptodev-vhost.c +1 -1
@@ -201,7 +201,7 @@ int cryptodev_vhost_start(VirtIODevice *dev, int
 total_queues)
     r = k->set_guest_notifiers(qbus->parent, total_queues, true);
     if (r < 0) {
         error_report("error binding guest notifier: %d", -r);
-        goto err;
+        return r;
     }
 
     for (i = 0; i < total_queues; i++) { @@ -236,7 +236,7 @@ err_start:
     if (e < 0) {
         error_report("vhost guest notifier cleanup failed: %d", e);
     }
backends/cryptodev-vhost.c +1 -2
-err:
+
     return r;
 }
 
--

2.24.1

#109 lore raw
In reply to Daniel Henrique Barboza
Quoted 18 lines · Daniel Henrique Barboza

Hello,

This is the type of cleanup I've contributed to Libvirt during the last year. Figured QEMU also deserves the same care.

The idea here is remove unneeded labels. By 'unneeded' I mean labels that does nothing but a 'return' call. One common case is something like this:

if ()

    goto cleanup;
[...]
 cleanup:
    return 0;

This code can be simplified to:

Quoted 7 lines

if ()

    return 0;

Which is cleaner and requires less brain cycles to wonder whether the 'cleanup' label does anything special, such as a heap memory cleanup.

For me, it doesn’t require any brain cycles, because I generally just assume the cleanup label will do the right thing. OTOH, a return statement may make me invest some some brain cycles, because maybe there is something to be cleaned up and it isn’t done here.

Quoted 11 lines

Another common case uses a variable to set a return value, generally an error, then return:

if () {
    ret = -ENOENT;
    goto out;
}
[..]
 out:
    return ret;
Quoted 3 lines

Likewise, it is clearer to just 'return -ENOENT' instead of jumping to a label. There are other cases being handled in these patches, but these are the most common.

I find it clearer from the perspective of “less LoC”, but I find it less clear from the perspective of “Is this the right way to clean up?”.

Even on patch 15 (which you say isn’t too much of a debate), I don’t find the change to make things any clearer. Just less verbose.

I suppose none of this would matter if we used __attribute__((cleanup)) everywhere and simply never had to clean up anything manually. But as long as we don’t and require cleanup paths in many places, I disagree that they require more brain cycles than plain return statements.

Max

Acked-by on v1 12/59
#24 lore raw

Re: [PATCH v1 12/59] virtfs-proxy-helper.c: remove 'err_out' label in setugid()

In reply to Daniel Henrique Barboza
Quoted 6 lines · On Mon, 6 Jan 2020 15:23:38 -0300 Daniel Henrique Barboza…

'err_out' can be removed and be replaced by 'return -errno' in its only instance in the function.

---

I don't really mind, but I confirm this doesn't change behavior.

What's the plan to get this and the other 9p related patches merged ? Through the trivial tree or each subsystem tree ?

Quoted 25 lines
 fsdev/virtfs-proxy-helper.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
fsdev/virtfs-proxy-helper.c +1 -3
index 0d4de49dcf..aa1ab2590d 100644
@@ -287,8 +287,7 @@ static int setugid(int uid, int gid, int *suid, int *sgid)
     *sgid = getegid();
 
     if (setresgid(-1, gid, *sgid) == -1) {
-        retval = -errno;
-        goto err_out;
+        return -errno;
     }
 
     if (setresuid(-1, uid, *suid) == -1) {
@@ -322,7 +321,6 @@ err_sgid:
     if (setresgid(-1, *sgid, *sgid) == -1) {
         abort();
     }
-err_out:
     return retval;
 }
 
Reviewed-by on v1 57/59
#98 lore raw

Re: [PATCH v1 57/59] linux-user/syscall.c: fix trailing whitespaces and style

In reply to Daniel Henrique Barboza
Quoted 7 lines · Daniel Henrique Barboza

There are trailing whitespaces in this file that, if removed by a text editor that refuses to let the traiing whitespace alone, which happens to be the editor I am using, will cause checkpatch.pl to warn about styling problems in the resulting patch. This happens because the trailing whitespace lines are using a deprecated style.

You should fix your editor to not do this kind of uncommanded edit (otherwise you'll be spending forever trying to sort out unasked for changes from patches you write) but the style cleanup here is reasonable.

Quoted 34 lines

To keep the intended change I wanted to do (remove unneeded labels in do_ioctl_blkpg() and do_sendrecvmsg_locked()) trivial, this patch is another trivial change to fix the trailing whitespaces and the code style errors that checkpatch.pl warns about. Doing this change beforehand will keep the next patch focused just on the label removal changes.

linux-user/syscall.c +5 -3
@@ -1526,10 +1526,11 @@ static inline abi_long target_to_host_cmsg(struct msghdr *msgh,
     abi_ulong target_cmsg_addr;
     struct target_cmsghdr *target_cmsg, *target_cmsg_start;
     socklen_t space = 0;
-
+
     msg_controllen = tswapal(target_msgh->msg_controllen);
-    if (msg_controllen < sizeof (struct target_cmsghdr))
+    if (msg_controllen < sizeof(struct target_cmsghdr)) {
         goto the_end;
+    }
     target_cmsg_addr = tswapal(target_msgh->msg_control);
     target_cmsg = lock_user(VERIFY_READ, target_cmsg_addr, msg_controllen, 1);
     target_cmsg_start = target_cmsg;
@@ -1610,8 +1611,9 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
     socklen_t space = 0;
 
     msg_controllen = tswapal(target_msgh->msg_controllen);
-    if (msg_controllen < sizeof (struct target_cmsghdr))
+    if (msg_controllen < sizeof(struct target_cmsghdr)) {
         goto the_end;
+    }
     target_cmsg_addr = tswapal(target_msgh->msg_control);
     target_cmsg = lock_user(VERIFY_WRITE, target_cmsg_addr, msg_controllen, 0);
     target_cmsg_start = target_cmsg;
@@ -5592,9 +5594,9 @@ abi_long do_set_thread_area(CPUX86State *env, abi_ulong ptr)
     }

linux-user/syscall.c abi_long do_set_thread_area(CPUX86State *env, abi_ulong ptr) · line 5602

Quoted 10 lines
linux-user/syscall.c +2 -2
     unlock_user_struct(target_ldt_info, ptr, 1);
 
-    if (ldt_info.entry_number < TARGET_GDT_ENTRY_TLS_MIN ||
+    if (ldt_info.entry_number < TARGET_GDT_ENTRY_TLS_MIN ||
         ldt_info.entry_number > TARGET_GDT_ENTRY_TLS_MAX)
-           return -TARGET_EINVAL;
+        return -TARGET_EINVAL;
     seg_32bit = ldt_info.flags & 1;
     contents = (ldt_info.flags >> 1) & 3;
     read_exec_only = (ldt_info.flags >> 3) & 1;

Doesn't checkpatch complain about not having braces on this if ?

Either way

-- PMM

Reviewed-by on v1 30/59
#53 lore raw

Re: [PATCH v1 30/59] util/module.c: remove unneeded label in module_load_file()

In reply to Daniel Henrique Barboza
Quoted 40 lines · Daniel Henrique Barboza

'out' can be replaced by the apropriate return values set in 'ret' for each case.

---
 util/module.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
util/module.c +3 -6
index e9fe3e5422..9b5453f878 100644
@@ -111,12 +111,10 @@ static int module_load_file(const char *fname)
 
     if (len <= suf_len || strcmp(&fname[len - suf_len], dsosuf)) {
         /* wrong suffix */
-        ret = -EINVAL;
-        goto out;
+        return -EINVAL;
     }
     if (access(fname, F_OK)) {
-        ret = -ENOENT;
-        goto out;
+        return -ENOENT;
     }
 
     assert(QTAILQ_EMPTY(&dso_init_list));
@@ -125,8 +123,7 @@ static int module_load_file(const char *fname)
     if (!g_module) {
         fprintf(stderr, "Failed to open module: %s\n",
                 g_module_error());
-        ret = -EINVAL;
-        goto out;
+        return -EINVAL;
     }
     if (!g_module_symbol(g_module, DSO_STAMP_FUN_STR, (gpointer *)&sym)) {
         fprintf(stderr, "Failed to initialize module: %s\n",

util/module.c static int module_load_file(const char *fname) · line 154

Quoted 8 lines
util/module.c +1 -1
@@ -151,7 +148,7 @@ static int module_load_file(const char *fname)
         QTAILQ_REMOVE(&dso_init_list, e, node);
         g_free(e);
     }
-out:
+
     return ret;
 }
 #endif
#106 lore raw
In reply to Kevin Wolf
Quoted 2 lines · Kevin Wolf

Am 06.01.2020 um 21:35 hat Daniel Henrique Barboza geschrieben:

Quoted 1 line

[...]

Quoted 4 lines

So what is your plan for getting the series merged? Should maintainers just picks patches from the series, or do you want to collect Acked-by tags and then merge it through a single tree? If the latter, which one?

The idea I had in mind was for each maintainer to pick up the patches and push through their own trees, like David did in patches 1 and 2.

From qemu-trivial archives I notice that Laurent creates qemu-trivial pull requests often, thus I believe this might also be an option. If we decide to go this route I'll ask David to remove patches 1 and 2 from his ppc tree to avoid unnecessary conflicts.

Thanks,

DHB

Quoted 3 lines

Kevin

#107 lore raw

Am 07.01.2020 um 12:52 hat Daniel Henrique Barboza geschrieben:

Quoted 6 lines
Quoted 3 lines

So what is your plan for getting the series merged? Should maintainers just picks patches from the series, or do you want to collect Acked-by tags and then merge it through a single tree? If the latter, which one?

The idea I had in mind was for each maintainer to pick up the patches and push through their own trees, like David did in patches 1 and 2.

Okay, thanks.

Quoted 4 lines

From qemu-trivial archives I notice that Laurent creates qemu-trivial pull requests often, thus I believe this might also be an option. If we decide to go this route I'll ask David to remove patches 1 and 2 from his ppc tree to avoid unnecessary conflicts.

Two trees picking up the same patch doesn't result in a conflict, git can resolve this just fine. It only gets problematic if different versions of a patch are picked up.

Kevin

#78 lore raw

Re: [PATCH v1 44/59] 9p-local.c: remove unneeded label in local_unlinkat_common()

In reply to Daniel Henrique Barboza
Quoted 39 lines · On Montag, 6. Januar 2020 19:24:10 CET Daniel Henrique Barboza wrote:

'err_out' can be replaced by 'return ret' in the error conditions the jump was being made.

---
 hw/9pfs/9p-local.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
hw/9pfs/9p-local.c +2 -2
index ca641390fb..f9bdd2ad7c 100644
@@ -1094,12 +1094,12 @@ static int local_unlinkat_common(FsContext *ctx, int
 dirfd, const char *name,
 
             fd = openat_dir(dirfd, name);
             if (fd == -1) {
-                goto err_out;
+                return ret;
             }
             ret = unlinkat(fd, VIRTFS_META_DIR, AT_REMOVEDIR);
             close_preserve_errno(fd);
             if (ret < 0 && errno != ENOENT) {
-                goto err_out;
+                return ret;
             }
         }
         map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR);
hw/9pfs/9p-local.c +2 -2
@@ -1107,16 +1107,14 @@ static int local_unlinkat_common(FsContext *ctx, int
 dirfd, const char *name, ret = unlinkat(map_dirfd, name, 0);
             close_preserve_errno(map_dirfd);
             if (ret < 0 && errno != ENOENT) {
-                goto err_out;
+                return ret;
             }
         } else if (errno != ENOENT) {
-            goto err_out;
+            return ret;

hw/9pfs/9p-local.c static int local_unlinkat_common(FsContext *ctx, int · line 1120

Quoted 10 lines
hw/9pfs/9p-local.c +1 -3
         }
     }
 
-    ret = unlinkat(dirfd, name, flags);
-err_out:
-    return ret;
+    return unlinkat(dirfd, name, flags);
 }
 
 static int local_remove(FsContext *ctx, const char *path)

Well, personally I don't see any improvement by these changes. It probably makes the code slightly more elegant, but IMO not more readable. And return constructed functions vs. jump to label constructed functions are more likely to gather missing-cleanup bugs.

At least this patch does not cause any behaviour change, so I leave that up to you Greg to decide. ;-)

Best regards,
Christian Schoenebeck

Reviewed-by on v1 31/59
#55 lore raw

Re: [PATCH v1 31/59] util/aio-posix.c: remove unneeded 'out' label in aio_epoll

In reply to Daniel Henrique Barboza
Quoted 22 lines · Daniel Henrique Barboza

'out' can be replaced by 'return ret'.

---
 util/aio-posix.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
util/aio-posix.c +1 -1
index a4977f538e..7c4cfea8ce 100644
@@ -121,7 +121,7 @@ static int aio_epoll(AioContext *ctx, GPollFD *pfds,
                          ARRAY_SIZE(events),
                          timeout);
         if (ret <= 0) {
-            goto out;
+            return ret;
         }
         for (i = 0; i < ret; i++) {
             int ev = events[i].events;

util/aio-posix.c static int aio_epoll(AioContext *ctx, GPollFD *pfds, · line 136

Quoted 6 lines
util/aio-posix.c +0 -1
@@ -132,7 +132,6 @@ static int aio_epoll(AioContext *ctx, GPollFD *pfds,
                 (ev & EPOLLERR ? G_IO_ERR : 0);
         }
     }
-out:
     return ret;
 }
#83 lore raw

Re: [PATCH v1 45/59] 9pfs/9p.c: remove unneeded labels

In reply to Daniel Henrique Barboza
Quoted 45 lines · On Montag, 6. Januar 2020 19:24:11 CET Daniel Henrique Barboza wrote:

'out' label in v9fs_xattr_write() and 'out_nofid' label in v9fs_complete_rename() can be replaced by appropriate return calls.

---
 hw/9pfs/9p.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
hw/9pfs/9p.c +1 -2
index 520177f40c..be2beba4cd 100644
@@ -2464,8 +2464,7 @@ static int v9fs_xattr_write(V9fsState *s, V9fsPDU
 *pdu, V9fsFidState *fidp,
 
 
     if (fidp->fs.xattr.len < off) {
-        err = -ENOSPC;
-        goto out;
+        return -ENOSPC;
     }
     write_count = fidp->fs.xattr.len - off;
     if (write_count > count) {
hw/9pfs/9p.c +2 -3
@@ -2491,7 +2490,7 @@ static int v9fs_xattr_write(V9fsState *s, V9fsPDU
 *pdu, V9fsFidState *fidp, off += to_copy;
         write_count -= to_copy;
     }
-out:
+
     return err;
 }
 
@@ -3056,8 +3055,7 @@ static int coroutine_fn v9fs_complete_rename(V9fsPDU
 *pdu, V9fsFidState *fidp, if (newdirfid != -1) {
         dirfidp = get_fid(pdu, newdirfid);
         if (dirfidp == NULL) {
-            err = -ENOENT;
-            goto out_nofid;
+            return -ENOENT;
         }
         if (fidp->fid_type != P9_FID_NONE) {
             err = -EINVAL;

hw/9pfs/9p.c out: · line 3102

Quoted 6 lines
hw/9pfs/9p.c +0 -1
@@ -3100,7 +3098,6 @@ out:
         put_fid(pdu, dirfidp);
     }
     v9fs_path_free(&new_path);
-out_nofid:
     return err;
 }

Same as with patch 44: IMO not any improvement, but also not any behaviour change at least. So it's up to you Greg.

Best regards,
Christian Schoenebeck

Reviewed-by on v1 37/59
#62 lore raw

Re: [PATCH v1 37/59] s390x/event-facility.c: remove unneeded labels

In reply to Daniel Henrique Barboza
Quoted 80 lines · Daniel Henrique Barboza

'out' label from write_event_mask(), handle_sccb_read_events() and write_event_data() can be replaced by 'return'.

CC Cornelia Huck <[email protected]>
CC Halil Pasic <[email protected]>
CC Christian Borntraeger <[email protected]>
---
 hw/s390x/event-facility.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)
hw/s390x/event-facility.c +6 -12
index 6afe278cad..f3b9661f32 100644
@@ -182,11 +182,11 @@ static void write_event_data(SCLPEventFacility *ef, SCCB *sccb)
 {
     if (sccb->h.function_code != SCLP_FC_NORMAL_WRITE) {
         sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_FUNCTION);
-        goto out;
+        return;
     }
     if (be16_to_cpu(sccb->h.length) < 8) {
         sccb->h.response_code = cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LENGTH);
-        goto out;
+        return;
     }
     /* first do a sanity check of the write events */
     sccb->h.response_code = cpu_to_be16(write_event_length_check(sccb));
@@ -196,9 +196,6 @@ static void write_event_data(SCLPEventFacility *ef, SCCB *sccb)
         sccb->h.response_code =
                 cpu_to_be16(handle_sccb_write_events(ef, sccb));
     }
-
-out:
-    return;
 }
 
 static uint16_t handle_sccb_read_events(SCLPEventFacility *ef, SCCB *sccb,
@@ -262,7 +259,7 @@ static void read_event_data(SCLPEventFacility *ef, SCCB *sccb)
 
     if (be16_to_cpu(sccb->h.length) != SCCB_SIZE) {
         sccb->h.response_code = cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LENGTH);
-        goto out;
+        return;
     }
 
     sclp_cp_receive_mask = ef->receive_mask;
@@ -280,18 +277,15 @@ static void read_event_data(SCLPEventFacility *ef, SCCB *sccb)
             (sclp_active_selection_mask & ~sclp_cp_receive_mask)) {
             sccb->h.response_code =
                     cpu_to_be16(SCLP_RC_INVALID_SELECTION_MASK);
-            goto out;
+            return;
         }
         break;
     default:
         sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_FUNCTION);
-        goto out;
+        return;
     }
     sccb->h.response_code = cpu_to_be16(
             handle_sccb_read_events(ef, sccb, sclp_active_selection_mask));
-
-out:
-    return;
 }
 
 static void write_event_mask(SCLPEventFacility *ef, SCCB *sccb)
@@ -303,7 +297,7 @@ static void write_event_mask(SCLPEventFacility *ef, SCCB *sccb)
     if (!mask_length || (mask_length > SCLP_EVENT_MASK_LEN_MAX) ||
         ((mask_length != 4) && !ef->allow_all_mask_sizes)) {
         sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_MASK_LENGTH);
-        goto out;
+        return;
     }
 
     /*

hw/s390x/event-facility.c static void write_event_mask(SCLPEventFacility *ef, SCCB *sccb) · line 327

Quoted 9 lines
hw/s390x/event-facility.c +0 -3
@@ -328,9 +322,6 @@ static void write_event_mask(SCLPEventFacility *ef, SCCB *sccb)
 
     sccb->h.response_code = cpu_to_be16(SCLP_RC_NORMAL_COMPLETION);
     ef->mask_length = mask_length;
-
-out:
-    return;
 }
 
 /* qemu object creation and initialization functions */
Reviewed-by on v1 38/59
#66 lore raw

Re: [PATCH v1 38/59] s390x/sclp.c: remove unneeded label in sclp_service_call()

In reply to Daniel Henrique Barboza
Quoted 56 lines · Daniel Henrique Barboza

'out' label can be replaced by 'return' with the appropriate value. The 'r' integer, which is used solely to set the return value for this label, can also be removed.

CC Cornelia Huck <[email protected]>
CC Halil Pasic <[email protected]>
CC Christian Borntraeger <[email protected]>
---
 hw/s390x/sclp.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
hw/s390x/sclp.c +4 -9
index f57ce7b739..af0bfbc2ec 100644
@@ -197,24 +197,20 @@ int sclp_service_call(CPUS390XState *env, uint64_t sccb, uint32_t code)
 {
     SCLPDevice *sclp = get_sclp_device();
     SCLPDeviceClass *sclp_c = SCLP_GET_CLASS(sclp);
-    int r = 0;
     SCCB work_sccb;
 
     hwaddr sccb_len = sizeof(SCCB);
 
     /* first some basic checks on program checks */
     if (env->psw.mask & PSW_MASK_PSTATE) {
-        r = -PGM_PRIVILEGED;
-        goto out;
+        return -PGM_PRIVILEGED;
     }
     if (cpu_physical_memory_is_io(sccb)) {
-        r = -PGM_ADDRESSING;
-        goto out;
+        return -PGM_ADDRESSING;
     }
     if ((sccb & ~0x1fffUL) == 0 || (sccb & ~0x1fffUL) == env->psa
         || (sccb & ~0x7ffffff8UL) != 0) {
-        r = -PGM_SPECIFICATION;
-        goto out;
+        return -PGM_SPECIFICATION;
     }
 
     /*
@@ -226,8 +222,7 @@ int sclp_service_call(CPUS390XState *env, uint64_t sccb, uint32_t code)
 
     /* Valid sccb sizes */
     if (be16_to_cpu(work_sccb.h.length) < sizeof(SCCBHeader)) {
-        r = -PGM_SPECIFICATION;
-        goto out;
+        return -PGM_SPECIFICATION;
     }
 
     switch (code & SCLP_CMD_CODE_MASK) {

hw/s390x/sclp.c out_write: · line 258

Quoted 9 lines
hw/s390x/sclp.c +1 -2
@@ -257,8 +252,7 @@ out_write:
 
     sclp_c->service_interrupt(sclp, sccb);
 
-out:
-    return r;
+    return 0;
 }
 
 static void service_interrupt(SCLPDevice *sclp, uint32_t sccb)
#80 lore raw

Re: [PATCH v1 44/59] 9p-local.c: remove unneeded label in local_unlinkat_common()

In reply to Daniel Henrique Barboza
Quoted 29 lines · On Mon, 6 Jan 2020 15:24:10 -0300 Daniel Henrique Barboza…

'err_out' can be replaced by 'return ret' in the error conditions the jump was being made.

---
 hw/9pfs/9p-local.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
hw/9pfs/9p-local.c +2 -2
index ca641390fb..f9bdd2ad7c 100644
@@ -1094,12 +1094,12 @@ static int local_unlinkat_common(FsContext *ctx, int dirfd, const char *name,
 
             fd = openat_dir(dirfd, name);
             if (fd == -1) {
-                goto err_out;
+                return ret;
             }
             ret = unlinkat(fd, VIRTFS_META_DIR, AT_REMOVEDIR);
             close_preserve_errno(fd);
             if (ret < 0 && errno != ENOENT) {
-                goto err_out;
+                return ret;
             }
         }
         map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR);

hw/9pfs/9p-local.c static int local_unlinkat_common(FsContext *ctx, int dirfd, const char *name, · line 1113

Quoted 9 lines
hw/9pfs/9p-local.c +2 -2
@@ -1107,16 +1107,14 @@ static int local_unlinkat_common(FsContext *ctx, int dirfd, const char *name,
             ret = unlinkat(map_dirfd, name, 0);
             close_preserve_errno(map_dirfd);
             if (ret < 0 && errno != ENOENT) {
-                goto err_out;
+                return ret;
             }
         } else if (errno != ENOENT) {
-            goto err_out;
+            return ret;

Ouch... I now realize we can get there with ret == 0 when unlinking a directory in mapped-file mode. The function will wrongly return success despite the failure.... Since this function is supposed to return -1 on error, I suggest to do that instead of return ret, and to drop the initialization of ret to -1, which wouldn't be needed anymore.

Since this would fix a bug it makes sense to post it separately from this series. Rewrite the title/changelog accordingly and I'll merge it via the 9p tree.

Quoted 10 lines
hw/9pfs/9p-local.c +1 -3
         }
     }
 
-    ret = unlinkat(dirfd, name, flags);
-err_out:
-    return ret;
+    return unlinkat(dirfd, name, flags);
 }
 
 static int local_remove(FsContext *ctx, const char *path)
#79 lore raw

Re: [PATCH v1 44/59] 9p-local.c: remove unneeded label in local_unlinkat_common()

In reply to Christian Schoenebeck
Quoted 56 lines · On Tue, 07 Jan 2020 13:04:20 +0100 Christian Schoenebeck…
Quoted 39 lines · On Montag, 6. Januar 2020 19:24:10 CET Daniel Henrique Barboza wrote:

'err_out' can be replaced by 'return ret' in the error conditions the jump was being made.

---
 hw/9pfs/9p-local.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
hw/9pfs/9p-local.c +2 -2
index ca641390fb..f9bdd2ad7c 100644
@@ -1094,12 +1094,12 @@ static int local_unlinkat_common(FsContext *ctx, int
 dirfd, const char *name,
 
             fd = openat_dir(dirfd, name);
             if (fd == -1) {
-                goto err_out;
+                return ret;
             }
             ret = unlinkat(fd, VIRTFS_META_DIR, AT_REMOVEDIR);
             close_preserve_errno(fd);
             if (ret < 0 && errno != ENOENT) {
-                goto err_out;
+                return ret;
             }
         }
         map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR);
hw/9pfs/9p-local.c +2 -2
@@ -1107,16 +1107,14 @@ static int local_unlinkat_common(FsContext *ctx, int
 dirfd, const char *name, ret = unlinkat(map_dirfd, name, 0);
             close_preserve_errno(map_dirfd);
             if (ret < 0 && errno != ENOENT) {
-                goto err_out;
+                return ret;
             }
         } else if (errno != ENOENT) {
-            goto err_out;
+            return ret;

hw/9pfs/9p-local.c static int local_unlinkat_common(FsContext *ctx, int · line 1120

Quoted 10 lines
hw/9pfs/9p-local.c +1 -3
         }
     }
 
-    ret = unlinkat(dirfd, name, flags);
-err_out:
-    return ret;
+    return unlinkat(dirfd, name, flags);
 }
 
 static int local_remove(FsContext *ctx, const char *path)

Well, personally I don't see any improvement by these changes. It probably makes the code slightly more elegant, but IMO not more readable. And return constructed functions vs. jump to label constructed functions are more likely to gather missing-cleanup bugs.

Quoted 3 lines

At least this patch does not cause any behaviour change, so I leave that up to you Greg to decide. ;-)

I don't care that much but in the present case, the function has a bug that can be fixed with a variant of this patch if 'goto err_out' is turned into 'return -1'. I've hence asked Daniel to move this patch out of the series and to turn it into a real fix that I'll merge directly.

Quoted 4 lines

Best regards,
Christian Schoenebeck

#81 lore raw

Re: [PATCH v1 44/59] 9p-local.c: remove unneeded label in local_unlinkat_common()

In reply to Greg Kurz
Quoted 48 lines · Greg Kurz
Quoted 29 lines · On Mon, 6 Jan 2020 15:24:10 -0300 Daniel Henrique Barboza…

'err_out' can be replaced by 'return ret' in the error conditions the jump was being made.

---
  hw/9pfs/9p-local.c | 12 +++++-------
  1 file changed, 5 insertions(+), 7 deletions(-)
hw/9pfs/9p-local.c +2 -2
index ca641390fb..f9bdd2ad7c 100644
@@ -1094,12 +1094,12 @@ static int local_unlinkat_common(FsContext *ctx, int dirfd, const char *name,
 
              fd = openat_dir(dirfd, name);
              if (fd == -1) {
-                goto err_out;
+                return ret;
              }
              ret = unlinkat(fd, VIRTFS_META_DIR, AT_REMOVEDIR);
              close_preserve_errno(fd);
              if (ret < 0 && errno != ENOENT) {
-                goto err_out;
+                return ret;
              }
          }
          map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR);

hw/9pfs/9p-local.c static int local_unlinkat_common(FsContext *ctx, int dirfd, const char *name, · line 1113

Quoted 9 lines
hw/9pfs/9p-local.c +2 -2
@@ -1107,16 +1107,14 @@ static int local_unlinkat_common(FsContext *ctx, int dirfd, const char *name,
              ret = unlinkat(map_dirfd, name, 0);
              close_preserve_errno(map_dirfd);
              if (ret < 0 && errno != ENOENT) {
-                goto err_out;
+                return ret;
              }
          } else if (errno != ENOENT) {
-            goto err_out;
+            return ret;

Ouch... I now realize we can get there with ret == 0 when unlinking a directory in mapped-file mode. The function will wrongly return success despite the failure.... Since this function is supposed to return -1 on error, I suggest to do that instead of return ret, and to drop the initialization of ret to -1, which wouldn't be needed anymore.

Quoted 3 lines

Since this would fix a bug it makes sense to post it separately from this series. Rewrite the title/changelog accordingly and I'll merge it via the 9p tree.

Got it. I'll repost it separately with an updated title and commit msg.

Thanks,

Daniel

Quoted 12 lines
Quoted 11 lines
hw/9pfs/9p-local.c +1 -3
          }
      }
 
-    ret = unlinkat(dirfd, name, flags);
-err_out:
-    return ret;
+    return unlinkat(dirfd, name, flags);
  }
 
  static int local_remove(FsContext *ctx, const char *path)
Reviewed-by on v1 17/59
#36 lore raw

Re: [PATCH v1 17/59] block/dmg.c: remove unneeded 'fail' label in dmg_read_mish_block()

In reply to Daniel Henrique Barboza
Quoted 9 lines · Daniel Henrique Barboza

Both the 'fail' label and 'ret' variable can be removed from the function. Instead, call 'return -EINVAL' in the error conditions.

---
 block/dmg.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
Reviewed-by on v1 5/59
#10 lore raw

Re: [PATCH v1 05/59] ram.c: remove unneeded labels

In reply to Daniel Henrique Barboza
Quoted 10 lines · Daniel Henrique Barboza

ram_save_queue_pages() has an 'err' label that can be replaced by 'return -1' instead.

Same thing with ram_discard_range(), and in this case we can also get rid of the 'ret' variable and return either '-1' on error or the result of ram_block_discard_range().

CC Juan Quintela <[email protected]>
CC Dr. David Alan Gilbert <[email protected]>

queued

#63 lore raw

Re: [PATCH v1 37/59] s390x/event-facility.c: remove unneeded labels

In reply to Daniel Henrique Barboza
Quoted 30 lines · On Mon, 6 Jan 2020 15:24:03 -0300 Daniel Henrique Barboza…

'out' label from write_event_mask(), handle_sccb_read_events() and write_event_data() can be replaced by 'return'.

CC Cornelia Huck <[email protected]>
CC Halil Pasic <[email protected]>
CC Christian Borntraeger <[email protected]>
---
 hw/s390x/event-facility.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)
hw/s390x/event-facility.c +2 -2
index 6afe278cad..f3b9661f32 100644
@@ -182,11 +182,11 @@ static void write_event_data(SCLPEventFacility *ef, SCCB *sccb)
 {
     if (sccb->h.function_code != SCLP_FC_NORMAL_WRITE) {
         sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_FUNCTION);
-        goto out;
+        return;
     }
     if (be16_to_cpu(sccb->h.length) < 8) {
         sccb->h.response_code = cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LENGTH);
-        goto out;
+        return;
     }
     /* first do a sanity check of the write events */
     sccb->h.response_code = cpu_to_be16(write_event_length_check(sccb));

hw/s390x/event-facility.c static void write_event_data(SCLPEventFacility *ef, SCCB *sccb) · line 199

Quoted 7 lines
hw/s390x/event-facility.c +0 -3
@@ -196,9 +196,6 @@ static void write_event_data(SCLPEventFacility *ef, SCCB *sccb)
         sccb->h.response_code =
                 cpu_to_be16(handle_sccb_write_events(ef, sccb));
     }
-
-out:
-    return;
 }

I'm fine with the changes to write_event_data().

Quoted 20 lines
hw/s390x/event-facility.c +2 -2
 static uint16_t handle_sccb_read_events(SCLPEventFacility *ef, SCCB *sccb,
@@ -262,7 +259,7 @@ static void read_event_data(SCLPEventFacility *ef, SCCB *sccb)
 
     if (be16_to_cpu(sccb->h.length) != SCCB_SIZE) {
         sccb->h.response_code = cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LENGTH);
-        goto out;
+        return;
     }
 
     sclp_cp_receive_mask = ef->receive_mask;
@@ -280,18 +277,15 @@ static void read_event_data(SCLPEventFacility *ef, SCCB *sccb)
             (sclp_active_selection_mask & ~sclp_cp_receive_mask)) {
             sccb->h.response_code =
                     cpu_to_be16(SCLP_RC_INVALID_SELECTION_MASK);
-            goto out;
+            return;
         }
         break;
     default:

hw/s390x/event-facility.c static void read_event_data(SCLPEventFacility *ef, SCCB *sccb) · line 289

Quoted 10 lines
hw/s390x/event-facility.c +1 -4
         sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_FUNCTION);
-        goto out;
+        return;
     }
     sccb->h.response_code = cpu_to_be16(
             handle_sccb_read_events(ef, sccb, sclp_active_selection_mask));
-
-out:
-    return;
 }

I think read_event_data() is still a bit confusing, even if we get rid of the 'out:' label, as the flow remains the same. How about something like the following, which makes it clear that we handle the sccb events for unconditional read and for a selective read with a valid mask:

hw/s390x/event-facility.c +8 -12
index 6afe278cad15..877721d6601e 100644
@@ -262,17 +262,17 @@ static void read_event_data(SCLPEventFacility *ef, SCCB *sccb)
 
     if (be16_to_cpu(sccb->h.length) != SCCB_SIZE) {
         sccb->h.response_code = cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LENGTH);
-        goto out;
+        return;
     }
 
-    sclp_cp_receive_mask = ef->receive_mask;
-
-    /* get active selection mask */
     switch (sccb->h.function_code) {
     case SCLP_UNCONDITIONAL_READ:
-        sclp_active_selection_mask = sclp_cp_receive_mask;
+        sccb->h.response_code = cpu_to_be16(
+            handle_sccb_read_events(ef, sccb, ef->receive_mask));
         break;
     case SCLP_SELECTIVE_READ:
+        sclp_cp_receive_mask = ef->receive_mask;
+        /* get active selection mask */
         copy_mask((uint8_t *)&sclp_active_selection_mask, (uint8_t *)&red->mask,
                   sizeof(sclp_active_selection_mask), ef->mask_length);
         sclp_active_selection_mask = be64_to_cpu(sclp_active_selection_mask);
@@ -280,18 +280,14 @@ static void read_event_data(SCLPEventFacility *ef, SCCB *sccb)
             (sclp_active_selection_mask & ~sclp_cp_receive_mask)) {
             sccb->h.response_code =
                     cpu_to_be16(SCLP_RC_INVALID_SELECTION_MASK);
-            goto out;
+        } else {
+            sccb->h.response_code = cpu_to_be16(
+                handle_sccb_read_events(ef, sccb, sclp_active_selection_mask));
         }
         break;
     default:
         sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_FUNCTION);
-        goto out;
     }
-    sccb->h.response_code = cpu_to_be16(
-            handle_sccb_read_events(ef, sccb, sclp_active_selection_mask));
-
-out:
-    return;
 }
 
 static void write_event_mask(SCLPEventFacility *ef, SCCB *sccb)
Quoted 12 lines
hw/s390x/event-facility.c +1 -1
 static void write_event_mask(SCLPEventFacility *ef, SCCB *sccb)
@@ -303,7 +297,7 @@ static void write_event_mask(SCLPEventFacility *ef, SCCB *sccb)
     if (!mask_length || (mask_length > SCLP_EVENT_MASK_LEN_MAX) ||
         ((mask_length != 4) && !ef->allow_all_mask_sizes)) {
         sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_MASK_LENGTH);
-        goto out;
+        return;
     }
 
     /*

hw/s390x/event-facility.c static void write_event_mask(SCLPEventFacility *ef, SCCB *sccb) · line 327

Quoted 9 lines
hw/s390x/event-facility.c +0 -3
@@ -328,9 +322,6 @@ static void write_event_mask(SCLPEventFacility *ef, SCCB *sccb)
 
     sccb->h.response_code = cpu_to_be16(SCLP_RC_NORMAL_COMPLETION);
     ef->mask_length = mask_length;
-
-out:
-    return;
 }
 
 /* qemu object creation and initialization functions */

The changes to write_event_mask() look fine to me as well.

#72 lore raw

Re: [PATCH v1 41/59] intc/s390_flic_kvm.c: remove unneeded label in kvm_flic_load()

In reply to Daniel Henrique Barboza
Quoted 4 lines · On Mon, 6 Jan 2020 15:24:07 -0300 Daniel Henrique Barboza…

'out' label can be replaced by 'return' with the apropriate value that is set by 'r' right before the jump.

Christian Borntraeger <[email protected]>

I think something went wrong here; adding some cc:s.

Quoted 31 lines
---
 hw/intc/s390_flic_kvm.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
hw/intc/s390_flic_kvm.c +3 -6
index dddd33ea61..2e1e70c61d 100644
@@ -439,17 +439,14 @@ static int kvm_flic_load(QEMUFile *f, void *opaque, size_t size,
     count = qemu_get_be64(f);
     len = count * sizeof(struct kvm_s390_irq);
     if (count == FLIC_FAILED) {
-        r = -EINVAL;
-        goto out;
+        return -EINVAL;
     }
     if (count == 0) {
-        r = 0;
-        goto out;
+        return 0;
     }
     buf = g_try_malloc0(len);
     if (!buf) {
-        r = -ENOMEM;
-        goto out;
+        return -ENOMEM;
     }
 
     if (qemu_get_buffer(f, (uint8_t *) buf, len) != len) {

hw/intc/s390_flic_kvm.c static int kvm_flic_load(QEMUFile *f, void *opaque, size_t size, · line 462

Quoted 7 lines
hw/intc/s390_flic_kvm.c +0 -1
@@ -460,7 +457,6 @@ static int kvm_flic_load(QEMUFile *f, void *opaque, size_t size,
 
 out_free:
     g_free(buf);
-out:
     return r;
 }
 

Looks fine to me; will apply unless someone sees an issue.

#67 lore raw

Re: [PATCH v1 38/59] s390x/sclp.c: remove unneeded label in sclp_service_call()

In reply to Daniel Henrique Barboza
Quoted 11 lines · On Mon, 6 Jan 2020 15:24:04 -0300 Daniel Henrique Barboza…

'out' label can be replaced by 'return' with the appropriate value. The 'r' integer, which is used solely to set the return value for this label, can also be removed.

CC Cornelia Huck <[email protected]>
CC Halil Pasic <[email protected]>
CC Christian Borntraeger <[email protected]>
---
 hw/s390x/sclp.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

Thanks, applied.

Acked-by
#84 lore raw

Re: [PATCH v1 45/59] 9pfs/9p.c: remove unneeded labels

In reply to Christian Schoenebeck
Quoted 47 lines · On Tue, 07 Jan 2020 13:14:20 +0100 Christian Schoenebeck…
Quoted 46 lines · On Montag, 6. Januar 2020 19:24:11 CET Daniel Henrique Barboza wrote:

'out' label in v9fs_xattr_write() and 'out_nofid' label in v9fs_complete_rename() can be replaced by appropriate return calls.

---
 hw/9pfs/9p.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
hw/9pfs/9p.c +1 -2
index 520177f40c..be2beba4cd 100644
@@ -2464,8 +2464,7 @@ static int v9fs_xattr_write(V9fsState *s, V9fsPDU
 *pdu, V9fsFidState *fidp,
 
 
     if (fidp->fs.xattr.len < off) {
-        err = -ENOSPC;
-        goto out;
+        return -ENOSPC;
     }
     write_count = fidp->fs.xattr.len - off;
     if (write_count > count) {
hw/9pfs/9p.c +2 -3
@@ -2491,7 +2490,7 @@ static int v9fs_xattr_write(V9fsState *s, V9fsPDU
 *pdu, V9fsFidState *fidp, off += to_copy;
         write_count -= to_copy;
     }
-out:
+
     return err;
 }
 
@@ -3056,8 +3055,7 @@ static int coroutine_fn v9fs_complete_rename(V9fsPDU
 *pdu, V9fsFidState *fidp, if (newdirfid != -1) {
         dirfidp = get_fid(pdu, newdirfid);
         if (dirfidp == NULL) {
-            err = -ENOENT;
-            goto out_nofid;
+            return -ENOENT;
         }
         if (fidp->fid_type != P9_FID_NONE) {
             err = -EINVAL;
@@ -3100,7 +3098,6 @@ out:
         put_fid(pdu, dirfidp);
Quoted 9 lines

hw/9pfs/9p.c out: · line 3102

Quoted 5 lines
hw/9pfs/9p.c +0 -1
     }
     v9fs_path_free(&new_path);
-out_nofid:
     return err;
 }

Same as with patch 44: IMO not any improvement, but also not any behaviour change at least. So it's up to you Greg.

I don't really care either but as you say it doesn't change behaviour, and and the diffstat is nice :)

Quoted 4 lines

Best regards,
Christian Schoenebeck

#64 lore raw

Re: [PATCH v1 37/59] s390x/event-facility.c: remove unneeded labels

In reply to Cornelia Huck
Quoted 3 lines · Cornelia Huck

On Mon, 6 Jan 2020 15:24:03 -0300
Daniel Henrique Barboza <[email protected]> wrote:

[..]

Quoted 4 lines

I think read_event_data() is still a bit confusing, even if we get rid of the 'out:' label, as the flow remains the same. How about something like the following, which makes it clear that we handle the sccb events for unconditional read and for a selective read with a valid mask:

The code reading is better with your suggestion indeed.

I'll re-send this patch with this new read_event_data() flow.

Thanks,

DHB

#105 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 20 lines · Philippe Mathieu-Daudé
Quoted 19 lines · Kevin Wolf

Am 06.01.2020 um 21:35 hat Daniel Henrique Barboza geschrieben:

Quoted 17 lines · Corey Minyard
Quoted 2 lines · Daniel Henrique Barboza
Quoted 1 line

Hello,

[...]

Quoted 13 lines
Quoted 4 lines

Which is cleaner and requires less brain cycles to wonder whether the 'cleanup' label does anything special, such as a heap memory cleanup.

I would disagree with this analysis.  To me, I often wonder when I have to add cleanup code to a routine whether there is some hidden return in the middle of the function.  That's a lot harder to spot than just looking for the cleanup label at the end of the function to see what it does.  For non-trivial functions I prefer to have one point of return at the end (and maybe some minor checks with returns right at the beginning). I'm not adamant about this, just my opinion.

Quoted 9 lines
Quoted 4 lines

It depends on the case, but yes, I had similar thoughts, at least when we're talking about non-trivial parts of a function. (Very short functions of just some initial checks returning directly are usually fine.)

From a debugging point of view, and when adding trace-events, it is easier to have a single function exit path.

In various functions modified by your patches, we can split big functions in smaller ones and avoid the goto label.

Splitting and refactoring big funcitons wasn't the initial idea of this work, but I see no problems in doing it. Care to point out where did you see such cases?

Thanks,

DHB

#110 lore raw
In reply to Max Reitz
Quoted 1 line · Max Reitz

On 06.01.20 19:23, Daniel Henrique Barboza wrote:

[...]

Quoted 20 lines

For me, it doesn’t require any brain cycles, because I generally just assume the cleanup label will do the right thing. OTOH, a return statement may make me invest some some brain cycles, because maybe there is something to be cleaned up and it isn’t done here.

Quoted 11 lines

Another common case uses a variable to set a return value, generally an error, then return:

if () {
     ret = -ENOENT;
     goto out;
}
[..]
  out:
     return ret;
Quoted 3 lines

Likewise, it is clearer to just 'return -ENOENT' instead of jumping to a label. There are other cases being handled in these patches, but these are the most common.

Quoted 5 lines

I find it clearer from the perspective of “less LoC”, but I find it less clear from the perspective of “Is this the right way to clean up?”.

Even on patch 15 (which you say isn’t too much of a debate), I don’t find the change to make things any clearer. Just less verbose.

Fair enough. As I said in the cover, all this patches makes no functional changes, just a clean up aiming for less LoC (and more clarity, at least in my opinion).

I am aware all the good sides of keeping the code as is, such as being easier to debug (although I would argue that an explicit trace_event call is better than keeping verbose code 'just in case'), or goto usage to keep just one return statement per function.

I am also aware that the existing QEMU code base has a mesh of styles. What I'm proposing here isn't a 'my way is better' case by any means, but it's not something unprecedented in the existing code base either. Since there's no QEMU code guideline imposing that a function should have only one 'return' statement regardless of how many 'goto' calls are needed, or a guideline that discourages 'goto' calls regardless of how many 'return' calls are needed, in the end it's a matter of seeing what fits the function/code better. In the maintainers opinion, of course.

Thanks,

DHB

Quoted 8 lines

I suppose none of this would matter if we used __attribute__((cleanup)) everywhere and simply never had to clean up anything manually. But as long as we don’t and require cleanup paths in many places, I disagree that they require more brain cycles than plain return statements.

Max

Reviewed-by on v1 6/59
#12 lore raw

Re: [PATCH v1 06/59] mips-semi.c: remove 'uhi_done' label in helper_do_semihosting()

In reply to Daniel Henrique Barboza
Quoted 12 lines · Daniel Henrique Barboza

The label 'uhi_done' is a simple 'return' call and can be removed for a bit more clarity in the code.

CC Aurelien Jarno <[email protected]>
CC Aleksandar Markovic <[email protected]>
CC Aleksandar Rikalo <[email protected]>
---
 target/mips/mips-semi.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
Quoted 79 lines
target/mips/mips-semi.c +7 -9
index 35bdfd7c77..10a710c1e8 100644
@@ -218,7 +218,7 @@ static int copy_argn_to_target(CPUMIPSState *env, int
 arg_num,
         if (!p) {                               \
             gpr[2] = -1;                        \
             gpr[3] = EFAULT;                    \
-            goto uhi_done;                      \
+            return;                             \
         }                                       \
     } while (0)
@@ -228,14 +228,14 @@ static int copy_argn_to_target(CPUMIPSState *env,
 int arg_num,
         if (!p) {                                       \
             gpr[2] = -1;                                \
             gpr[3] = EFAULT;                            \
-            goto uhi_done;                              \
+            return;                                     \
         }                                               \
         p2 = lock_user_string(addr2);                   \
         if (!p2) {                                      \
             unlock_user(p, addr, 0);                    \
             gpr[2] = -1;                                \
             gpr[3] = EFAULT;                            \
-            goto uhi_done;                              \
+            return;                                     \
         }                                               \
     } while (0)
@@ -272,7 +272,7 @@ void helper_do_semihosting(CPUMIPSState *env)
         if (gpr[4] < 3) {
             /* ignore closing stdin/stdout/stderr */
             gpr[2] = 0;
-            goto uhi_done;
+            return;
         }
         gpr[2] = close(gpr[4]);
         gpr[3] = errno_mips(errno);
@@ -302,7 +302,7 @@ void helper_do_semihosting(CPUMIPSState *env)
             gpr[2] = fstat(gpr[4], &sbuf);
             gpr[3] = errno_mips(errno);
             if (gpr[2]) {
-                goto uhi_done;
+                return;
             }
             gpr[2] = copy_stat_to_target(env, &sbuf, gpr[5]);
             gpr[3] = errno_mips(errno);
@@ -314,14 +314,14 @@ void helper_do_semihosting(CPUMIPSState *env)
     case UHI_argnlen:
         if (gpr[4] >= semihosting_get_argc()) {
             gpr[2] = -1;
-            goto uhi_done;
+            return;
         }
         gpr[2] = strlen(semihosting_get_arg(gpr[4]));
         break;
     case UHI_argn:
         if (gpr[4] >= semihosting_get_argc()) {
             gpr[2] = -1;
-            goto uhi_done;
+            return;
         }
         gpr[2] = copy_argn_to_target(env, gpr[4], gpr[5]);
         break;
@@ -369,6 +369,5 @@ void helper_do_semihosting(CPUMIPSState *env)
         fprintf(stderr, "Unknown UHI operation %d\n", op);
         abort();
     }
-uhi_done:
     return;
 }
--

2.24.1

Reviewed-by on v1 15/59
#33 lore raw

RE: [PATCH v1 15/59] block/blkreplay.c: remove unneeded 'fail' label in blkreplay_open()

In reply to Daniel Henrique Barboza
Quoted 6 lines

From: Daniel Henrique Barboza [mailto:[email protected]]
Sent: Monday, January 06, 2020 9:24 PM
To: [email protected]
Cc: [email protected]; Daniel Henrique Barboza; Pavel Dovgalyuk; Paolo Bonzini
Subject: [PATCH v1 15/59] block/blkreplay.c: remove unneeded 'fail' label in blkreplay_open()

Quoted 7 lines

Both the 'fail' label and the 'ret' variable can be removed. Use 'return -EINVAL' in the error condition and 'return 0' in the end of the function.

CC Pavel Dovgalyuk <[email protected]>
CC Paolo Bonzini <[email protected]>
Quoted 35 lines
---
 block/blkreplay.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
block/blkreplay.c +2 -7
index c96ac8f4bc..d8c4c311f3 100644
@@ -24,23 +24,19 @@ static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags,
                           Error **errp)
 {
     Error *local_err = NULL;
-    int ret;
 
     /* Open the image file */
     bs->file = bdrv_open_child(NULL, options, "image",
                                bs, &child_file, false, &local_err);
     if (local_err) {
-        ret = -EINVAL;
         error_propagate(errp, local_err);
-        goto fail;
+        return -EINVAL;
     }
 
     bs->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED;
     bs->supported_zero_flags = BDRV_REQ_WRITE_UNCHANGED;
 
-    ret = 0;
-fail:
-    return ret;
+    return 0;
 }
 
 static int64_t blkreplay_getlength(BlockDriverState *bs)
--
Quoted 1 line

2.24.1

Pavel Dovgalyuk

#111 lore raw
In reply to Daniel Henrique Barboza
Quoted 16 lines · Daniel Henrique Barboza

Hello,

This is the type of cleanup I've contributed to Libvirt during the last year. Figured QEMU also deserves the same care.

The idea here is remove unneeded labels. By 'unneeded' I mean labels that does nothing but a 'return' call. One common case is something like this:

if ()

     goto cleanup;
[...]
  cleanup:
     return 0;
Quoted 6 lines

This code can be simplified to:

if ()

     return 0;

How much of this work is done manually, and how much via Coccinelle?

Quoted 5 lines
  qga/commands-win32.c          | 17 ++++---
  target/mips/mips-semi.c       | 15 +++---
  target/unicore32/softmmu.c    | 23 +++-------
  util/aio-posix.c              |  3 +-
  util/module.c                 | 11 ++---

Hmm, no change to scripts/coccinelle, so presumably all manual :(

If we have a Coccinelle script that performs this transformation, we are more likely to be able to catch all places in the tree that would benefit (rather than relying on grep calls or other manual inspection), and more importantly, we can repeat the effort periodically to fix future additions that don't comply with the preferred style as well as backport the patch by rerunning the Coccinelle script with less worry of changed context. Automated cleanups are always going to be easier to swallow (even if the diffstat is larger) than manual ad hoc cleanups.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#112 lore raw
Quoted 17 lines · Eric Blake
Quoted 16 lines · Daniel Henrique Barboza

Hello,

This is the type of cleanup I've contributed to Libvirt during the last year. Figured QEMU also deserves the same care.

The idea here is remove unneeded labels. By 'unneeded' I mean labels that does nothing but a 'return' call. One common case is something like this:

if ()
     goto cleanup;
[...]
  cleanup:
     return 0;

Quoted 8 lines
Quoted 6 lines

This code can be simplified to:

if ()
     return 0;

How much of this work is done manually, and how much via Coccinelle?

I'm still getting along with Coccinelle. I'm able to do simple matches but couldn't make it work to match this scenario. I didn't invest too much time on it though.

Quoted 9 lines
Quoted 7 lines

  qga/commands-win32.c          | 17 ++++---
  target/mips/mips-semi.c       | 15 +++---
  target/unicore32/softmmu.c    | 23 +++-------
  util/aio-posix.c              |  3 +-
  util/module.c                 | 11 ++---

Hmm, no change to scripts/coccinelle, so presumably all manual :(

I used pcregrep:

$ pcregrep --exclude-dir=build --exclude-dir=docs --exclude-dir=scripts -r -n -M ':\n*\s*return' . > clean_labels

(note: there was a lot more of --exclude-dir in the original command, unfortunately I didn't record it)

Then I filtered in the output file the cases where the regexp matched "switch" labels and any other false positives like strings in comments. It's not manual inspection, but it was crude indeed.

Quoted 2 lines

If we have a Coccinelle script that performs this transformation, we are more likely to be able to catch all places in the tree that would benefit (rather than relying on grep calls or other manual inspection), and more importantly, we can repeat the effort periodically to fix future additions that don't comply with the preferred style as well as backport the patch by rerunning the Coccinelle script with less worry of changed context.  Automated cleanups are always going to be easier to swallow (even if the diffstat is larger) than manual ad hoc cleanups.

I am not aware of how QEMU handles Coccinelle, if it is imposed via ./scripts/checkpatch.pl or something that it is ran from time to time to suggest changes. But if it's desirable, I can see if I can cook a Coccinelle script (or anything a bit more sophisticated than what I did) to flag these cases I attempted to handle with this series.

Thanks,

DHB

Quoted 1 line
#25 lore raw

Re: [PATCH v1 12/59] virtfs-proxy-helper.c: remove 'err_out' label in setugid()

In reply to Greg Kurz
Quoted 10 lines · Greg Kurz
Quoted 6 lines · On Mon, 6 Jan 2020 15:23:38 -0300 Daniel Henrique Barboza…

'err_out' can be removed and be replaced by 'return -errno' in its only instance in the function.

---

Quoted 6 lines

I don't really mind, but I confirm this doesn't change behavior.

What's the plan to get this and the other 9p related patches merged ? Through the trivial tree or each subsystem tree ?

I guess qemu-trivial will eventually pick up whatever hasn't been merged by maintainers.

[...]

#108 lore raw
In reply to Corey Minyard
Quoted 27 lines · Corey Minyard
Quoted 18 lines · Daniel Henrique Barboza

Hello,

This is the type of cleanup I've contributed to Libvirt during the last year. Figured QEMU also deserves the same care.

The idea here is remove unneeded labels. By 'unneeded' I mean labels that does nothing but a 'return' call. One common case is something like this:

if ()

    goto cleanup;
[...]
 cleanup:
    return 0;

This code can be simplified to:

Quoted 7 lines

if ()

    return 0;

Which is cleaner and requires less brain cycles to wonder whether the 'cleanup' label does anything special, such as a heap memory cleanup.

Quoted 5 lines

I would disagree with this analysis. To me, I often wonder when I have to add cleanup code to a routine whether there is some hidden return in the middle of the function. That's a lot harder to spot than just looking for the cleanup label at the end of the function to see what it does.

A cleanup label does not preclude existence of return. You have to check for return anyway.

Quoted 4 lines

For non-trivial
functions I prefer to have one point of return at the end (and maybe some minor checks with returns right at the beginning). I'm not adamant about this, just my opinion.

I'm in Daniel's camp: if there's no need for cleanup, return without ado.

Quoted 3 lines

But if we are going to fix things like this, it might be best to add them to the coding style document and checkpatch script. Otherwise these sorts of things will just continue.

Maybe.

Reviewed-by on v1 41/59
#74 lore raw

Re: [PATCH v1 41/59] intc/s390_flic_kvm.c: remove unneeded label in kvm_flic_load()

In reply to Daniel Henrique Barboza
Quoted 1 line · Daniel Henrique Barboza

'out' label can be replaced by 'return' with the apropriate

s/apropriate/appropriate/

Quoted 3 lines

value that is set by 'r' right before the jump.

Christian Borntraeger <[email protected]>

Missing "Cc:" ? With this line and the typo removed/fixed:

Quoted 39 lines
---
 hw/intc/s390_flic_kvm.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
hw/intc/s390_flic_kvm.c +3 -7
index dddd33ea61..2e1e70c61d 100644
@@ -439,17 +439,14 @@ static int kvm_flic_load(QEMUFile *f, void *opaque, size_t size,
     count = qemu_get_be64(f);
     len = count * sizeof(struct kvm_s390_irq);
     if (count == FLIC_FAILED) {
-        r = -EINVAL;
-        goto out;
+        return -EINVAL;
     }
     if (count == 0) {
-        r = 0;
-        goto out;
+        return 0;
     }
     buf = g_try_malloc0(len);
     if (!buf) {
-        r = -ENOMEM;
-        goto out;
+        return -ENOMEM;
     }
 
     if (qemu_get_buffer(f, (uint8_t *) buf, len) != len) {
@@ -460,7 +457,6 @@ static int kvm_flic_load(QEMUFile *f, void *opaque, size_t size,
 
 out_free:
     g_free(buf);
-out:
     return r;
 }
 
#26 lore raw

Re: [PATCH v1 12/59] virtfs-proxy-helper.c: remove 'err_out' label in setugid()

In reply to Markus Armbruster

Le 13/01/2020 à 16:15, Markus Armbruster a écrit :

Quoted 16 lines
Quoted 14 lines · Greg Kurz
Quoted 6 lines · On Mon, 6 Jan 2020 15:23:38 -0300 Daniel Henrique Barboza…

'err_out' can be removed and be replaced by 'return -errno' in its only instance in the function.

---

I don't really mind, but I confirm this doesn't change behavior.

Quoted 8 lines
Quoted 2 lines

What's the plan to get this and the other 9p related patches merged ? Through the trivial tree or each subsystem tree ?

I guess qemu-trivial will eventually pick up whatever hasn't been merged by maintainers.

[...]

Yes, but the difficulty will be to sort which ones of the 59 patches series to collect...

Thanks,
Laurent

#73 lore raw

Re: [PATCH v1 41/59] intc/s390_flic_kvm.c: remove unneeded label in kvm_flic_load()

In reply to Cornelia Huck
Quoted 8 lines · On Wed, 8 Jan 2020 14:00:46 +0100 Cornelia Huck <[email protected]> wrote:
Quoted 4 lines · On Mon, 6 Jan 2020 15:24:07 -0300 Daniel Henrique Barboza…

'out' label can be replaced by 'return' with the apropriate value that is set by 'r' right before the jump.

Christian Borntraeger <[email protected]>

Quoted 10 lines

I think something went wrong here; adding some cc:s.

Quoted 4 lines
---
 hw/intc/s390_flic_kvm.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

Looks fine to me; will apply unless someone sees an issue.

Thanks, applied (with the patch description fixed as per Thomas' comments).

#27 lore raw

Re: [PATCH v1 12/59] virtfs-proxy-helper.c: remove 'err_out' label in setugid()

In reply to Laurent Vivier
Quoted 20 lines · On Mon, 13 Jan 2020 17:32:31 +0100 Laurent Vivier <[email protected]> wrote:

Le 13/01/2020 à 16:15, Markus Armbruster a écrit :

Quoted 19 lines
Quoted 16 lines · Greg Kurz
Quoted 6 lines · On Mon, 6 Jan 2020 15:23:38 -0300 Daniel Henrique Barboza…

'err_out' can be removed and be replaced by 'return -errno' in its only instance in the function.

---

I don't really mind, but I confirm this doesn't change behavior.

What's the plan to get this and the other 9p related patches merged ? Through the trivial tree or each subsystem tree ?

Quoted 9 lines
Quoted 5 lines

I guess qemu-trivial will eventually pick up whatever hasn't been merged by maintainers.

[...]

Yes, but the difficulty will be to sort which ones of the 59 patches series to collect...

Ok, less work for you then. I've applied both 12/59 and 45/59 to 9p-next. I'm planning to send a PR later this week.

Quoted 3 lines

Thanks,
Laurent

Cheers,

--
Greg

#28 lore raw

Re: [PATCH v1 12/59] virtfs-proxy-helper.c: remove 'err_out' label in setugid()

In reply to Laurent Vivier
Quoted 20 lines · Laurent Vivier

Le 13/01/2020 à 16:15, Markus Armbruster a écrit :

Quoted 19 lines
Quoted 16 lines · Greg Kurz
Quoted 6 lines · On Mon, 6 Jan 2020 15:23:38 -0300 Daniel Henrique Barboza…

'err_out' can be removed and be replaced by 'return -errno' in its only instance in the function.

---

I don't really mind, but I confirm this doesn't change behavior.

What's the plan to get this and the other 9p related patches merged ? Through the trivial tree or each subsystem tree ?

Quoted 8 lines
Quoted 5 lines

I guess qemu-trivial will eventually pick up whatever hasn't been merged by maintainers.

[...]

Yes, but the difficulty will be to sort which ones of the 59 patches series to collect...

Collect them all and let git figure out which ones have been applied already?

#13 lore raw

Re: [PATCH v1 06/59] mips-semi.c: remove 'uhi_done' label in helper_do_semihosting()

In reply to Daniel Henrique Barboza
Quoted 12 lines · Daniel Henrique Barboza

The label 'uhi_done' is a simple 'return' call and can be removed for a bit more clarity in the code.

CC Aurelien Jarno <[email protected]>
CC Aleksandar Markovic <[email protected]>
CC Aleksandar Rikalo <[email protected]>
---
 target/mips/mips-semi.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

Applied to MIPS queue.

Quoted 79 lines
target/mips/mips-semi.c +7 -9
index 35bdfd7c77..10a710c1e8 100644
@@ -218,7 +218,7 @@ static int copy_argn_to_target(CPUMIPSState *env, int
 arg_num,
         if (!p) {                               \
             gpr[2] = -1;                        \
             gpr[3] = EFAULT;                    \
-            goto uhi_done;                      \
+            return;                             \
         }                                       \
     } while (0)
@@ -228,14 +228,14 @@ static int copy_argn_to_target(CPUMIPSState *env,
 int arg_num,
         if (!p) {                                       \
             gpr[2] = -1;                                \
             gpr[3] = EFAULT;                            \
-            goto uhi_done;                              \
+            return;                                     \
         }                                               \
         p2 = lock_user_string(addr2);                   \
         if (!p2) {                                      \
             unlock_user(p, addr, 0);                    \
             gpr[2] = -1;                                \
             gpr[3] = EFAULT;                            \
-            goto uhi_done;                              \
+            return;                                     \
         }                                               \
     } while (0)
@@ -272,7 +272,7 @@ void helper_do_semihosting(CPUMIPSState *env)
         if (gpr[4] < 3) {
             /* ignore closing stdin/stdout/stderr */
             gpr[2] = 0;
-            goto uhi_done;
+            return;
         }
         gpr[2] = close(gpr[4]);
         gpr[3] = errno_mips(errno);
@@ -302,7 +302,7 @@ void helper_do_semihosting(CPUMIPSState *env)
             gpr[2] = fstat(gpr[4], &sbuf);
             gpr[3] = errno_mips(errno);
             if (gpr[2]) {
-                goto uhi_done;
+                return;
             }
             gpr[2] = copy_stat_to_target(env, &sbuf, gpr[5]);
             gpr[3] = errno_mips(errno);
@@ -314,14 +314,14 @@ void helper_do_semihosting(CPUMIPSState *env)
     case UHI_argnlen:
         if (gpr[4] >= semihosting_get_argc()) {
             gpr[2] = -1;
-            goto uhi_done;
+            return;
         }
         gpr[2] = strlen(semihosting_get_arg(gpr[4]));
         break;
     case UHI_argn:
         if (gpr[4] >= semihosting_get_argc()) {
             gpr[2] = -1;
-            goto uhi_done;
+            return;
         }
         gpr[2] = copy_argn_to_target(env, gpr[4], gpr[5]);
         break;
@@ -369,6 +369,5 @@ void helper_do_semihosting(CPUMIPSState *env)
         fprintf(stderr, "Unknown UHI operation %d\n", op);
         abort();
     }
-uhi_done:
     return;
 }
--

2.24.1