aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Habkost <ehabkost@redhat.com>2016-06-13 18:57:58 -0300
committerMarkus Armbruster <armbru@redhat.com>2016-06-20 16:38:13 +0200
commit9be385980d37e8f4fd33f605f5fb1c3d144170a8 (patch)
treed4516d2305c01fabda776667acdb48c48cb105af
parent6b62d961373e0327f2af8fb77d6d5d6308864180 (diff)
downloadqemu-9be385980d37e8f4fd33f605f5fb1c3d144170a8.zip
qemu-9be385980d37e8f4fd33f605f5fb1c3d144170a8.tar.gz
qemu-9be385980d37e8f4fd33f605f5fb1c3d144170a8.tar.bz2
coccinelle: Remove unnecessary variables for function return value
Use Coccinelle script to replace 'ret = E; return ret' with 'return E'. The script will do the substitution only when the function return type and variable type are the same. Manual fixups: * audio/audio.c: coding style of "read (...)" and "write (...)" * block/qcow2-cluster.c: wrap line to make it shorter * block/qcow2-refcount.c: change indentation of wrapped line * target-tricore/op_helper.c: fix coding style of "remainder|quotient" * target-mips/dsp_helper.c: reverted changes because I don't want to argue about checkpatch.pl * ui/qemu-pixman.c: fix line indentation * block/rbd.c: restore blank line between declarations and statements Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Message-Id: <1465855078-19435-4-git-send-email-ehabkost@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Unused Coccinelle rule name dropped along with a redundant comment; whitespace touched up in block/qcow2-cluster.c; stale commit message paragraph deleted] Signed-off-by: Markus Armbruster <armbru@redhat.com>
-rw-r--r--audio/audio.c10
-rw-r--r--block/archipelago.c4
-rw-r--r--block/qcow2-cluster.c6
-rw-r--r--block/qcow2-refcount.c7
-rw-r--r--block/raw-posix.c8
-rw-r--r--block/raw_bsd.c5
-rw-r--r--block/rbd.c4
-rw-r--r--block/vmdk.c6
-rw-r--r--block/vvfat.c5
-rw-r--r--hw/acpi/aml-build.c13
-rw-r--r--hw/audio/intel-hda.c5
-rw-r--r--hw/display/vga.c4
-rw-r--r--hw/intc/s390_flic_kvm.c5
-rw-r--r--hw/pci-host/uninorth.c5
-rw-r--r--hw/ppc/spapr_vio.c5
-rw-r--r--hw/scsi/megasas.c5
-rw-r--r--hw/scsi/scsi-generic.c5
-rw-r--r--hw/timer/mc146818rtc.c4
-rw-r--r--hw/virtio/virtio-pci.c4
-rw-r--r--linux-user/signal.c15
-rw-r--r--page_cache.c5
-rw-r--r--qga/commands-posix.c4
-rw-r--r--qga/commands-win32.c5
-rw-r--r--qobject/qlist.c5
-rw-r--r--scripts/coccinelle/return_directly.cocci19
-rw-r--r--target-i386/fpu_helper.c10
-rw-r--r--target-i386/kvm.c5
-rw-r--r--target-mips/op_helper.c4
-rw-r--r--target-s390x/helper.c6
-rw-r--r--target-sparc/cc_helper.c25
-rw-r--r--target-tricore/op_helper.c13
-rw-r--r--tests/display-vga-test.c6
-rw-r--r--tests/endianness-test.c5
-rw-r--r--tests/i440fx-test.c4
-rw-r--r--tests/intel-hda-test.c6
-rw-r--r--tests/test-filter-redirector.c6
-rw-r--r--tests/virtio-blk-test.c5
-rw-r--r--tests/virtio-console-test.c6
-rw-r--r--tests/virtio-net-test.c6
-rw-r--r--tests/virtio-scsi-test.c6
-rw-r--r--tests/wdt_ib700-test.c6
-rw-r--r--ui/cursor.c10
-rw-r--r--ui/qemu-pixman.c13
-rw-r--r--util/module.c6
-rw-r--r--vl.c5
45 files changed, 88 insertions, 228 deletions
diff --git a/audio/audio.c b/audio/audio.c
index e60c124..9d4dcc7 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1131,8 +1131,6 @@ static void audio_timer (void *opaque)
*/
int AUD_write (SWVoiceOut *sw, void *buf, int size)
{
- int bytes;
-
if (!sw) {
/* XXX: Consider options */
return size;
@@ -1143,14 +1141,11 @@ int AUD_write (SWVoiceOut *sw, void *buf, int size)
return 0;
}
- bytes = sw->hw->pcm_ops->write (sw, buf, size);
- return bytes;
+ return sw->hw->pcm_ops->write(sw, buf, size);
}
int AUD_read (SWVoiceIn *sw, void *buf, int size)
{
- int bytes;
-
if (!sw) {
/* XXX: Consider options */
return size;
@@ -1161,8 +1156,7 @@ int AUD_read (SWVoiceIn *sw, void *buf, int size)
return 0;
}
- bytes = sw->hw->pcm_ops->read (sw, buf, size);
- return bytes;
+ return sw->hw->pcm_ops->read(sw, buf, size);
}
int AUD_get_buffer_size_out (SWVoiceOut *sw)
diff --git a/block/archipelago.c b/block/archipelago.c
index b9f5e69..37b8aca 100644
--- a/block/archipelago.c
+++ b/block/archipelago.c
@@ -974,11 +974,9 @@ err_exit2:
static int64_t qemu_archipelago_getlength(BlockDriverState *bs)
{
- int64_t ret;
BDRVArchipelagoState *s = bs->opaque;
- ret = archipelago_volume_info(s);
- return ret;
+ return archipelago_volume_info(s);
}
static int qemu_archipelago_truncate(BlockDriverState *bs, int64_t offset)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 893ddf6..0fb4356 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -154,11 +154,9 @@ static int l2_load(BlockDriverState *bs, uint64_t l2_offset,
uint64_t **l2_table)
{
BDRVQcow2State *s = bs->opaque;
- int ret;
-
- ret = qcow2_cache_get(bs, s->l2_table_cache, l2_offset, (void**) l2_table);
- return ret;
+ return qcow2_cache_get(bs, s->l2_table_cache, l2_offset,
+ (void **)l2_table);
}
/*
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 66f187a..3bef410 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -218,13 +218,10 @@ static int load_refcount_block(BlockDriverState *bs,
void **refcount_block)
{
BDRVQcow2State *s = bs->opaque;
- int ret;
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_LOAD);
- ret = qcow2_cache_get(bs, s->refcount_block_cache, refcount_block_offset,
- refcount_block);
-
- return ret;
+ return qcow2_cache_get(bs, s->refcount_block_cache, refcount_block_offset,
+ refcount_block);
}
/*
diff --git a/block/raw-posix.c b/block/raw-posix.c
index dbdabc9..bef7a67 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -582,11 +582,9 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
BDRVRawState *s = bs->opaque;
- int ret;
s->type = FTYPE_FILE;
- ret = raw_open_common(bs, options, flags, 0, errp);
- return ret;
+ return raw_open_common(bs, options, flags, 0, errp);
}
static int raw_reopen_prepare(BDRVReopenState *state,
@@ -2437,13 +2435,11 @@ static int cdrom_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
BDRVRawState *s = bs->opaque;
- int ret;
s->type = FTYPE_CD;
/* open will not fail even if no CD is inserted, so add O_NONBLOCK */
- ret = raw_open_common(bs, options, flags, O_NONBLOCK, errp);
- return ret;
+ return raw_open_common(bs, options, flags, O_NONBLOCK, errp);
}
static int cdrom_probe_device(const char *filename)
diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index b51ac98..7f63791 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -190,10 +190,7 @@ static int raw_has_zero_init(BlockDriverState *bs)
static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
{
- int ret;
-
- ret = bdrv_create_file(filename, opts, errp);
- return ret;
+ return bdrv_create_file(filename, opts, errp);
}
static int raw_open(BlockDriverState *bs, QDict *options, int flags,
diff --git a/block/rbd.c b/block/rbd.c
index 5226b6f..0a5840d 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -883,10 +883,8 @@ static int qemu_rbd_snap_rollback(BlockDriverState *bs,
const char *snapshot_name)
{
BDRVRBDState *s = bs->opaque;
- int r;
- r = rbd_snap_rollback(s->image, snapshot_name);
- return r;
+ return rbd_snap_rollback(s->image, snapshot_name);
}
static int qemu_rbd_snap_list(BlockDriverState *bs,
diff --git a/block/vmdk.c b/block/vmdk.c
index ee09423..2901692 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1260,15 +1260,13 @@ static VmdkExtent *find_extent(BDRVVmdkState *s,
static inline uint64_t vmdk_find_offset_in_cluster(VmdkExtent *extent,
int64_t offset)
{
- uint64_t offset_in_cluster, extent_begin_offset, extent_relative_offset;
+ uint64_t extent_begin_offset, extent_relative_offset;
uint64_t cluster_size = extent->cluster_sectors * BDRV_SECTOR_SIZE;
extent_begin_offset =
(extent->end_sector - extent->sectors) * BDRV_SECTOR_SIZE;
extent_relative_offset = offset - extent_begin_offset;
- offset_in_cluster = extent_relative_offset % cluster_size;
-
- return offset_in_cluster;
+ return extent_relative_offset % cluster_size;
}
static inline uint64_t vmdk_find_index_in_cluster(VmdkExtent *extent,
diff --git a/block/vvfat.c b/block/vvfat.c
index 6d2e21c..5569450 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -114,15 +114,12 @@ static inline int array_ensure_allocated(array_t* array, int index)
static inline void* array_get_next(array_t* array) {
unsigned int next = array->next;
- void* result;
if (array_ensure_allocated(array, next) < 0)
return NULL;
array->next = next + 1;
- result = array_get(array, next);
-
- return result;
+ return array_get(array, next);
}
static inline void* array_insert(array_t* array,unsigned int index,unsigned int count) {
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 123160a..874e473 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -324,12 +324,9 @@ static void aml_free(gpointer data, gpointer user_data)
Aml *init_aml_allocator(void)
{
- Aml *var;
-
assert(!alloc_list);
alloc_list = g_ptr_array_new();
- var = aml_alloc();
- return var;
+ return aml_alloc();
}
void free_aml_allocator(void)
@@ -451,12 +448,10 @@ Aml *aml_name_decl(const char *name, Aml *val)
/* ACPI 1.0b: 16.2.6.1 Arg Objects Encoding */
Aml *aml_arg(int pos)
{
- Aml *var;
uint8_t op = 0x68 /* ARG0 op */ + pos;
assert(pos <= 6);
- var = aml_opcode(op);
- return var;
+ return aml_opcode(op);
}
/* ACPI 2.0a: 17.2.4.4 Type 2 Opcodes Encoding: DefToInteger */
@@ -1082,12 +1077,10 @@ Aml *aml_string(const char *name_format, ...)
/* ACPI 1.0b: 16.2.6.2 Local Objects Encoding */
Aml *aml_local(int num)
{
- Aml *var;
uint8_t op = 0x60 /* Local0Op */ + num;
assert(num <= 7);
- var = aml_opcode(op);
- return var;
+ return aml_opcode(op);
}
/* ACPI 2.0a: 17.2.2 Data Objects Encoding: DefVarPackage */
diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
index 93d7669..098b17d 100644
--- a/hw/audio/intel-hda.c
+++ b/hw/audio/intel-hda.c
@@ -219,10 +219,7 @@ static void intel_hda_reset(DeviceState *dev);
static hwaddr intel_hda_addr(uint32_t lbase, uint32_t ubase)
{
- hwaddr addr;
-
- addr = ((uint64_t)ubase << 32) | lbase;
- return addr;
+ return ((uint64_t)ubase << 32) | lbase;
}
static void intel_hda_update_int_sts(IntelHDAState *d)
diff --git a/hw/display/vga.c b/hw/display/vga.c
index 9ebc54f..2a88b3c 100644
--- a/hw/display/vga.c
+++ b/hw/display/vga.c
@@ -700,9 +700,7 @@ static void vbe_update_vgaregs(VGACommonState *s)
static uint32_t vbe_ioport_read_index(void *opaque, uint32_t addr)
{
VGACommonState *s = opaque;
- uint32_t val;
- val = s->vbe_index;
- return val;
+ return s->vbe_index;
}
uint32_t vbe_ioport_read_data(void *opaque, uint32_t addr)
diff --git a/hw/intc/s390_flic_kvm.c b/hw/intc/s390_flic_kvm.c
index 680857f..fef8080 100644
--- a/hw/intc/s390_flic_kvm.c
+++ b/hw/intc/s390_flic_kvm.c
@@ -195,7 +195,7 @@ static int kvm_s390_register_io_adapter(S390FLICState *fs, uint32_t id,
.swap = swap,
};
KVMS390FLICState *flic = KVM_S390_FLIC(fs);
- int r, ret;
+ int r;
struct kvm_device_attr attr = {
.group = KVM_DEV_FLIC_ADAPTER_REGISTER,
.addr = (uint64_t)&adapter,
@@ -208,8 +208,7 @@ static int kvm_s390_register_io_adapter(S390FLICState *fs, uint32_t id,
r = ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr);
- ret = r ? -errno : 0;
- return ret;
+ return r ? -errno : 0;
}
static int kvm_s390_io_adapter_map(S390FLICState *fs, uint32_t id,
diff --git a/hw/pci-host/uninorth.c b/hw/pci-host/uninorth.c
index 15b1054..7aac4d6 100644
--- a/hw/pci-host/uninorth.c
+++ b/hw/pci-host/uninorth.c
@@ -62,12 +62,9 @@ typedef struct UNINState {
static int pci_unin_map_irq(PCIDevice *pci_dev, int irq_num)
{
- int retval;
int devfn = pci_dev->devfn & 0x00FFFFFF;
- retval = (((devfn >> 11) & 0x1F) + irq_num) & 3;
-
- return retval;
+ return (((devfn >> 11) & 0x1F) + irq_num) & 3;
}
static void pci_unin_set_irq(void *opaque, int irq_num, int level)
diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c
index 3d9b9c6..ae40db8 100644
--- a/hw/ppc/spapr_vio.c
+++ b/hw/ppc/spapr_vio.c
@@ -57,12 +57,9 @@ static char *spapr_vio_get_dev_name(DeviceState *qdev)
{
VIOsPAPRDevice *dev = VIO_SPAPR_DEVICE(qdev);
VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
- char *name;
/* Device tree style name device@reg */
- name = g_strdup_printf("%s@%x", pc->dt_name, dev->reg);
-
- return name;
+ return g_strdup_printf("%s@%x", pc->dt_name, dev->reg);
}
static void spapr_vio_bus_class_init(ObjectClass *klass, void *data)
diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
index a9ffc32..d177218 100644
--- a/hw/scsi/megasas.c
+++ b/hw/scsi/megasas.c
@@ -410,17 +410,14 @@ static void megasas_encode_lba(uint8_t *cdb, uint64_t lba,
static uint64_t megasas_fw_time(void)
{
struct tm curtime;
- uint64_t bcd_time;
qemu_get_timedate(&curtime, 0);
- bcd_time = ((uint64_t)curtime.tm_sec & 0xff) << 48 |
+ return ((uint64_t)curtime.tm_sec & 0xff) << 48 |
((uint64_t)curtime.tm_min & 0xff) << 40 |
((uint64_t)curtime.tm_hour & 0xff) << 32 |
((uint64_t)curtime.tm_mday & 0xff) << 24 |
((uint64_t)curtime.tm_mon & 0xff) << 16 |
((uint64_t)(curtime.tm_year + 1900) & 0xffff);
-
- return bcd_time;
}
/*
diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c
index 71372a8..6a2d89a 100644
--- a/hw/scsi/scsi-generic.c
+++ b/hw/scsi/scsi-generic.c
@@ -579,10 +579,7 @@ const SCSIReqOps scsi_generic_req_ops = {
static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun,
uint8_t *buf, void *hba_private)
{
- SCSIRequest *req;
-
- req = scsi_req_alloc(&scsi_generic_req_ops, d, tag, lun, hba_private);
- return req;
+ return scsi_req_alloc(&scsi_generic_req_ops, d, tag, lun, hba_private);
}
static Property scsi_generic_properties[] = {
diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
index a11b8b4..f4e333e 100644
--- a/hw/timer/mc146818rtc.c
+++ b/hw/timer/mc146818rtc.c
@@ -105,12 +105,10 @@ static inline bool rtc_running(RTCState *s)
static uint64_t get_guest_rtc_ns(RTCState *s)
{
- uint64_t guest_rtc;
uint64_t guest_clock = qemu_clock_get_ns(rtc_clock);
- guest_rtc = s->base_rtc * NANOSECONDS_PER_SECOND +
+ return s->base_rtc * NANOSECONDS_PER_SECOND +
guest_clock - s->last_update + s->offset;
- return guest_rtc;
}
#ifdef TARGET_I386
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index bfedbbf..1a02783 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -761,9 +761,7 @@ static int kvm_virtio_pci_irqfd_use(VirtIOPCIProxy *proxy,
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
VirtQueue *vq = virtio_get_queue(vdev, queue_no);
EventNotifier *n = virtio_queue_get_guest_notifier(vq);
- int ret;
- ret = kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, n, NULL, irqfd->virq);
- return ret;
+ return kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, n, NULL, irqfd->virq);
}
static void kvm_virtio_pci_irqfd_release(VirtIOPCIProxy *proxy,
diff --git a/linux-user/signal.c b/linux-user/signal.c
index 61c1145..1dadddf 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -195,7 +195,6 @@ int block_signals(void)
{
TaskState *ts = (TaskState *)thread_cpu->opaque;
sigset_t set;
- int pending;
/* It's OK to block everything including SIGSEGV, because we won't
* run any further guest code before unblocking signals in
@@ -204,9 +203,7 @@ int block_signals(void)
sigfillset(&set);
sigprocmask(SIG_SETMASK, &set, 0);
- pending = atomic_xchg(&ts->signal_pending, 1);
-
- return pending;
+ return atomic_xchg(&ts->signal_pending, 1);
}
/* Wrapper for sigprocmask function
@@ -3956,9 +3953,7 @@ static void setup_sigcontext(struct target_sigcontext *sc,
static inline unsigned long align_sigframe(unsigned long sp)
{
- unsigned long i;
- i = sp & ~3UL;
- return i;
+ return sp & ~3UL;
}
static inline abi_ulong get_sigframe(struct target_sigaction *ka,
@@ -4555,7 +4550,7 @@ static target_ulong get_sigframe(struct target_sigaction *ka,
CPUPPCState *env,
int frame_size)
{
- target_ulong oldsp, newsp;
+ target_ulong oldsp;
oldsp = env->gpr[1];
@@ -4565,9 +4560,7 @@ static target_ulong get_sigframe(struct target_sigaction *ka,
+ target_sigaltstack_used.ss_size);
}
- newsp = (oldsp - frame_size) & ~0xFUL;
-
- return newsp;
+ return (oldsp - frame_size) & ~0xFUL;
}
static void save_user_regs(CPUPPCState *env, struct target_mcontext *frame)
diff --git a/page_cache.c b/page_cache.c
index a2809db..5f85787 100644
--- a/page_cache.c
+++ b/page_cache.c
@@ -111,11 +111,8 @@ void cache_fini(PageCache *cache)
static size_t cache_get_cache_pos(const PageCache *cache,
uint64_t address)
{
- size_t pos;
-
g_assert(cache->max_num_items);
- pos = (address / cache->page_size) & (cache->max_num_items - 1);
- return pos;
+ return (address / cache->page_size) & (cache->max_num_items - 1);
}
static CacheItem *cache_get_by_addr(const PageCache *cache, uint64_t addr)
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index eaef7be..ea37c09 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -127,7 +127,6 @@ int64_t qmp_guest_get_time(Error **errp)
{
int ret;
qemu_timeval tq;
- int64_t time_ns;
ret = qemu_gettimeofday(&tq);
if (ret < 0) {
@@ -135,8 +134,7 @@ int64_t qmp_guest_get_time(Error **errp)
return -1;
}
- time_ns = tq.tv_sec * 1000000000LL + tq.tv_usec * 1000;
- return time_ns;
+ return tq.tv_sec * 1000000000LL + tq.tv_usec * 1000;
}
void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp)
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index ea23797..9c9be12 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -1150,7 +1150,6 @@ out:
int64_t qmp_guest_get_time(Error **errp)
{
SYSTEMTIME ts = {0};
- int64_t time_ns;
FILETIME tf;
GetSystemTime(&ts);
@@ -1164,10 +1163,8 @@ int64_t qmp_guest_get_time(Error **errp)
return -1;
}
- time_ns = ((((int64_t)tf.dwHighDateTime << 32) | tf.dwLowDateTime)
+ return ((((int64_t)tf.dwHighDateTime << 32) | tf.dwLowDateTime)
- W32_FT_OFFSET) * 100;
-
- return time_ns;
}
void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp)
diff --git a/qobject/qlist.c b/qobject/qlist.c
index 1ec74de..86b60cb 100644
--- a/qobject/qlist.c
+++ b/qobject/qlist.c
@@ -100,7 +100,6 @@ QObject *qlist_pop(QList *qlist)
QObject *qlist_peek(QList *qlist)
{
QListEntry *entry;
- QObject *ret;
if (qlist == NULL || QTAILQ_EMPTY(&qlist->head)) {
return NULL;
@@ -108,9 +107,7 @@ QObject *qlist_peek(QList *qlist)
entry = QTAILQ_FIRST(&qlist->head);
- ret = entry->value;
-
- return ret;
+ return entry->value;
}
int qlist_empty(const QList *qlist)
diff --git a/scripts/coccinelle/return_directly.cocci b/scripts/coccinelle/return_directly.cocci
new file mode 100644
index 0000000..48680f2
--- /dev/null
+++ b/scripts/coccinelle/return_directly.cocci
@@ -0,0 +1,19 @@
+// replace 'R = X; return R;' with 'return R;'
+@@
+identifier VAR;
+expression E;
+type T;
+identifier F;
+@@
+ T F(...)
+ {
+ ...
+- T VAR;
+ ... when != VAR
+
+- VAR =
++ return
+ E;
+- return VAR;
+ ... when != VAR
+ }
diff --git a/target-i386/fpu_helper.c b/target-i386/fpu_helper.c
index 206e60f..929489b 100644
--- a/target-i386/fpu_helper.c
+++ b/target-i386/fpu_helper.c
@@ -298,18 +298,12 @@ int32_t helper_fistt_ST0(CPUX86State *env)
int32_t helper_fisttl_ST0(CPUX86State *env)
{
- int32_t val;
-
- val = floatx80_to_int32_round_to_zero(ST0, &env->fp_status);
- return val;
+ return floatx80_to_int32_round_to_zero(ST0, &env->fp_status);
}
int64_t helper_fisttll_ST0(CPUX86State *env)
{
- int64_t val;
-
- val = floatx80_to_int64_round_to_zero(ST0, &env->fp_status);
- return val;
+ return floatx80_to_int64_round_to_zero(ST0, &env->fp_status);
}
void helper_fldt_ST0(CPUX86State *env, target_ulong ptr)
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index ff92b1d..f3698f1 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1346,7 +1346,7 @@ static int kvm_put_xsave(X86CPU *cpu)
CPUX86State *env = &cpu->env;
X86XSaveArea *xsave = env->kvm_xsave_buf;
uint16_t cwd, swd, twd;
- int i, r;
+ int i;
if (!has_xsave) {
return kvm_put_fpu(cpu);
@@ -1395,8 +1395,7 @@ static int kvm_put_xsave(X86CPU *cpu)
16 * sizeof env->xmm_regs[16]);
memcpy(&xsave->pkru_state, &env->pkru, sizeof env->pkru);
#endif
- r = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_XSAVE, xsave);
- return r;
+ return kvm_vcpu_ioctl(CPU(cpu), KVM_SET_XSAVE, xsave);
}
static int kvm_put_xcrs(X86CPU *cpu)
diff --git a/target-mips/op_helper.c b/target-mips/op_helper.c
index 7cf9807..1ae1dda 100644
--- a/target-mips/op_helper.c
+++ b/target-mips/op_helper.c
@@ -133,10 +133,8 @@ static inline uint64_t get_HILO(CPUMIPSState *env)
static inline target_ulong set_HIT0_LO(CPUMIPSState *env, uint64_t HILO)
{
- target_ulong tmp;
env->active_tc.LO[0] = (int32_t)(HILO & 0xFFFFFFFF);
- tmp = env->active_tc.HI[0] = (int32_t)(HILO >> 32);
- return tmp;
+ return env->active_tc.HI[0] = (int32_t)(HILO >> 32);
}
static inline target_ulong set_HI_LOT0(CPUMIPSState *env, uint64_t HILO)
diff --git a/target-s390x/helper.c b/target-s390x/helper.c
index 9a744df..54a5177 100644
--- a/target-s390x/helper.c
+++ b/target-s390x/helper.c
@@ -70,11 +70,7 @@ void s390x_cpu_timer(void *opaque)
S390CPU *cpu_s390x_create(const char *cpu_model, Error **errp)
{
- S390CPU *cpu;
-
- cpu = S390_CPU(object_new(TYPE_S390_CPU));
-
- return cpu;
+ return S390_CPU(object_new(TYPE_S390_CPU));
}
S390CPU *s390x_new_cpu(const char *cpu_model, int64_t id, Error **errp)
diff --git a/target-sparc/cc_helper.c b/target-sparc/cc_helper.c
index 44c4409..a410a0b 100644
--- a/target-sparc/cc_helper.c
+++ b/target-sparc/cc_helper.c
@@ -200,10 +200,7 @@ static uint32_t compute_all_addx_xcc(CPUSPARCState *env)
static uint32_t compute_C_addx_xcc(CPUSPARCState *env)
{
- uint32_t ret;
-
- ret = get_C_addx_xcc(CC_DST, CC_SRC, CC_SRC2);
- return ret;
+ return get_C_addx_xcc(CC_DST, CC_SRC, CC_SRC2);
}
#endif
@@ -219,10 +216,7 @@ static uint32_t compute_all_addx(CPUSPARCState *env)
static uint32_t compute_C_addx(CPUSPARCState *env)
{
- uint32_t ret;
-
- ret = get_C_addx_icc(CC_DST, CC_SRC, CC_SRC2);
- return ret;
+ return get_C_addx_icc(CC_DST, CC_SRC, CC_SRC2);
}
static inline uint32_t get_V_tag_icc(target_ulong src1, target_ulong src2)
@@ -365,10 +359,7 @@ static uint32_t compute_all_subx_xcc(CPUSPARCState *env)
static uint32_t compute_C_subx_xcc(CPUSPARCState *env)
{
- uint32_t ret;
-
- ret = get_C_subx_xcc(CC_DST, CC_SRC, CC_SRC2);
- return ret;
+ return get_C_subx_xcc(CC_DST, CC_SRC, CC_SRC2);
}
#endif
@@ -384,10 +375,7 @@ static uint32_t compute_all_subx(CPUSPARCState *env)
static uint32_t compute_C_subx(CPUSPARCState *env)
{
- uint32_t ret;
-
- ret = get_C_subx_icc(CC_DST, CC_SRC, CC_SRC2);
- return ret;
+ return get_C_subx_icc(CC_DST, CC_SRC, CC_SRC2);
}
static uint32_t compute_all_tsub(CPUSPARCState *env)
@@ -479,8 +467,5 @@ void helper_compute_psr(CPUSPARCState *env)
uint32_t helper_compute_C_icc(CPUSPARCState *env)
{
- uint32_t ret;
-
- ret = icc_table[CC_OP].compute_c(env) >> PSR_CARRY_SHIFT;
- return ret;
+ return icc_table[CC_OP].compute_c(env) >> PSR_CARRY_SHIFT;
}
diff --git a/target-tricore/op_helper.c b/target-tricore/op_helper.c
index a73ed53..3382a12 100644
--- a/target-tricore/op_helper.c
+++ b/target-tricore/op_helper.c
@@ -2117,7 +2117,7 @@ uint64_t helper_dvadj(uint64_t r1, uint32_t r2)
int32_t eq_pos = x_sign & ((r1 >> 32) == r2);
int32_t eq_neg = x_sign & ((r1 >> 32) == -r2);
uint32_t quotient;
- uint64_t ret, remainder;
+ uint64_t remainder;
if ((q_sign & ~eq_neg) | eq_pos) {
quotient = (r1 + 1) & 0xffffffff;
@@ -2130,8 +2130,7 @@ uint64_t helper_dvadj(uint64_t r1, uint32_t r2)
} else {
remainder = (r1 & 0xffffffff00000000ull);
}
- ret = remainder|quotient;
- return ret;
+ return remainder | quotient;
}
uint64_t helper_dvstep(uint64_t r1, uint32_t r2)
@@ -2236,7 +2235,6 @@ uint64_t helper_divide_u(CPUTriCoreState *env, uint32_t r1, uint32_t r2)
uint64_t helper_mul_h(uint32_t arg00, uint32_t arg01,
uint32_t arg10, uint32_t arg11, uint32_t n)
{
- uint64_t ret;
uint32_t result0, result1;
int32_t sc1 = ((arg00 & 0xffff) == 0x8000) &&
@@ -2253,8 +2251,7 @@ uint64_t helper_mul_h(uint32_t arg00, uint32_t arg01,
} else {
result0 = (((uint32_t)(arg01 * arg11)) << n);
}
- ret = (((uint64_t)result1 << 32)) | result0;
- return ret;
+ return (((uint64_t)result1 << 32)) | result0;
}
uint64_t helper_mulm_h(uint32_t arg00, uint32_t arg01,
@@ -2308,11 +2305,9 @@ uint32_t helper_mulr_h(uint32_t arg00, uint32_t arg01,
uint32_t helper_crc32(uint32_t arg0, uint32_t arg1)
{
uint8_t buf[4];
- uint32_t ret;
stl_be_p(buf, arg0);
- ret = crc32(arg1, buf, 4);
- return ret;
+ return crc32(arg1, buf, 4);
}
/* context save area (CSA) related helpers */
diff --git a/tests/display-vga-test.c b/tests/display-vga-test.c
index 06b244e..9146021 100644
--- a/tests/display-vga-test.c
+++ b/tests/display-vga-test.c
@@ -50,8 +50,6 @@ static void pci_virtio_vga(void)
int main(int argc, char **argv)
{
- int ret;
-
g_test_init(&argc, &argv, NULL);
qtest_add_func("/display/pci/cirrus", pci_cirrus);
@@ -62,7 +60,5 @@ int main(int argc, char **argv)
#ifdef CONFIG_VIRTIO_VGA
qtest_add_func("/display/pci/virtio-vga", pci_virtio_vga);
#endif
- ret = g_test_run();
-
- return ret;
+ return g_test_run();
}
diff --git a/tests/endianness-test.c b/tests/endianness-test.c
index 2197972..b7a120e 100644
--- a/tests/endianness-test.c
+++ b/tests/endianness-test.c
@@ -282,7 +282,6 @@ static void test_endianness_combine(gconstpointer data)
int main(int argc, char **argv)
{
const char *arch = qtest_get_arch();
- int ret;
int i;
g_test_init(&argc, &argv, NULL);
@@ -305,7 +304,5 @@ int main(int argc, char **argv)
qtest_add_data_func(path, &test_cases[i], test_endianness_combine);
}
- ret = g_test_run();
-
- return ret;
+ return g_test_run();
}
diff --git a/tests/i440fx-test.c b/tests/i440fx-test.c
index c1d9b3e..3542ad1 100644
--- a/tests/i440fx-test.c
+++ b/tests/i440fx-test.c
@@ -394,7 +394,6 @@ static void request_pflash(FirmwareTestFixture *fixture,
int main(int argc, char **argv)
{
TestData data;
- int ret;
g_test_init(&argc, &argv, NULL);
@@ -405,6 +404,5 @@ int main(int argc, char **argv)
add_firmware_test("i440fx/firmware/bios", request_bios);
add_firmware_test("i440fx/firmware/pflash", request_pflash);
- ret = g_test_run();
- return ret;
+ return g_test_run();
}
diff --git a/tests/intel-hda-test.c b/tests/intel-hda-test.c
index b0ca7e0..b782b2e 100644
--- a/tests/intel-hda-test.c
+++ b/tests/intel-hda-test.c
@@ -31,13 +31,9 @@ static void ich9_test(void)
int main(int argc, char **argv)
{
- int ret;
-
g_test_init(&argc, &argv, NULL);
qtest_add_func("/intel-hda/ich6", ich6_test);
qtest_add_func("/intel-hda/ich9", ich9_test);
- ret = g_test_run();
-
- return ret;
+ return g_test_run();
}
diff --git a/tests/test-filter-redirector.c b/tests/test-filter-redirector.c
index 280e4b6..c63b68f 100644
--- a/tests/test-filter-redirector.c
+++ b/tests/test-filter-redirector.c
@@ -209,12 +209,8 @@ static void test_redirector_rx(void)
int main(int argc, char **argv)
{
- int ret;
-
g_test_init(&argc, &argv, NULL);
qtest_add_func("/netfilter/redirector_tx", test_redirector_tx);
qtest_add_func("/netfilter/redirector_rx", test_redirector_rx);
- ret = g_test_run();
-
- return ret;
+ return g_test_run();
}
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index 8272ba8..06dd7fc 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -763,7 +763,6 @@ static void mmio_basic(void)
int main(int argc, char **argv)
{
- int ret;
const char *arch = qtest_get_arch();
g_test_init(&argc, &argv, NULL);
@@ -779,7 +778,5 @@ int main(int argc, char **argv)
qtest_add_func("/virtio/blk/mmio/basic", mmio_basic);
}
- ret = g_test_run();
-
- return ret;
+ return g_test_run();
}
diff --git a/tests/virtio-console-test.c b/tests/virtio-console-test.c
index 6d6414d..1c3de07 100644
--- a/tests/virtio-console-test.c
+++ b/tests/virtio-console-test.c
@@ -27,13 +27,9 @@ static void serialport_pci_nop(void)
int main(int argc, char **argv)
{
- int ret;
-
g_test_init(&argc, &argv, NULL);
qtest_add_func("/virtio/console/pci/nop", console_pci_nop);
qtest_add_func("/virtio/serialport/pci/nop", serialport_pci_nop);
- ret = g_test_run();
-
- return ret;
+ return g_test_run();
}
diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
index e5c1448..f4f6a4a 100644
--- a/tests/virtio-net-test.c
+++ b/tests/virtio-net-test.c
@@ -248,8 +248,6 @@ static void hotplug(void)
int main(int argc, char **argv)
{
- int ret;
-
g_test_init(&argc, &argv, NULL);
#ifndef _WIN32
qtest_add_data_func("/virtio/net/pci/basic", send_recv_test, pci_basic);
@@ -258,7 +256,5 @@ int main(int argc, char **argv)
#endif
qtest_add_func("/virtio/net/pci/hotplug", hotplug);
- ret = g_test_run();
-
- return ret;
+ return g_test_run();
}
diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
index 5f1a8ae..b712652 100644
--- a/tests/virtio-scsi-test.c
+++ b/tests/virtio-scsi-test.c
@@ -260,15 +260,11 @@ static void test_unaligned_write_same(void)
int main(int argc, char **argv)
{
- int ret;
-
g_test_init(&argc, &argv, NULL);
qtest_add_func("/virtio/scsi/pci/nop", pci_nop);
qtest_add_func("/virtio/scsi/pci/hotplug", hotplug);
qtest_add_func("/virtio/scsi/pci/scsi-disk/unaligned-write-same",
test_unaligned_write_same);
- ret = g_test_run();
-
- return ret;
+ return g_test_run();
}
diff --git a/tests/wdt_ib700-test.c b/tests/wdt_ib700-test.c
index 9c1d78b..49f4f0c 100644
--- a/tests/wdt_ib700-test.c
+++ b/tests/wdt_ib700-test.c
@@ -117,15 +117,11 @@ static void ib700_none(void)
int main(int argc, char **argv)
{
- int ret;
-
g_test_init(&argc, &argv, NULL);
qtest_add_func("/wdt_ib700/pause", ib700_pause);
qtest_add_func("/wdt_ib700/reset", ib700_reset);
qtest_add_func("/wdt_ib700/shutdown", ib700_shutdown);
qtest_add_func("/wdt_ib700/none", ib700_none);
- ret = g_test_run();
-
- return ret;
+ return g_test_run();
}
diff --git a/ui/cursor.c b/ui/cursor.c
index a276e01..5155b39 100644
--- a/ui/cursor.c
+++ b/ui/cursor.c
@@ -81,18 +81,12 @@ void cursor_print_ascii_art(QEMUCursor *c, const char *prefix)
QEMUCursor *cursor_builtin_hidden(void)
{
- QEMUCursor *c;
-
- c = cursor_parse_xpm(cursor_hidden_xpm);
- return c;
+ return cursor_parse_xpm(cursor_hidden_xpm);
}
QEMUCursor *cursor_builtin_left_ptr(void)
{
- QEMUCursor *c;
-
- c = cursor_parse_xpm(cursor_left_ptr_xpm);
- return c;
+ return cursor_parse_xpm(cursor_left_ptr_xpm);
}
QEMUCursor *cursor_alloc(int width, int height)
diff --git a/ui/qemu-pixman.c b/ui/qemu-pixman.c
index c9f8dce..6e8b83a 100644
--- a/ui/qemu-pixman.c
+++ b/ui/qemu-pixman.c
@@ -180,14 +180,11 @@ void qemu_pixman_linebuf_copy(pixman_image_t *fb, int width, int x, int y,
pixman_image_t *qemu_pixman_mirror_create(pixman_format_code_t format,
pixman_image_t *image)
{
- pixman_image_t *mirror;
-
- mirror = pixman_image_create_bits(format,
- pixman_image_get_width(image),
- pixman_image_get_height(image),
- NULL,
- pixman_image_get_stride(image));
- return mirror;
+ return pixman_image_create_bits(format,
+ pixman_image_get_width(image),
+ pixman_image_get_height(image),
+ NULL,
+ pixman_image_get_stride(image));
}
void qemu_pixman_image_unref(pixman_image_t *image)
diff --git a/util/module.c b/util/module.c
index ce058ae..86e3f7a 100644
--- a/util/module.c
+++ b/util/module.c
@@ -55,13 +55,9 @@ static void init_lists(void)
static ModuleTypeList *find_type(module_init_type type)
{
- ModuleTypeList *l;
-
init_lists();
- l = &init_type_list[type];
-
- return l;
+ return &init_type_list[type];
}
void register_module_init(void (*fn)(void), module_init_type type)
diff --git a/vl.c b/vl.c
index 18af70a..afd5c0b 100644
--- a/vl.c
+++ b/vl.c
@@ -2352,10 +2352,7 @@ static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
#ifdef CONFIG_VIRTFS
static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
{
- int ret;
- ret = qemu_fsdev_add(opts);
-
- return ret;
+ return qemu_fsdev_add(opts);
}
#endif