Hi, recently I found some code style problems while using checkpatch.pl tool,please review.
Date: Tue, 3 Nov 2020 10:09:34 +0800 Subject: [PATCH] braces {} are necessary for all arms of this statement signed-off-by: Haoyu Chai<chaihao...@huawei.com> --- --- softmmu/cpus.c | 6 ++++-- softmmu/dma-helpers.c | 3 ++- softmmu/memory.c | 3 ++- softmmu/physmem.c | 15 ++++++++----- softmmu/qdev-monitor.c | 15 +++++++------ softmmu/vl.c | 49 +++++++++++++++++++++++++++--------------- 6 files changed, 59 insertions(+), 32 deletions(-) diff --git a/softmmu/cpus.c b/softmmu/cpus.c index e46ac68ad0..3e08a64d6b 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -743,8 +743,9 @@ void qmp_memsave(int64_t addr, int64_t size, const char *filename, while (size != 0) { l = sizeof(buf); - if (l > size) + if (l > size) { l = size; + } if (cpu_memory_rw_debug(cpu, addr, buf, l, 0) != 0) { error_setg(errp, "Invalid addr 0x%016" PRIx64 "/size %" PRId64 " specified", orig_addr, orig_size); @@ -777,8 +778,9 @@ void qmp_pmemsave(int64_t addr, int64_t size, const char *filename, while (size != 0) { l = sizeof(buf); - if (l > size) + if (l > size) { l = size; + } cpu_physical_memory_read(addr, buf, l); if (fwrite(buf, 1, l, f) != l) { error_setg(errp, QERR_IO_ERROR); diff --git a/softmmu/dma-helpers.c b/softmmu/dma-helpers.c index 03c92e0cc6..9194ebf681 100644 --- a/softmmu/dma-helpers.c +++ b/softmmu/dma-helpers.c @@ -164,8 +164,9 @@ static void dma_blk_cb(void *opaque, int ret) } } } - if (!mem) + if (!mem) { break; + } qemu_iovec_add(&dbs->iov, mem, cur_len); dbs->sg_cur_byte += cur_len; if (dbs->sg_cur_byte == dbs->sg->sg[dbs->sg_cur_index].len) { diff --git a/softmmu/memory.c b/softmmu/memory.c index 550cffe8f6..107ce0a4f8 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -664,8 +664,9 @@ void flatview_for_each_range(FlatView *fv, flatview_cb cb , void *opaque) assert(cb); FOR_EACH_FLAT_RANGE(fr, fv) { - if (cb(fr->addr.start, fr->addr.size, fr->mr, opaque)) + if (cb(fr->addr.start, fr->addr.size, fr->mr, opaque)) { break; + } } } diff --git a/softmmu/physmem.c b/softmmu/physmem.c index a9adedb9f8..44ffb60b5d 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -797,8 +797,9 @@ int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len, tlb_flush(cpu); } - if (watchpoint) + if (watchpoint) { *watchpoint = wp; + } return 0; } @@ -1210,8 +1211,9 @@ void flatview_add_to_dispatch(FlatView *fv, MemoryRegionSection *section) void qemu_flush_coalesced_mmio_buffer(void) { - if (kvm_enabled()) + if (kvm_enabled()) { kvm_flush_coalesced_mmio_buffer(); + } } void qemu_mutex_lock_ramlist(void) @@ -2495,8 +2497,9 @@ static int subpage_register(subpage_t *mmio, uint32_t start, uint32_t end, { int idx, eidx; - if (start >= TARGET_PAGE_SIZE || end >= TARGET_PAGE_SIZE) + if (start >= TARGET_PAGE_SIZE || end >= TARGET_PAGE_SIZE) { return -1; + } idx = SUBPAGE_IDX(start); eidx = SUBPAGE_IDX(end); #if defined(DEBUG_SUBPAGE) @@ -3408,11 +3411,13 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr, phys_addr = cpu_get_phys_page_attrs_debug(cpu, page, &attrs); asidx = cpu_asidx_from_attrs(cpu, attrs); /* if no physical page mapped, return an error */ - if (phys_addr == -1) + if (phys_addr == -1) { return -1; + } l = (page + TARGET_PAGE_SIZE) - addr; - if (l > len) + if (l > len) { l = len; + } phys_addr += (addr & ~TARGET_PAGE_MASK); if (is_write) { res = address_space_write_rom(cpu->cpu_ases[asidx].as, phys_addr, diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index bcfb90a08f..e283d9c9c0 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -44,8 +44,7 @@ * Aliases were a bad idea from the start. Let's keep them * from spreading further. */ -typedef struct QDevAlias -{ +typedef struct QDevAlias { const char *typename; const char *alias; uint32_t arch_mask; @@ -180,10 +179,12 @@ static int set_property(void *opaque, const char *name, const char *value, { Object *obj = opaque; - if (strcmp(name, "driver") == 0) + if (strcmp(name, "driver") == 0) { return 0; - if (strcmp(name, "bus") == 0) + } + if (strcmp(name, "bus") == 0) { return 0; + } if (!object_property_parse(obj, name, value, errp)) { return -1; @@ -694,8 +695,9 @@ static void qbus_print(Monitor *mon, BusState *bus, int indent); static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props, int indent) { - if (!props) + if (!props) { return; + } for (; props->name; props++) { char *value; char *legacy_name = g_strdup_printf("legacy-%s", props->name); @@ -780,8 +782,9 @@ static void qbus_print(Monitor *mon, BusState *bus, int indent) void hmp_info_qtree(Monitor *mon, const QDict *qdict) { - if (sysbus_get_default()) + if (sysbus_get_default()) { qbus_print(mon, sysbus_get_default(), 0); + } } void hmp_info_qdm(Monitor *mon, const QDict *qdict) diff --git a/softmmu/vl.c b/softmmu/vl.c index 7c1c6d37ef..c4667d91fe 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -533,11 +533,13 @@ static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp) const char *driver = qemu_opt_get(opts, "driver"); int i; - if (!driver) + if (!driver) { return 0; + } for (i = 0; i < ARRAY_SIZE(default_list); i++) { - if (strcmp(default_list[i].driver, driver) != 0) + if (strcmp(default_list[i].driver, driver) != 0) { continue; + } *(default_list[i].flag) = 0; } return 0; @@ -1138,9 +1140,9 @@ static int usb_device_add(const char *devname) } dev = usbdevice_create(devname); - if (!dev) + if (!dev) { return -1; - + } return 0; } @@ -1845,10 +1847,12 @@ static void select_vgahw(const MachineClass *machine_class, const char *p) if (strstart(opts, ",retrace=", &nextopt)) { opts = nextopt; - if (strstart(opts, "dumb", &nextopt)) + if (strstart(opts, "dumb", &nextopt)) { vga_retrace_method = VGA_RETRACE_DUMB; - else if (strstart(opts, "precise", &nextopt)) + } + else if (strstart(opts, "precise", &nextopt)) { vga_retrace_method = VGA_RETRACE_PRECISE; + } else goto invalid_vga; } else goto invalid_vga; opts = nextopt; @@ -2201,8 +2205,9 @@ static int foreach_device_config(int type, int (*func)(const char *cmdline)) int rc; QTAILQ_FOREACH(conf, &device_configs, next) { - if (conf->type != type) + if (conf->type != type) { continue; + } loc_push_restore(&conf->loc); rc = func(conf->cmdline); loc_pop(&conf->loc); @@ -2218,8 +2223,9 @@ static int serial_parse(const char *devname) int index = num_serial_hds; char label[32]; - if (strcmp(devname, "none") == 0) + if (strcmp(devname, "none") == 0) { return 0; + } snprintf(label, sizeof(label), "serial%d", index); serial_hds = g_renew(Chardev *, serial_hds, index + 1); @@ -2252,8 +2258,9 @@ static int parallel_parse(const char *devname) static int index = 0; char label[32]; - if (strcmp(devname, "none") == 0) + if (strcmp(devname, "none") == 0) { return 0; + } if (index == MAX_PARALLEL_PORTS) { error_report("too many parallel ports"); exit(1); @@ -2407,16 +2414,18 @@ static const QEMUOption *lookup_opt(int argc, char **argv, loc_set_cmdline(argv, optind, 1); optind++; /* Treat --foo the same as -foo. */ - if (r[1] == '-') + if (r[1] == '-') { r++; + } popt = qemu_options; for(;;) { if (!popt->name) { error_report("invalid option"); exit(1); } - if (!strcmp(popt->name, r + 1)) + if (!strcmp(popt->name, r + 1)) { break; + } popt++; } if (popt->flags & HAS_ARG) { @@ -3000,8 +3009,9 @@ void qemu_init(int argc, char **argv, char **envp) /* second pass of option parsing */ optind = 1; for(;;) { - if (optind >= argc) + if (optind >= argc) { break; + } if (argv[optind][0] != '-') { loc_set_cmdline(argv, optind, 1); drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS); @@ -3047,12 +3057,14 @@ void qemu_init(int argc, char **argv, char **envp) } break; case QEMU_OPTION_set: - if (qemu_set_option(optarg) != 0) + if (qemu_set_option(optarg) != 0) { exit(1); + } break; case QEMU_OPTION_global: - if (qemu_global_option(optarg) != 0) + if (qemu_global_option(optarg) != 0) { exit(1); + } break; case QEMU_OPTION_mtdblock: drive_add(IF_MTD, -1, optarg, MTD_OPTS); @@ -3258,12 +3270,14 @@ void qemu_init(int argc, char **argv, char **envp) error_report("invalid resolution or depth"); exit(1); } - if (*p != 'x') + if (*p != 'x') { goto graphic_error; + } p++; h = strtol(p, (char **)&p, 10); - if (h <= 0) + if (h <= 0) { goto graphic_error; + } if (*p == 'x') { p++; depth = strtol(p, (char **)&p, 10); @@ -3286,8 +3300,9 @@ void qemu_init(int argc, char **argv, char **envp) { char *r; term_escape_char = strtol(optarg, &r, 0); - if (r == optarg) + if (r == optarg) { printf("Bad argument to echr\n"); + } break; } case QEMU_OPTION_monitor: --