Skip to content

Commit

Permalink
cleanup: Tweak and re-run return_directly.cocci
Browse files Browse the repository at this point in the history
Tweak the semantic patch to drop redundant parenthesis around the
return expression.

Coccinelle drops a comment in hw/rdma/vmw/pvrdma_cmd.c; restored
manually.

Coccinelle messes up vmdk_co_create(), not sure why.  Change dropped,
will be done manually in the next commit.

Line breaks in target/avr/cpu.h and hw/rdma/vmw/pvrdma_cmd.c tidied up
manually.

Whitespace in tools/virtiofsd/fuse_lowlevel.c tidied up manually.

checkpatch.pl complains "return of an errno should typically be -ve"
two times for hw/9pfs/9p-synth.c.  Preexisting, the patch merely makes
it visible to checkpatch.pl.

Signed-off-by: Markus Armbruster <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Acked-by: Dr. David Alan Gilbert <[email protected]>
  • Loading branch information
Markus Armbruster committed Dec 14, 2022
1 parent 10220d2 commit 66997c4
Show file tree
Hide file tree
Showing 27 changed files with 70 additions and 204 deletions.
14 changes: 4 additions & 10 deletions hw/9pfs/9p-synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ static V9fsSynthNode *v9fs_add_dir_node(V9fsSynthNode *parent, int mode,
int qemu_v9fs_synth_mkdir(V9fsSynthNode *parent, int mode,
const char *name, V9fsSynthNode **result)
{
int ret;
V9fsSynthNode *node, *tmp;

if (!synth_fs) {
Expand All @@ -87,8 +86,7 @@ int qemu_v9fs_synth_mkdir(V9fsSynthNode *parent, int mode,
QEMU_LOCK_GUARD(&synth_mutex);
QLIST_FOREACH(tmp, &parent->child, sibling) {
if (!strcmp(tmp->name, name)) {
ret = EEXIST;
return ret;
return EEXIST;
}
}
/* Add the name */
Expand All @@ -98,15 +96,13 @@ int qemu_v9fs_synth_mkdir(V9fsSynthNode *parent, int mode,
v9fs_add_dir_node(node, node->attr->mode, ".",
node->attr, node->attr->inode);
*result = node;
ret = 0;
return ret;
return 0;
}

int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode,
const char *name, v9fs_synth_read read,
v9fs_synth_write write, void *arg)
{
int ret;
V9fsSynthNode *node, *tmp;

if (!synth_fs) {
Expand All @@ -122,8 +118,7 @@ int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode,
QEMU_LOCK_GUARD(&synth_mutex);
QLIST_FOREACH(tmp, &parent->child, sibling) {
if (!strcmp(tmp->name, name)) {
ret = EEXIST;
return ret;
return EEXIST;
}
}
/* Add file type and remove write bits */
Expand All @@ -138,8 +133,7 @@ int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode,
node->private = arg;
pstrcpy(node->name, sizeof(node->name), name);
QLIST_INSERT_HEAD_RCU(&parent->child, node, sibling);
ret = 0;
return ret;
return 0;
}

static void synth_fill_statbuf(V9fsSynthNode *node, struct stat *stbuf)
Expand Down
4 changes: 1 addition & 3 deletions hw/char/sifive_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ SiFiveUARTState *sifive_uart_create(MemoryRegion *address_space, hwaddr base,
{
DeviceState *dev;
SysBusDevice *s;
SiFiveUARTState *r;

dev = qdev_new("riscv.sifive.uart");
s = SYS_BUS_DEVICE(dev);
Expand All @@ -284,6 +283,5 @@ SiFiveUARTState *sifive_uart_create(MemoryRegion *address_space, hwaddr base,
sysbus_mmio_get_region(s, 0));
sysbus_connect_irq(s, 0, irq);

r = SIFIVE_UART(dev);
return r;
return SIFIVE_UART(dev);
}
5 changes: 1 addition & 4 deletions hw/ppc/ppc4xx_sdram.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,13 +520,10 @@ static inline hwaddr sdram_ddr2_base(uint32_t bcr)

static hwaddr sdram_ddr2_size(uint32_t bcr)
{
hwaddr size;
int sh;

sh = 1024 - ((bcr >> 6) & 0x3ff);
size = 8 * MiB * sh;

return size;
return 8 * MiB * sh;
}

static uint32_t sdram_ddr2_dcr_read(void *opaque, int dcrn)
Expand Down
57 changes: 20 additions & 37 deletions hw/rdma/vmw/pvrdma_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,10 @@ static int create_pd(PVRDMADev *dev, union pvrdma_cmd_req *req,
{
struct pvrdma_cmd_create_pd *cmd = &req->create_pd;
struct pvrdma_cmd_create_pd_resp *resp = &rsp->create_pd_resp;
int rc;

memset(resp, 0, sizeof(*resp));
rc = rdma_rm_alloc_pd(&dev->rdma_dev_res, &dev->backend_dev,
&resp->pd_handle, cmd->ctx_handle);

return rc;
return rdma_rm_alloc_pd(&dev->rdma_dev_res, &dev->backend_dev,
&resp->pd_handle, cmd->ctx_handle);
}

static int destroy_pd(PVRDMADev *dev, union pvrdma_cmd_req *req,
Expand Down Expand Up @@ -504,20 +501,17 @@ static int modify_qp(PVRDMADev *dev, union pvrdma_cmd_req *req,
union pvrdma_cmd_resp *rsp)
{
struct pvrdma_cmd_modify_qp *cmd = &req->modify_qp;
int rc;

/* No need to verify sgid_index since it is u8 */

rc = rdma_rm_modify_qp(&dev->rdma_dev_res, &dev->backend_dev,
cmd->qp_handle, cmd->attr_mask,
cmd->attrs.ah_attr.grh.sgid_index,
(union ibv_gid *)&cmd->attrs.ah_attr.grh.dgid,
cmd->attrs.dest_qp_num,
(enum ibv_qp_state)cmd->attrs.qp_state,
cmd->attrs.qkey, cmd->attrs.rq_psn,
cmd->attrs.sq_psn);

return rc;
return rdma_rm_modify_qp(&dev->rdma_dev_res, &dev->backend_dev,
cmd->qp_handle, cmd->attr_mask,
cmd->attrs.ah_attr.grh.sgid_index,
(union ibv_gid *)&cmd->attrs.ah_attr.grh.dgid,
cmd->attrs.dest_qp_num,
(enum ibv_qp_state)cmd->attrs.qp_state,
cmd->attrs.qkey, cmd->attrs.rq_psn,
cmd->attrs.sq_psn);
}

static int query_qp(PVRDMADev *dev, union pvrdma_cmd_req *req,
Expand All @@ -526,15 +520,14 @@ static int query_qp(PVRDMADev *dev, union pvrdma_cmd_req *req,
struct pvrdma_cmd_query_qp *cmd = &req->query_qp;
struct pvrdma_cmd_query_qp_resp *resp = &rsp->query_qp_resp;
struct ibv_qp_init_attr init_attr;
int rc;

memset(resp, 0, sizeof(*resp));

rc = rdma_rm_query_qp(&dev->rdma_dev_res, &dev->backend_dev, cmd->qp_handle,
(struct ibv_qp_attr *)&resp->attrs, cmd->attr_mask,
&init_attr);

return rc;
return rdma_rm_query_qp(&dev->rdma_dev_res, &dev->backend_dev,
cmd->qp_handle,
(struct ibv_qp_attr *)&resp->attrs,
cmd->attr_mask,
&init_attr);
}

static int destroy_qp(PVRDMADev *dev, union pvrdma_cmd_req *req,
Expand All @@ -560,47 +553,37 @@ static int create_bind(PVRDMADev *dev, union pvrdma_cmd_req *req,
union pvrdma_cmd_resp *rsp)
{
struct pvrdma_cmd_create_bind *cmd = &req->create_bind;
int rc;
union ibv_gid *gid = (union ibv_gid *)&cmd->new_gid;

if (cmd->index >= MAX_PORT_GIDS) {
return -EINVAL;
}

rc = rdma_rm_add_gid(&dev->rdma_dev_res, &dev->backend_dev,
dev->backend_eth_device_name, gid, cmd->index);

return rc;
return rdma_rm_add_gid(&dev->rdma_dev_res, &dev->backend_dev,
dev->backend_eth_device_name, gid, cmd->index);
}

static int destroy_bind(PVRDMADev *dev, union pvrdma_cmd_req *req,
union pvrdma_cmd_resp *rsp)
{
int rc;

struct pvrdma_cmd_destroy_bind *cmd = &req->destroy_bind;

if (cmd->index >= MAX_PORT_GIDS) {
return -EINVAL;
}

rc = rdma_rm_del_gid(&dev->rdma_dev_res, &dev->backend_dev,
dev->backend_eth_device_name, cmd->index);

return rc;
return rdma_rm_del_gid(&dev->rdma_dev_res, &dev->backend_dev,
dev->backend_eth_device_name, cmd->index);
}

static int create_uc(PVRDMADev *dev, union pvrdma_cmd_req *req,
union pvrdma_cmd_resp *rsp)
{
struct pvrdma_cmd_create_uc *cmd = &req->create_uc;
struct pvrdma_cmd_create_uc_resp *resp = &rsp->create_uc_resp;
int rc;

memset(resp, 0, sizeof(*resp));
rc = rdma_rm_alloc_uc(&dev->rdma_dev_res, cmd->pfn, &resp->ctx_handle);

return rc;
return rdma_rm_alloc_uc(&dev->rdma_dev_res, cmd->pfn, &resp->ctx_handle);
}

static int destroy_uc(PVRDMADev *dev, union pvrdma_cmd_req *req,
Expand Down
6 changes: 1 addition & 5 deletions hw/virtio/vhost-user.c
Original file line number Diff line number Diff line change
Expand Up @@ -2533,11 +2533,7 @@ vhost_user_crypto_close_session(struct vhost_dev *dev, uint64_t session_id)
static bool vhost_user_mem_section_filter(struct vhost_dev *dev,
MemoryRegionSection *section)
{
bool result;

result = memory_region_get_fd(section->mr) >= 0;

return result;
return memory_region_get_fd(section->mr) >= 0;
}

static int vhost_user_get_inflight_fd(struct vhost_dev *dev,
Expand Down
7 changes: 2 additions & 5 deletions include/hw/pci/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -921,11 +921,8 @@ PCI_DMA_DEFINE_LDST(q_be, q_be, 64);
static inline void *pci_dma_map(PCIDevice *dev, dma_addr_t addr,
dma_addr_t *plen, DMADirection dir)
{
void *buf;

buf = dma_memory_map(pci_get_address_space(dev), addr, plen, dir,
MEMTXATTRS_UNSPECIFIED);
return buf;
return dma_memory_map(pci_get_address_space(dev), addr, plen, dir,
MEMTXATTRS_UNSPECIFIED);
}

static inline void pci_dma_unmap(PCIDevice *dev, void *buffer, dma_addr_t len,
Expand Down
10 changes: 2 additions & 8 deletions migration/dirtyrate.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ static void global_dirty_log_sync(unsigned int flag, bool one_shot)
static DirtyPageRecord *vcpu_dirty_stat_alloc(VcpuStat *stat)
{
CPUState *cpu;
DirtyPageRecord *records;
int nvcpu = 0;

CPU_FOREACH(cpu) {
Expand All @@ -121,9 +120,7 @@ static DirtyPageRecord *vcpu_dirty_stat_alloc(VcpuStat *stat)
stat->nvcpu = nvcpu;
stat->rates = g_new0(DirtyRateVcpu, nvcpu);

records = g_new0(DirtyPageRecord, nvcpu);

return records;
return g_new0(DirtyPageRecord, nvcpu);
}

static void vcpu_dirty_stat_collect(VcpuStat *stat,
Expand Down Expand Up @@ -473,7 +470,6 @@ find_block_matched(RAMBlock *block, int count,
struct RamblockDirtyInfo *infos)
{
int i;
struct RamblockDirtyInfo *matched;

for (i = 0; i < count; i++) {
if (!strcmp(infos[i].idstr, qemu_ram_get_idstr(block))) {
Expand All @@ -492,9 +488,7 @@ find_block_matched(RAMBlock *block, int count,
return NULL;
}

matched = &infos[i];

return matched;
return &infos[i];
}

static bool compare_page_hash_info(struct RamblockDirtyInfo *info,
Expand Down
6 changes: 1 addition & 5 deletions migration/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ QIOChannelTLS *migration_tls_client_create(MigrationState *s,
Error **errp)
{
QCryptoTLSCreds *creds;
QIOChannelTLS *tioc;

creds = migration_tls_get_creds(
s, QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT, errp);
Expand All @@ -138,10 +137,7 @@ QIOChannelTLS *migration_tls_client_create(MigrationState *s,
hostname = s->parameters.tls_hostname;
}

tioc = qio_channel_tls_new_client(
ioc, creds, hostname, errp);

return tioc;
return qio_channel_tls_new_client(ioc, creds, hostname, errp);
}

void migration_tls_channel_connect(MigrationState *s,
Expand Down
5 changes: 1 addition & 4 deletions replay/replay-time.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,12 @@ void replay_read_next_clock(ReplayClockKind kind)
/*! Reads next clock event from the input. */
int64_t replay_read_clock(ReplayClockKind kind, int64_t raw_icount)
{
int64_t ret;
g_assert(replay_file && replay_mutex_locked());

replay_advance_current_icount(raw_icount);

if (replay_next_event_is(EVENT_CLOCK + kind)) {
replay_read_next_clock(kind);
}
ret = replay_state.cached_clock[kind];

return ret;
return replay_state.cached_clock[kind];
}
5 changes: 2 additions & 3 deletions scripts/coccinelle/return_directly.cocci
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ identifier F;
- T VAR;
... when != VAR

- VAR =
+ return
E;
- VAR = (E);
- return VAR;
+ return E;
... when != VAR
}
4 changes: 1 addition & 3 deletions semihosting/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ static SemihostingConsole console;
static int console_can_read(void *opaque)
{
SemihostingConsole *c = opaque;
int ret;
g_assert(qemu_mutex_iothread_locked());
ret = (int) fifo8_num_free(&c->fifo);
return ret;
return (int)fifo8_num_free(&c->fifo);
}

static void console_wake_up(gpointer data, gpointer user_data)
Expand Down
11 changes: 2 additions & 9 deletions softmmu/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -2372,20 +2372,15 @@ void memory_region_reset_dirty(MemoryRegion *mr, hwaddr addr,

int memory_region_get_fd(MemoryRegion *mr)
{
int fd;

RCU_READ_LOCK_GUARD();
while (mr->alias) {
mr = mr->alias;
}
fd = mr->ram_block->fd;

return fd;
return mr->ram_block->fd;
}

void *memory_region_get_ram_ptr(MemoryRegion *mr)
{
void *ptr;
uint64_t offset = 0;

RCU_READ_LOCK_GUARD();
Expand All @@ -2394,9 +2389,7 @@ void *memory_region_get_ram_ptr(MemoryRegion *mr)
mr = mr->alias;
}
assert(mr->ram_block);
ptr = qemu_map_ram_ptr(mr->ram_block, offset);

return ptr;
return qemu_map_ram_ptr(mr->ram_block, offset);
}

MemoryRegion *memory_region_from_host(void *ptr, ram_addr_t *offset)
Expand Down
9 changes: 2 additions & 7 deletions softmmu/physmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -3236,7 +3236,6 @@ void *address_space_map(AddressSpace *as,
hwaddr len = *plen;
hwaddr l, xlat;
MemoryRegion *mr;
void *ptr;
FlatView *fv;

if (len == 0) {
Expand Down Expand Up @@ -3275,9 +3274,7 @@ void *address_space_map(AddressSpace *as,
*plen = flatview_extend_translation(fv, addr, len, mr, xlat,
l, is_write, attrs);
fuzz_dma_read_cb(addr, *plen, mr);
ptr = qemu_ram_ptr_length(mr->ram_block, xlat, plen, true);

return ptr;
return qemu_ram_ptr_length(mr->ram_block, xlat, plen, true);
}

/* Unmaps a memory region previously mapped by address_space_map().
Expand Down Expand Up @@ -3545,15 +3542,13 @@ bool cpu_physical_memory_is_io(hwaddr phys_addr)
{
MemoryRegion*mr;
hwaddr l = 1;
bool res;

RCU_READ_LOCK_GUARD();
mr = address_space_translate(&address_space_memory,
phys_addr, &phys_addr, &l, false,
MEMTXATTRS_UNSPECIFIED);

res = !(memory_region_is_ram(mr) || memory_region_is_romd(mr));
return res;
return !(memory_region_is_ram(mr) || memory_region_is_romd(mr));
}

int qemu_ram_foreach_block(RAMBlockIterFunc func, void *opaque)
Expand Down
Loading

0 comments on commit 66997c4

Please sign in to comment.