Skip to content

Commit

Permalink
coccinelle: Remove unnecessary variables for function return value
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ehabkost authored and Markus Armbruster committed Jun 20, 2016
1 parent 6b62d96 commit 9be3859
Show file tree
Hide file tree
Showing 45 changed files with 88 additions and 228 deletions.
10 changes: 2 additions & 8 deletions audio/audio.c
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions block/archipelago.c
Expand Up @@ -974,11 +974,9 @@ static int64_t archipelago_volume_info(BDRVArchipelagoState *s)

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)
Expand Down
6 changes: 2 additions & 4 deletions block/qcow2-cluster.c
Expand Up @@ -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);
}

/*
Expand Down
7 changes: 2 additions & 5 deletions block/qcow2-refcount.c
Expand Up @@ -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);
}

/*
Expand Down
8 changes: 2 additions & 6 deletions block/raw-posix.c
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions block/raw_bsd.c
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions block/rbd.c
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions block/vmdk.c
Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions block/vvfat.c
Expand Up @@ -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) {
Expand Down
13 changes: 3 additions & 10 deletions hw/acpi/aml-build.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down
5 changes: 1 addition & 4 deletions hw/audio/intel-hda.c
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions hw/display/vga.c
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions hw/intc/s390_flic_kvm.c
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions hw/pci-host/uninorth.c
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions hw/ppc/spapr_vio.c
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions hw/scsi/megasas.c
Expand Up @@ -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;
}

/*
Expand Down
5 changes: 1 addition & 4 deletions hw/scsi/scsi-generic.c
Expand Up @@ -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[] = {
Expand Down
4 changes: 1 addition & 3 deletions hw/timer/mc146818rtc.c
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions hw/virtio/virtio-pci.c
Expand Up @@ -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,
Expand Down
15 changes: 4 additions & 11 deletions linux-user/signal.c
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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];

Expand All @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions page_cache.c
Expand Up @@ -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)
Expand Down

0 comments on commit 9be3859

Please sign in to comment.