Skip to contentSkip to conversation

Compress lines for immediate return

PATCH Superseded Simran Singhal 4 participants 6 messages Apr 1, 2020 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Compress lines for immediate return

Compress two lines into a single line if immediate return statement is found.

It also remove variables progress, val, data, ret and sock as they are no longer needed.

Remove space between function "mixer_load" and '(' to fix the checkpatch.pl error:-
ERROR: space prohibited between function name and open parenthesis '('

---
 block/file-posix.c      | 3 +--
 block/nfs.c             | 3 +--
 block/nvme.c            | 4 +---
 block/vhdx.c            | 3 +--
 hw/audio/ac97.c         | 4 +---
 hw/audio/adlib.c        | 5 +----
 hw/display/cirrus_vga.c | 4 +---
 migration/ram.c         | 4 +---
 ui/gtk.c                | 3 +--
 util/qemu-sockets.c     | 5 +----
 10 files changed, 10 insertions(+), 28 deletions(-)
block/file-posix.c +1 -2
index 7e19bbff5f..dc01f0d4d3 100644
@@ -1627,8 +1627,7 @@ static int handle_aiocb_write_zeroes_unmap(void *opaque)
 
     /* If we couldn't manage to unmap while guaranteed that the area reads as
      * all-zero afterwards, just write zeroes without unmapping */
-    ret = handle_aiocb_write_zeroes(aiocb);
-    return ret;
+    return handle_aiocb_write_zeroes(aiocb);
 }
 
 #ifndef HAVE_COPY_FILE_RANGE
block/nfs.c +1 -2
index cc2413d5ab..100f15bd1f 100644
@@ -623,8 +623,7 @@ static int nfs_file_open(BlockDriverState *bs, QDict *options, int flags,
     }
 
     bs->total_sectors = ret;
-    ret = 0;
-    return ret;
+    return 0;
 }
 
 static QemuOptsList nfs_create_opts = {
block/nvme.c +1 -3
index 7b7c0cc5d6..eb2f54dd9d 100644
@@ -575,11 +575,9 @@ static bool nvme_poll_cb(void *opaque)
 {
     EventNotifier *e = opaque;
     BDRVNVMeState *s = container_of(e, BDRVNVMeState, irq_notifier);
-    bool progress = false;
 
     trace_nvme_poll_cb(s);
-    progress = nvme_poll_queues(s);
-    return progress;
+    return nvme_poll_queues(s);
 }
 
 static int nvme_init(BlockDriverState *bs, const char *device, int namespace,
block/vhdx.c +1 -2
index 33e57cd656..2c0e7ee44d 100644
@@ -411,8 +411,7 @@ int vhdx_update_headers(BlockDriverState *bs, BDRVVHDXState *s,
     if (ret < 0) {
         return ret;
     }
-    ret = vhdx_update_header(bs, s, generate_data_write_guid, log_guid);
-    return ret;
+    return vhdx_update_header(bs, s, generate_data_write_guid, log_guid);
 }
 
 /* opens the specified header block from the VHDX file header section */
hw/audio/ac97.c +1 -3
index 1ec87feec0..8a9b9924c4 100644
@@ -573,11 +573,9 @@ static uint32_t nam_readb (void *opaque, uint32_t addr)
 static uint32_t nam_readw (void *opaque, uint32_t addr)
 {
     AC97LinkState *s = opaque;
-    uint32_t val = ~0U;
     uint32_t index = addr;
     s->cas = 0;
-    val = mixer_load (s, index);
-    return val;
+    return mixer_load(s, index);
 }
 
 static uint32_t nam_readl (void *opaque, uint32_t addr)
hw/audio/adlib.c +1 -4
index d6c1fb0586..7c3b67dcfb 100644
@@ -120,13 +120,10 @@ static void adlib_write(void *opaque, uint32_t nport, uint32_t val)
 static uint32_t adlib_read(void *opaque, uint32_t nport)
 {
     AdlibState *s = opaque;
-    uint8_t data;
     int a = nport & 3;
 
     adlib_kill_timers (s);
-    data = OPLRead (s->opl, a);
-
-    return data;
+    return OPLRead (s->opl, a);
 }
 
 static void timer_handler (void *opaque, int c, double interval_Sec)
hw/display/cirrus_vga.c +1 -3
index 0d391e1300..1f29731ffe 100644
@@ -2411,12 +2411,10 @@ static uint64_t cirrus_linear_bitblt_read(void *opaque,
                                           unsigned size)
 {
     CirrusVGAState *s = opaque;
-    uint32_t ret;
 
     /* XXX handle bitblt */
     (void)s;
-    ret = 0xff;
-    return ret;
+    return 0xff;
 }
 
 static void cirrus_linear_bitblt_write(void *opaque,
migration/ram.c +1 -3
index 04f13feb2e..06cba88632 100644
@@ -2135,9 +2135,7 @@ int ram_postcopy_send_discard_bitmap(MigrationState *ms)
     }
     trace_ram_postcopy_send_discard_bitmap();
 
-    ret = postcopy_each_ram_send_discard(ms);
-
-    return ret;
+    return postcopy_each_ram_send_discard(ms);
 }
 
 /**
ui/gtk.c +1 -2
index 030b251c61..83f2f5d49b 100644
@@ -1650,8 +1650,7 @@ static GSList *gd_vc_menu_init(GtkDisplayState *s, VirtualConsole *vc,
                      G_CALLBACK(gd_menu_switch_vc), s);
     gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), vc->menu_item);
 
-    group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc->menu_item));
-    return group;
+    return gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc->menu_item));
 }
 
 #if defined(CONFIG_VTE)
util/qemu-sockets.c +1 -4
index bcc06d0e01..86c48b9fa5 100644
@@ -765,15 +765,12 @@ static int vsock_connect_addr(const struct sockaddr_vm *svm, Error **errp)
 static int vsock_connect_saddr(VsockSocketAddress *vaddr, Error **errp)
 {
     struct sockaddr_vm svm;
-    int sock = -1;
 
     if (!vsock_parse_vaddr_to_sockaddr(vaddr, &svm, errp)) {
         return -1;
     }
 
-    sock = vsock_connect_addr(&svm, errp);
-
-    return sock;
+    return vsock_connect_addr(&svm, errp);
 }
 
 static int vsock_listen_saddr(VsockSocketAddress *vaddr,
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 141 lines · * Simran Singhal ([email protected]) wrote:

Compress two lines into a single line if immediate return statement is found.

It also remove variables progress, val, data, ret and sock as they are no longer needed.

Remove space between function "mixer_load" and '(' to fix the checkpatch.pl error:-
ERROR: space prohibited between function name and open parenthesis '('

---
 block/file-posix.c      | 3 +--
 block/nfs.c             | 3 +--
 block/nvme.c            | 4 +---
 block/vhdx.c            | 3 +--
 hw/audio/ac97.c         | 4 +---
 hw/audio/adlib.c        | 5 +----
 hw/display/cirrus_vga.c | 4 +---
 migration/ram.c         | 4 +---
 ui/gtk.c                | 3 +--
 util/qemu-sockets.c     | 5 +----
 10 files changed, 10 insertions(+), 28 deletions(-)
block/file-posix.c +1 -2
index 7e19bbff5f..dc01f0d4d3 100644
@@ -1627,8 +1627,7 @@ static int handle_aiocb_write_zeroes_unmap(void *opaque)
 
     /* If we couldn't manage to unmap while guaranteed that the area reads as
      * all-zero afterwards, just write zeroes without unmapping */
-    ret = handle_aiocb_write_zeroes(aiocb);
-    return ret;
+    return handle_aiocb_write_zeroes(aiocb);
 }
 
 #ifndef HAVE_COPY_FILE_RANGE
block/nfs.c +1 -2
index cc2413d5ab..100f15bd1f 100644
@@ -623,8 +623,7 @@ static int nfs_file_open(BlockDriverState *bs, QDict *options, int flags,
     }
 
     bs->total_sectors = ret;
-    ret = 0;
-    return ret;
+    return 0;
 }
 
 static QemuOptsList nfs_create_opts = {
block/nvme.c +1 -3
index 7b7c0cc5d6..eb2f54dd9d 100644
@@ -575,11 +575,9 @@ static bool nvme_poll_cb(void *opaque)
 {
     EventNotifier *e = opaque;
     BDRVNVMeState *s = container_of(e, BDRVNVMeState, irq_notifier);
-    bool progress = false;
 
     trace_nvme_poll_cb(s);
-    progress = nvme_poll_queues(s);
-    return progress;
+    return nvme_poll_queues(s);
 }
 
 static int nvme_init(BlockDriverState *bs, const char *device, int namespace,
block/vhdx.c +1 -2
index 33e57cd656..2c0e7ee44d 100644
@@ -411,8 +411,7 @@ int vhdx_update_headers(BlockDriverState *bs, BDRVVHDXState *s,
     if (ret < 0) {
         return ret;
     }
-    ret = vhdx_update_header(bs, s, generate_data_write_guid, log_guid);
-    return ret;
+    return vhdx_update_header(bs, s, generate_data_write_guid, log_guid);
 }
 
 /* opens the specified header block from the VHDX file header section */
hw/audio/ac97.c +1 -3
index 1ec87feec0..8a9b9924c4 100644
@@ -573,11 +573,9 @@ static uint32_t nam_readb (void *opaque, uint32_t addr)
 static uint32_t nam_readw (void *opaque, uint32_t addr)
 {
     AC97LinkState *s = opaque;
-    uint32_t val = ~0U;
     uint32_t index = addr;
     s->cas = 0;
-    val = mixer_load (s, index);
-    return val;
+    return mixer_load(s, index);
 }
 
 static uint32_t nam_readl (void *opaque, uint32_t addr)
hw/audio/adlib.c +1 -4
index d6c1fb0586..7c3b67dcfb 100644
@@ -120,13 +120,10 @@ static void adlib_write(void *opaque, uint32_t nport, uint32_t val)
 static uint32_t adlib_read(void *opaque, uint32_t nport)
 {
     AdlibState *s = opaque;
-    uint8_t data;
     int a = nport & 3;
 
     adlib_kill_timers (s);
-    data = OPLRead (s->opl, a);
-
-    return data;
+    return OPLRead (s->opl, a);
 }
 
 static void timer_handler (void *opaque, int c, double interval_Sec)
hw/display/cirrus_vga.c +1 -3
index 0d391e1300..1f29731ffe 100644
@@ -2411,12 +2411,10 @@ static uint64_t cirrus_linear_bitblt_read(void *opaque,
                                           unsigned size)
 {
     CirrusVGAState *s = opaque;
-    uint32_t ret;
 
     /* XXX handle bitblt */
     (void)s;
-    ret = 0xff;
-    return ret;
+    return 0xff;
 }
 
 static void cirrus_linear_bitblt_write(void *opaque,
migration/ram.c +0 -0
index 04f13feb2e..06cba88632 100644

migration/ram.c int ram_postcopy_send_discard_bitmap(MigrationState *ms) · line 2140

Quoted 9 lines
migration/ram.c +1 -3
@@ -2135,9 +2135,7 @@ int ram_postcopy_send_discard_bitmap(MigrationState *ms)
     }
     trace_ram_postcopy_send_discard_bitmap();
 
-    ret = postcopy_each_ram_send_discard(ms);
-
-    return ret;
+    return postcopy_each_ram_send_discard(ms);
 }
 

For migration

(If you rework this patch for another reason you could move the 'int ret' down into the
loop as int ret = .... but it's not important)

Quoted 39 lines
migration/ram.c +0 -0
 /**
ui/gtk.c +1 -2
index 030b251c61..83f2f5d49b 100644
@@ -1650,8 +1650,7 @@ static GSList *gd_vc_menu_init(GtkDisplayState *s, VirtualConsole *vc,
                      G_CALLBACK(gd_menu_switch_vc), s);
     gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), vc->menu_item);
 
-    group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc->menu_item));
-    return group;
+    return gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc->menu_item));
 }
 
 #if defined(CONFIG_VTE)
util/qemu-sockets.c +1 -4
index bcc06d0e01..86c48b9fa5 100644
@@ -765,15 +765,12 @@ static int vsock_connect_addr(const struct sockaddr_vm *svm, Error **errp)
 static int vsock_connect_saddr(VsockSocketAddress *vaddr, Error **errp)
 {
     struct sockaddr_vm svm;
-    int sock = -1;
 
     if (!vsock_parse_vaddr_to_sockaddr(vaddr, &svm, errp)) {
         return -1;
     }
 
-    sock = vsock_connect_addr(&svm, errp);
-
-    return sock;
+    return vsock_connect_addr(&svm, errp);
 }
 
 static int vsock_listen_saddr(VsockSocketAddress *vaddr,
Signature · 1 line
2.17.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#2 lore raw
In reply to Simran Singhal

Hi Simran,

Quoted 1 line · Simran Singhal

Compress two lines into a single line if immediate return statement is found.

How did you find these changes? Manual audit, some tool?

Quoted 86 lines

It also remove variables progress, val, data, ret and sock as they are no longer needed.

Remove space between function "mixer_load" and '(' to fix the checkpatch.pl error:-
ERROR: space prohibited between function name and open parenthesis '('

---
  block/file-posix.c      | 3 +--
  block/nfs.c             | 3 +--
  block/nvme.c            | 4 +---
  block/vhdx.c            | 3 +--
  hw/audio/ac97.c         | 4 +---
  hw/audio/adlib.c        | 5 +----
  hw/display/cirrus_vga.c | 4 +---
  migration/ram.c         | 4 +---
  ui/gtk.c                | 3 +--
  util/qemu-sockets.c     | 5 +----
  10 files changed, 10 insertions(+), 28 deletions(-)
block/file-posix.c +1 -2
index 7e19bbff5f..dc01f0d4d3 100644
@@ -1627,8 +1627,7 @@ static int handle_aiocb_write_zeroes_unmap(void *opaque)
 
      /* If we couldn't manage to unmap while guaranteed that the area reads as
       * all-zero afterwards, just write zeroes without unmapping */
-    ret = handle_aiocb_write_zeroes(aiocb);
-    return ret;
+    return handle_aiocb_write_zeroes(aiocb);
  }
 
  #ifndef HAVE_COPY_FILE_RANGE
block/nfs.c +1 -2
index cc2413d5ab..100f15bd1f 100644
@@ -623,8 +623,7 @@ static int nfs_file_open(BlockDriverState *bs, QDict *options, int flags,
      }
 
      bs->total_sectors = ret;
-    ret = 0;
-    return ret;
+    return 0;
  }
 
  static QemuOptsList nfs_create_opts = {
block/nvme.c +1 -3
index 7b7c0cc5d6..eb2f54dd9d 100644
@@ -575,11 +575,9 @@ static bool nvme_poll_cb(void *opaque)
  {
      EventNotifier *e = opaque;
      BDRVNVMeState *s = container_of(e, BDRVNVMeState, irq_notifier);
-    bool progress = false;
 
      trace_nvme_poll_cb(s);
-    progress = nvme_poll_queues(s);
-    return progress;
+    return nvme_poll_queues(s);
  }
 
  static int nvme_init(BlockDriverState *bs, const char *device, int namespace,
block/vhdx.c +1 -2
index 33e57cd656..2c0e7ee44d 100644
@@ -411,8 +411,7 @@ int vhdx_update_headers(BlockDriverState *bs, BDRVVHDXState *s,
      if (ret < 0) {
          return ret;
      }
-    ret = vhdx_update_header(bs, s, generate_data_write_guid, log_guid);
-    return ret;
+    return vhdx_update_header(bs, s, generate_data_write_guid, log_guid);
  }
 
  /* opens the specified header block from the VHDX file header section */
hw/audio/ac97.c +0 -0
index 1ec87feec0..8a9b9924c4 100644

hw/audio/ac97.c static uint32_t nam_readb (void *opaque, uint32_t addr) · line 576

Quoted 5 lines
hw/audio/ac97.c +0 -1
@@ -573,11 +573,9 @@ static uint32_t nam_readb (void *opaque, uint32_t addr)
  static uint32_t nam_readw (void *opaque, uint32_t addr)
  {
      AC97LinkState *s = opaque;
-    uint32_t val = ~0U;
      uint32_t index = addr;

Why remove 'val' and keep 'index'?

Quoted 12 lines
hw/audio/ac97.c +1 -2
      s->cas = 0;
-    val = mixer_load (s, index);
-    return val;
+    return mixer_load(s, index);
  }
 
  static uint32_t nam_readl (void *opaque, uint32_t addr)
hw/audio/adlib.c +0 -0
index d6c1fb0586..7c3b67dcfb 100644

hw/audio/adlib.c static void adlib_write(void *opaque, uint32_t nport, uint32_t val) · line 123

Quoted 5 lines
hw/audio/adlib.c +0 -1
@@ -120,13 +120,10 @@ static void adlib_write(void *opaque, uint32_t nport, uint32_t val)
  static uint32_t adlib_read(void *opaque, uint32_t nport)
  {
      AdlibState *s = opaque;
-    uint8_t data;
      int a = nport & 3;

Why remove 'data' and keep 'a'?

Quoted 14 lines
hw/audio/adlib.c +1 -3
      adlib_kill_timers (s);
-    data = OPLRead (s->opl, a);
-
-    return data;
+    return OPLRead (s->opl, a);
  }
 
  static void timer_handler (void *opaque, int c, double interval_Sec)
hw/display/cirrus_vga.c +0 -0
index 0d391e1300..1f29731ffe 100644

hw/display/cirrus_vga.c static uint64_t cirrus_linear_bitblt_read(void *opaque, · line 2414

Quoted 4 lines
hw/display/cirrus_vga.c +0 -1
@@ -2411,12 +2411,10 @@ static uint64_t cirrus_linear_bitblt_read(void *opaque,
                                            unsigned size)
  {
      CirrusVGAState *s = opaque;
-    uint32_t ret;

Why remove 'ret' and keep 's'?

Quoted 60 lines
hw/display/cirrus_vga.c +1 -2
      /* XXX handle bitblt */
      (void)s;
-    ret = 0xff;
-    return ret;
+    return 0xff;
  }
 
  static void cirrus_linear_bitblt_write(void *opaque,
migration/ram.c +1 -3
index 04f13feb2e..06cba88632 100644
@@ -2135,9 +2135,7 @@ int ram_postcopy_send_discard_bitmap(MigrationState *ms)
      }
      trace_ram_postcopy_send_discard_bitmap();
 
-    ret = postcopy_each_ram_send_discard(ms);
-
-    return ret;
+    return postcopy_each_ram_send_discard(ms);
  }
 
  /**
ui/gtk.c +1 -2
index 030b251c61..83f2f5d49b 100644
@@ -1650,8 +1650,7 @@ static GSList *gd_vc_menu_init(GtkDisplayState *s, VirtualConsole *vc,
                       G_CALLBACK(gd_menu_switch_vc), s);
      gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), vc->menu_item);
 
-    group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc->menu_item));
-    return group;
+    return gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc->menu_item));
  }
 
  #if defined(CONFIG_VTE)
util/qemu-sockets.c +1 -4
index bcc06d0e01..86c48b9fa5 100644
@@ -765,15 +765,12 @@ static int vsock_connect_addr(const struct sockaddr_vm *svm, Error **errp)
  static int vsock_connect_saddr(VsockSocketAddress *vaddr, Error **errp)
  {
      struct sockaddr_vm svm;
-    int sock = -1;
 
      if (!vsock_parse_vaddr_to_sockaddr(vaddr, &svm, errp)) {
          return -1;
      }
 
-    sock = vsock_connect_addr(&svm, errp);
-
-    return sock;
+    return vsock_connect_addr(&svm, errp);
  }
 
  static int vsock_listen_saddr(VsockSocketAddress *vaddr,
#3 lore raw

Hello Philippe

Quoted 8 lines · Philippe Mathieu-Daudé

Hi Simran,

Quoted 1 line · Simran Singhal

Compress two lines into a single line if immediate return statement is

found.

How did you find these changes? Manual audit, some tool?

I wrote coccinelle script to do these changes.

Quoted 94 lines

block/file-posix.c static int handle_aiocb_write_zeroes_unmap(void

Quoted 27 lines

It also remove variables progress, val, data, ret and sock as they are no longer needed.

Remove space between function "mixer_load" and '(' to fix the checkpatch.pl error:-
ERROR: space prohibited between function name and open parenthesis '('

---
  block/file-posix.c      | 3 +--
  block/nfs.c             | 3 +--
  block/nvme.c            | 4 +---
  block/vhdx.c            | 3 +--
  hw/audio/ac97.c         | 4 +---
  hw/audio/adlib.c        | 5 +----
  hw/display/cirrus_vga.c | 4 +---
  migration/ram.c         | 4 +---
  ui/gtk.c                | 3 +--
  util/qemu-sockets.c     | 5 +----
  10 files changed, 10 insertions(+), 28 deletions(-)
block/file-posix.c +0 -0
index 7e19bbff5f..dc01f0d4d3 100644
@@ -1627,8 +1627,7 @@ static int handle_aiocb_write_zeroes_unmap(void

*opaque)

block/file-posix.c static int handle_aiocb_write_zeroes_unmap(void · line 1627

Quoted 2 lines
block/file-posix.c +0 -0
      /* If we couldn't manage to unmap while guaranteed that the area

reads as

block/nfs.c static int nfs_file_open(BlockDriverState *bs, QDict

Quoted 12 lines
block/file-posix.c +1 -2
       * all-zero afterwards, just write zeroes without unmapping */
-    ret = handle_aiocb_write_zeroes(aiocb);
-    return ret;
+    return handle_aiocb_write_zeroes(aiocb);
  }
 
  #ifndef HAVE_COPY_FILE_RANGE
block/nfs.c +0 -0
index cc2413d5ab..100f15bd1f 100644
@@ -623,8 +623,7 @@ static int nfs_file_open(BlockDriverState *bs, QDict

*options, int flags,

Quoted 16 lines
block/nfs.c +1 -2
      }
 
      bs->total_sectors = ret;
-    ret = 0;
-    return ret;
+    return 0;
  }
 
  static QemuOptsList nfs_create_opts = {
block/nvme.c +0 -0
index 7b7c0cc5d6..eb2f54dd9d 100644
@@ -575,11 +575,9 @@ static bool nvme_poll_cb(void *opaque)
  {
      EventNotifier *e = opaque;

block/nvme.c static bool nvme_poll_cb(void *opaque) · line 583

Quoted 10 lines
block/nvme.c +1 -3
      BDRVNVMeState *s = container_of(e, BDRVNVMeState, irq_notifier);
-    bool progress = false;
 
      trace_nvme_poll_cb(s);
-    progress = nvme_poll_queues(s);
-    return progress;
+    return nvme_poll_queues(s);
  }
 
  static int nvme_init(BlockDriverState *bs, const char *device, int

namespace,

block/vhdx.c int vhdx_update_headers(BlockDriverState *bs,

Quoted 5 lines
block/vhdx.c +0 -0
index 33e57cd656..2c0e7ee44d 100644
@@ -411,8 +411,7 @@ int vhdx_update_headers(BlockDriverState *bs,

BDRVVHDXState *s,

block/vhdx.c int vhdx_update_headers(BlockDriverState *bs, BDRVVHDXState *s,

Quoted 6 lines
block/vhdx.c +1 -2
      if (ret < 0) {
          return ret;
      }
-    ret = vhdx_update_header(bs, s, generate_data_write_guid, log_guid);
-    return ret;
+    return vhdx_update_header(bs, s, generate_data_write_guid,

log_guid);

block/vhdx.c int vhdx_update_headers(BlockDriverState *bs, · line 417

Quoted 3 lines
block/vhdx.c +0 -0
  }
 
  /* opens the specified header block from the VHDX file header section

*/

hw/audio/ac97.c static uint32_t nam_readb (void *opaque, uint32_t

Quoted 5 lines
hw/audio/ac97.c +0 -0
index 1ec87feec0..8a9b9924c4 100644
@@ -573,11 +573,9 @@ static uint32_t nam_readb (void *opaque, uint32_t

addr)

Quoted 8 lines

hw/audio/ac97.c static uint32_t nam_readb (void *opaque, uint32_t addr) · line 576

Quoted 5 lines
hw/audio/ac97.c +0 -1
  static uint32_t nam_readw (void *opaque, uint32_t addr)
  {
      AC97LinkState *s = opaque;
-    uint32_t val = ~0U;
      uint32_t index = addr;

Why remove 'val' and keep 'index'?

I focused on doing one type of change in this patch. I removed 'val' because that variable was no longer useful with these changes.

Quoted 13 lines

hw/audio/adlib.c static void adlib_write(void *opaque, uint32_t

Quoted 12 lines
hw/audio/ac97.c +1 -2
      s->cas = 0;
-    val = mixer_load (s, index);
-    return val;
+    return mixer_load(s, index);
  }
 
  static uint32_t nam_readl (void *opaque, uint32_t addr)
hw/audio/adlib.c +0 -0
index d6c1fb0586..7c3b67dcfb 100644
@@ -120,13 +120,10 @@ static void adlib_write(void *opaque, uint32_t

nport, uint32_t val)

Quoted 8 lines

hw/audio/adlib.c static void adlib_write(void *opaque, uint32_t nport, uint32_t val) · line 123

Quoted 5 lines
hw/audio/adlib.c +0 -1
  static uint32_t adlib_read(void *opaque, uint32_t nport)
  {
      AdlibState *s = opaque;
-    uint8_t data;
      int a = nport & 3;

Why remove 'data' and keep 'a'?

I focused on doing one type of change in this patch. I removed 'data' because that variable was no longer useful with these changes.

Quoted 16 lines

hw/display/cirrus_vga.c static uint64_t cirrus_linear_bitblt_read(void

Quoted 15 lines
hw/audio/adlib.c +1 -3
      adlib_kill_timers (s);
-    data = OPLRead (s->opl, a);
-
-    return data;
+    return OPLRead (s->opl, a);
  }
 
  static void timer_handler (void *opaque, int c, double interval_Sec)
hw/display/cirrus_vga.c +0 -0
index 0d391e1300..1f29731ffe 100644
@@ -2411,12 +2411,10 @@ static uint64_t cirrus_linear_bitblt_read(void

*opaque,

Quoted 7 lines

hw/display/cirrus_vga.c static uint64_t cirrus_linear_bitblt_read(void *opaque, · line 2414

Quoted 4 lines
hw/display/cirrus_vga.c +0 -1
                                            unsigned size)
  {
      CirrusVGAState *s = opaque;
-    uint32_t ret;

Why remove 'ret' and keep 's'?

I focused on doing one type of change in this patch. I removed 'ret' because that variable was no longer useful with these changes.

Quoted 68 lines

migration/ram.c int

Quoted 15 lines
hw/display/cirrus_vga.c +1 -2
      /* XXX handle bitblt */
      (void)s;
-    ret = 0xff;
-    return ret;
+    return 0xff;
  }
 
  static void cirrus_linear_bitblt_write(void *opaque,
migration/ram.c +0 -0
index 04f13feb2e..06cba88632 100644
@@ -2135,9 +2135,7 @@ int

ram_postcopy_send_discard_bitmap(MigrationState *ms)

ui/gtk.c static GSList *gd_vc_menu_init(GtkDisplayState *s,

Quoted 15 lines
migration/ram.c +1 -3
      }
      trace_ram_postcopy_send_discard_bitmap();
 
-    ret = postcopy_each_ram_send_discard(ms);
-
-    return ret;
+    return postcopy_each_ram_send_discard(ms);
  }
 
  /**
ui/gtk.c +0 -0
index 030b251c61..83f2f5d49b 100644
@@ -1650,8 +1650,7 @@ static GSList *gd_vc_menu_init(GtkDisplayState *s,

VirtualConsole *vc,

ui/gtk.c static GSList *gd_vc_menu_init(GtkDisplayState *s, VirtualConsole *vc,

Quoted 4 lines
ui/gtk.c +0 -1
                       G_CALLBACK(gd_menu_switch_vc), s);
      gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), vc->menu_item);
 
-    group =

gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc->menu_item));

ui/gtk.c static GSList *gd_vc_menu_init(GtkDisplayState *s, · line 1653

Quoted 2 lines
ui/gtk.c +1 -1
-    return group;
+    return

gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc->menu_item));

util/qemu-sockets.c static int vsock_connect_addr(const struct

Quoted 8 lines
ui/gtk.c +0 -0
  }
 
  #if defined(CONFIG_VTE)
util/qemu-sockets.c +0 -0
index bcc06d0e01..86c48b9fa5 100644
@@ -765,15 +765,12 @@ static int vsock_connect_addr(const struct

sockaddr_vm *svm, Error **errp)

Quoted 17 lines
util/qemu-sockets.c +1 -4
  static int vsock_connect_saddr(VsockSocketAddress *vaddr, Error **errp)
  {
      struct sockaddr_vm svm;
-    int sock = -1;
 
      if (!vsock_parse_vaddr_to_sockaddr(vaddr, &svm, errp)) {
          return -1;
      }
 
-    sock = vsock_connect_addr(&svm, errp);
-
-    return sock;
+    return vsock_connect_addr(&svm, errp);
  }
 
  static int vsock_listen_saddr(VsockSocketAddress *vaddr,
#4 lore raw
Quoted 7 lines · Simran Singhal

Hello Philippe

Quoted 2 lines · Philippe Mathieu-Daudé

Hi Simran,

Quoted 9 lines
Quoted 6 lines · Simran Singhal
Quoted 1 line

Compress two lines into a single line if immediate return statement is

found.

How did you find these changes? Manual audit, some tool?

I wrote coccinelle script to do these changes.

Then is it worth checking in your script to scripts/coccinelle/ to let it be something we can repeatedly rerun in the future to catch more instances? Even if you don't go that far, mentioning the exact rune you used makes it easier to reproduce the patch, or even backport its effects to a different branch.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#5 lore raw
Quoted 16 lines · Eric Blake
Quoted 15 lines · Simran Singhal

Hello Philippe

On Wed, Apr 1, 2020 at 7:26 PM Philippe Mathieu-Daudé <[email protected]

Quoted 8 lines · wrote:

Hi Simran,

Quoted 1 line · Simran Singhal

Compress two lines into a single line if immediate return statement is

found.

How did you find these changes? Manual audit, some tool?

Quoted 9 lines
Quoted 2 lines

I wrote coccinelle script to do these changes.

Then is it worth checking in your script to scripts/coccinelle/ to let it be something we can repeatedly rerun in the future to catch more instances? Even if you don't go that far, mentioning the exact rune you used makes it easier to reproduce the patch, or even backport its effects to a different branch.

Ok, I'll resend the patch with changing the commit message to include the script used to make the change.

Thanks
Simran

Quoted 7 lines

--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org