Skip to contentSkip to conversation

spaces are required in some places

PATCH New chaihaoyu 3 participants 8 messages Oct 29, 2020 – Nov 4, 2020

lore
Share & tools
lore

chaihaoyu

author
#0 lore raw

PATCH 1/1 spaces are required in some places

Date: Thu, 29 Oct 2020 22:01:33 +0800

While reading softmmu related code, I found some style problems. Some spaces are required in softmmu/memory.c

---
 softmmu/memory.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
softmmu/memory.c +9 -9
index ee4a6bc168..550cffe8f6 100644
@@ -158,7 +158,7 @@ enum ListenerDirection { Forward, Reverse };
         MemoryRegionSection mrs = section_from_flat_range(fr,           \
                 address_space_to_flatview(as));                         \
         MEMORY_LISTENER_CALL(as, callback, dir, &mrs, ##_args);         \
-    } while(0)
+    } while (0)
 
 struct CoalescedMemoryRange {
     AddrRange addr;
@@ -329,7 +329,7 @@ static void flatview_simplify(FlatView *view)
     while (i < view->nr) {
         j = i + 1;
         while (j < view->nr
-               && can_merge(&view->ranges[j-1], &view->ranges[j])) {
+               && can_merge(&view->ranges[j - 1], &view->ranges[j])) {
             int128_addto(&view->ranges[i].addr.size, view->ranges[j].addr.size);
             ++j;
         }
@@ -834,8 +834,8 @@ static void address_space_update_ioeventfds(AddressSpace *as)
                     ioeventfds = g_realloc(ioeventfds,
                             ioeventfd_max * sizeof(*ioeventfds));
                 }
-                ioeventfds[ioeventfd_nb-1] = fr->mr->ioeventfds[i];
-                ioeventfds[ioeventfd_nb-1].addr = tmp;
+                ioeventfds[ioeventfd_nb - 1] = fr->mr->ioeventfds[i];
+                ioeventfds[ioeventfd_nb - 1].addr = tmp;
             }
         }
     }
@@ -2343,8 +2343,8 @@ void memory_region_add_eventfd(MemoryRegion *mr,
     ++mr->ioeventfd_nb;
     mr->ioeventfds = g_realloc(mr->ioeventfds,
                                   sizeof(*mr->ioeventfds) * mr->ioeventfd_nb);
-    memmove(&mr->ioeventfds[i+1], &mr->ioeventfds[i],
-            sizeof(*mr->ioeventfds) * (mr->ioeventfd_nb-1 - i));
+    memmove(&mr->ioeventfds[i + 1], &mr->ioeventfds[i],
+            sizeof(*mr->ioeventfds) * (mr->ioeventfd_nb - 1 - i));
     mr->ioeventfds[i] = mrfd;
     ioeventfd_update_pending |= mr->enabled;
     memory_region_transaction_commit();
@@ -2376,11 +2376,11 @@ void memory_region_del_eventfd(MemoryRegion *mr,
         }
     }
     assert(i != mr->ioeventfd_nb);
-    memmove(&mr->ioeventfds[i], &mr->ioeventfds[i+1],
-            sizeof(*mr->ioeventfds) * (mr->ioeventfd_nb - (i+1)));
+    memmove(&mr->ioeventfds[i], &mr->ioeventfds[i + 1],
+            sizeof(*mr->ioeventfds) * (mr->ioeventfd_nb - (i + 1)));
     --mr->ioeventfd_nb;
     mr->ioeventfds = g_realloc(mr->ioeventfds,
-                                  sizeof(*mr->ioeventfds)*mr->ioeventfd_nb + 1);
+                                  sizeof(*mr->ioeventfds) * mr->ioeventfd_nb + 1);
     ioeventfd_update_pending |= mr->enabled;
     memory_region_transaction_commit();
 }
#1 lore raw
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [PATCH] spaces are required in some places

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
bd92beb spaces are required in some places

=== OUTPUT BEGIN ===
ERROR: The correct form is "Signed-off-by"
#7:

WARNING: line over 80 characters
#68: FILE: softmmu/memory.c:2383:
+ sizeof(*mr->ioeventfds) * mr->ioeventfd_nb + 1);

total: 1 errors, 1 warnings, 50 lines checked

Commit bd92beb6573c (spaces are required in some places) has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

author
#2 lore raw

PATCH v2 1/3 softmmu: Do not use C99 // comments

Hi, recently I found some code style problems while using checkpatch.pl tool,please review.

Date: Tue, 3 Nov 2020 11:01:40 +0800

---
 softmmu/memory.c         | 2 +-
 softmmu/memory_mapping.c | 2 +-
 softmmu/physmem.c        | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
softmmu/memory.c +1 -1
index 107ce0a4f8..5fb591b001 100644
@@ -36,7 +36,7 @@
 #include "hw/boards.h"
 #include "migration/vmstate.h"
 
-//#define DEBUG_UNASSIGNED
+/* #define DEBUG_UNASSIGNED */
 
 static unsigned memory_region_transaction_depth;
 static bool memory_region_update_pending;
softmmu/memory_mapping.c +1 -1
index 18d0b8067c..f64053499e 100644
@@ -19,7 +19,7 @@
 #include "exec/memory.h"
 #include "exec/address-spaces.h"
 
-//#define DEBUG_GUEST_PHYS_REGION_ADD
+/* #define DEBUG_GUEST_PHYS_REGION_ADD */
 
 static void memory_mapping_list_add_mapping_sorted(MemoryMappingList *list,
                                                    MemoryMapping *mapping)
softmmu/physmem.c +1 -1
index 44ffb60b5d..78c1b6580a 100644
@@ -75,7 +75,7 @@
 #include <daxctl/libdaxctl.h>
 #endif
 
-//#define DEBUG_SUBPAGE
+/* #define DEBUG_SUBPAGE */
 
 /* ram_list is read under rcu_read_lock()/rcu_read_unlock().  Writes
  * are protected by the ramlist lock.
author
#3 lore raw

PATCH v2 2/3 softmmu: Don't use '#' flag of printf format

Hi, recently I found some code style problems while using checkpatch.pl tool,please review.

Date: Tue, 3 Nov 2020 11:01:40 +0800
Subject: [PATCH] Don't use '#' flag of printf format

---
 softmmu/device_tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
softmmu/device_tree.c +1 -1
index b335dae707..c70215ba6a 100644
@@ -367,7 +367,7 @@ int qemu_fdt_setprop_cell(void *fdt, const char *node_path,
 
     r = fdt_setprop_cell(fdt, findnode_nofail(fdt, node_path), property, val);
     if (r < 0) {
-        error_report("%s: Couldn't set %s/%s = %#08x: %s", __func__,
+        error_report("%s: Couldn't set %s/%s = 0x%08x: %s", __func__,
                      node_path, property, val, fdt_strerror(r));
         exit(1);
     }
Signature · 1 line
2.29.1.59.gf9b6481aed
author
#4 lore raw

PATCH v2 3/3 softmmu: braces {} are necessary for all arms of this statement

In reply to chaihaoyu

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

---

---
 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(-)
softmmu/cpus.c +4 -2
index e46ac68ad0..3e08a64d6b 100644
@@ -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);
softmmu/dma-helpers.c +2 -1
index 03c92e0cc6..9194ebf681 100644
@@ -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) {
softmmu/memory.c +2 -1
index 550cffe8f6..107ce0a4f8 100644
@@ -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;
+        }
     }
 }
 
softmmu/physmem.c +10 -5
index a9adedb9f8..44ffb60b5d 100644
@@ -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,
softmmu/qdev-monitor.c +9 -6
index bcfb90a08f..e283d9c9c0 100644
@@ -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)
softmmu/vl.c +32 -17

142 lines not on this page · raw message

author
#5 lore raw

v2 cover softmmu: some space-style problems while coding

In reply to chaihaoyu

Hi, recently I found some code style problems while using checkpatch.pl tool,please review.

Date: Tue, 3 Nov 2020 11:19:37 +0800
Subject: [PATCH] space style

---
 softmmu/physmem.c      |  2 +-
 softmmu/qdev-monitor.c |  4 ++--
 softmmu/vl.c           | 12 ++++++------
 3 files changed, 9 insertions(+), 9 deletions(-)
softmmu/physmem.c +1 -1
index 78c1b6580a..44b068ee85 100644
@@ -3457,7 +3457,7 @@ int qemu_target_page_bits_min(void)
 
 bool cpu_physical_memory_is_io(hwaddr phys_addr)
 {
-    MemoryRegion*mr;
+    MemoryRegion *mr;
     hwaddr l = 1;
     bool res;
 
softmmu/qdev-monitor.c +2 -2
index e283d9c9c0..c2b218adce 100644
@@ -500,7 +500,7 @@ static BusState *qbus_find(const char *path, Error **errp)
         }
 
         /* find device */
-        if (sscanf(path+pos, "%127[^/]%n", elem, &len) != 1) {
+        if (sscanf(path + pos, "%127[^/]%n", elem, &len) != 1) {
             g_assert_not_reached();
             elem[0] = len = 0;
         }
@@ -535,7 +535,7 @@ static BusState *qbus_find(const char *path, Error **errp)
         }
 
         /* find bus */
-        if (sscanf(path+pos, "%127[^/]%n", elem, &len) != 1) {
+        if (sscanf(path + pos, "%127[^/]%n", elem, &len) != 1) {
             g_assert_not_reached();
             elem[0] = len = 0;
         }
softmmu/vl.c +6 -6
index c4667d91fe..d37520a356 100644
@@ -2418,7 +2418,7 @@ static const QEMUOption *lookup_opt(int argc, char **argv,
         r++;
     }
     popt = qemu_options;
-    for(;;) {
+    for (;;) {
         if (!popt->name) {
             error_report("invalid option");
             exit(1);
@@ -3008,7 +3008,7 @@ void qemu_init(int argc, char **argv, char **envp)
 
     /* second pass of option parsing */
     optind = 1;
-    for(;;) {
+    for (;;) {
         if (optind >= argc) {
             break;
         }
@@ -3023,7 +3023,7 @@ void qemu_init(int argc, char **argv, char **envp)
                 error_report("Option not supported for this target");
                 exit(1);
             }
-            switch(popt->index) {
+            switch (popt->index) {
             case QEMU_OPTION_cpu:
                 /* hw initialization will check this */
                 cpu_option = optarg;
@@ -3182,13 +3182,13 @@ void qemu_init(int argc, char **argv, char **envp)
 #endif
             case QEMU_OPTION_audio_help:
                 audio_legacy_help();
-                exit (0);
+                exit(0);
                 break;
             case QEMU_OPTION_audiodev:
                 audio_parse_option(optarg);
                 break;
             case QEMU_OPTION_soundhw:
-                select_soundhw (optarg);
+                select_soundhw(optarg);
                 break;
             case QEMU_OPTION_h:
                 help(0);
@@ -4323,7 +4323,7 @@ void qemu_init(int argc, char **argv, char **envp)
     if (watchdog) {
         i = select_watchdog(watchdog);
         if (i > 0)
-            exit (i == 1 ? 1 : 0);
+            exit(i == 1 ? 1 : 0);
     }
 
     /* This checkpoint is required by replay to separate prior clock
#6 lore raw

Re: [PATCH v2 1/3] softmmu: Do not use C99 // comments

In reply to chaihaoyu
Quoted 41 lines · chaihaoyu

Hi, recently I found some code style problems while using checkpatch.pl tool,please review.

Date: Tue, 3 Nov 2020 11:01:40 +0800

---
 softmmu/memory.c         | 2 +-
 softmmu/memory_mapping.c | 2 +-
 softmmu/physmem.c        | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
softmmu/memory.c +1 -1
index 107ce0a4f8..5fb591b001 100644
@@ -36,7 +36,7 @@
 #include "hw/boards.h"
 #include "migration/vmstate.h"
 
-//#define DEBUG_UNASSIGNED
+/* #define DEBUG_UNASSIGNED */
 
 static unsigned memory_region_transaction_depth;
 static bool memory_region_update_pending;
softmmu/memory_mapping.c +1 -1
index 18d0b8067c..f64053499e 100644
@@ -19,7 +19,7 @@
 #include "exec/memory.h"
 #include "exec/address-spaces.h"
 
-//#define DEBUG_GUEST_PHYS_REGION_ADD
+/* #define DEBUG_GUEST_PHYS_REGION_ADD */
 
 static void memory_mapping_list_add_mapping_sorted(MemoryMappingList *list,
                                                    MemoryMapping *mapping)
softmmu/physmem.c +0 -0
index 44ffb60b5d..78c1b6580a 100644

softmmu/physmem.c line 81

Quoted 8 lines
softmmu/physmem.c +1 -1
@@ -75,7 +75,7 @@
 #include <daxctl/libdaxctl.h>
 #endif
 
-//#define DEBUG_SUBPAGE
+/* #define DEBUG_SUBPAGE */
 
 /* ram_list is read under rcu_read_lock()/rcu_read_unlock().  Writes
  * are protected by the ramlist lock.

I recommend to leave these alone.

CODING_STYLE.rst:

Rationale: The // form is valid in C99, so this is purely a matter of consistency of style. The checkpatch script will warn you about this.

For "real" comments, we overwhelmingly use /* */, and avoiding // makes sense. Most exceptions are in code we copy from elsewhere, such as disas/libvixl/.

For commenting out *code*, we use both forms. Here are the counts for commenting out macro definitions:

    $ git-grep '^/\* *# *define' | wc -l
    125
    $ git-grep '^// *# *define' | wc -l
    192
author
#7 lore raw

Re: [PATCH v2 1/3] softmmu: Do not use C99 // comments

Thank you for your replay. That's OK if C99 support both kinds of comment style.

————————————————————————————————————————————————

Quoted 73 lines
Quoted 41 lines · chaihaoyu

Hi, recently I found some code style problems while using checkpatch.pl tool,please review.

Date: Tue, 3 Nov 2020 11:01:40 +0800

---
 softmmu/memory.c         | 2 +-
 softmmu/memory_mapping.c | 2 +-
 softmmu/physmem.c        | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
softmmu/memory.c +1 -1
index 107ce0a4f8..5fb591b001 100644
@@ -36,7 +36,7 @@
 #include "hw/boards.h"
 #include "migration/vmstate.h"
 
-//#define DEBUG_UNASSIGNED
+/* #define DEBUG_UNASSIGNED */
 
 static unsigned memory_region_transaction_depth;
 static bool memory_region_update_pending;
softmmu/memory_mapping.c +1 -1
index 18d0b8067c..f64053499e 100644
@@ -19,7 +19,7 @@
 #include "exec/memory.h"
 #include "exec/address-spaces.h"
 
-//#define DEBUG_GUEST_PHYS_REGION_ADD
+/* #define DEBUG_GUEST_PHYS_REGION_ADD */
 
 static void memory_mapping_list_add_mapping_sorted(MemoryMappingList *list,
                                                    MemoryMapping *mapping)
softmmu/physmem.c +0 -0
index 44ffb60b5d..78c1b6580a 100644

softmmu/physmem.c line 81

Quoted 8 lines
softmmu/physmem.c +1 -1
@@ -75,7 +75,7 @@
 #include <daxctl/libdaxctl.h>
 #endif
 
-//#define DEBUG_SUBPAGE
+/* #define DEBUG_SUBPAGE */
 
 /* ram_list is read under rcu_read_lock()/rcu_read_unlock().  Writes
  * are protected by the ramlist lock.

I recommend to leave these alone.

CODING_STYLE.rst:

Rationale: The // form is valid in C99, so this is purely a matter of consistency of style. The checkpatch script will warn you about this.

For "real" comments, we overwhelmingly use /* */, and avoiding // makes sense. Most exceptions are in code we copy from elsewhere, such as disas/libvixl/.

For commenting out *code*, we use both forms. Here are the counts for commenting out macro definitions:

    $ git-grep '^/\* *# *define' | wc -l
    125
    $ git-grep '^// *# *define' | wc -l
    192

.