diff mbox

[v2,17/29] virtio-serial: use DIV_ROUND_UP

Message ID 20170713163219.9024-18-marcandre.lureau@redhat.com
State New
Headers show

Commit Message

Marc-André Lureau July 13, 2017, 4:32 p.m. UTC
I used the clang-tidy qemu-round check to generate the fix:
https://github.com/elmarco/clang-tools-extra

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/char/virtio-serial-bus.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Philippe Mathieu-Daudé July 14, 2017, 4:22 a.m. UTC | #1
On 07/13/2017 01:32 PM, Marc-André Lureau wrote:
> I used the clang-tidy qemu-round check to generate the fix:
> https://github.com/elmarco/clang-tools-extra
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   hw/char/virtio-serial-bus.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
> index f5bc173844..17a1bb008a 100644
> --- a/hw/char/virtio-serial-bus.c
> +++ b/hw/char/virtio-serial-bus.c
> @@ -663,7 +663,7 @@ static void virtio_serial_save_device(VirtIODevice *vdev, QEMUFile *f)
>   
>       /* The ports map */
>       max_nr_ports = s->serial.max_virtserial_ports;
> -    for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
> +    for (i = 0; i < DIV_ROUND_UP(max_nr_ports, 32); i++) {
>           qemu_put_be32s(f, &s->ports_map[i]);
>       }
>   
> @@ -798,7 +798,7 @@ static int virtio_serial_load_device(VirtIODevice *vdev, QEMUFile *f,
>       qemu_get_be32s(f, &tmp);
>   
>       max_nr_ports = s->serial.max_virtserial_ports;
> -    for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
> +    for (i = 0; i < DIV_ROUND_UP(max_nr_ports, 32); i++) {
>           qemu_get_be32s(f, &ports_map);
>   
>           if (ports_map != s->ports_map[i]) {
> @@ -863,7 +863,7 @@ static uint32_t find_free_port_id(VirtIOSerial *vser)
>       unsigned int i, max_nr_ports;
>   
>       max_nr_ports = vser->serial.max_virtserial_ports;
> -    for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
> +    for (i = 0; i < DIV_ROUND_UP(max_nr_ports, 32); i++) {
>           uint32_t map, zeroes;
>   
>           map = vser->ports_map[i];
> @@ -1075,7 +1075,7 @@ static void virtio_serial_device_realize(DeviceState *dev, Error **errp)
>           vser->ovqs[i] = virtio_add_queue(vdev, 128, handle_output);
>       }
>   
> -    vser->ports_map = g_malloc0(((vser->serial.max_virtserial_ports + 31) / 32)
> +    vser->ports_map = g_malloc0((DIV_ROUND_UP(vser->serial.max_virtserial_ports, 32))
>           * sizeof(vser->ports_map[0]));

This line seems quite long now

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

>       /*
>        * Reserve location 0 for a console port for backward compat
>
Richard Henderson July 14, 2017, 8:39 a.m. UTC | #2
On 07/13/2017 06:32 AM, Marc-André Lureau wrote:
> I used the clang-tidy qemu-round check to generate the fix:
> https://github.com/elmarco/clang-tools-extra
> 
> Signed-off-by: Marc-André Lureau<marcandre.lureau@redhat.com>
> ---
>   hw/char/virtio-serial-bus.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)

Reviewed-by: Richard Henderson <rth@twiddle.net>


r~
Amit Shah July 16, 2017, 7:45 p.m. UTC | #3
On (Thu) 13 Jul 2017 [18:32:07], Marc-André Lureau wrote:
> I used the clang-tidy qemu-round check to generate the fix:
> https://github.com/elmarco/clang-tools-extra
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Reviewed-by: Amit Shah <amit@kernel.org>

		Amit
diff mbox

Patch

diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index f5bc173844..17a1bb008a 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -663,7 +663,7 @@  static void virtio_serial_save_device(VirtIODevice *vdev, QEMUFile *f)
 
     /* The ports map */
     max_nr_ports = s->serial.max_virtserial_ports;
-    for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
+    for (i = 0; i < DIV_ROUND_UP(max_nr_ports, 32); i++) {
         qemu_put_be32s(f, &s->ports_map[i]);
     }
 
@@ -798,7 +798,7 @@  static int virtio_serial_load_device(VirtIODevice *vdev, QEMUFile *f,
     qemu_get_be32s(f, &tmp);
 
     max_nr_ports = s->serial.max_virtserial_ports;
-    for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
+    for (i = 0; i < DIV_ROUND_UP(max_nr_ports, 32); i++) {
         qemu_get_be32s(f, &ports_map);
 
         if (ports_map != s->ports_map[i]) {
@@ -863,7 +863,7 @@  static uint32_t find_free_port_id(VirtIOSerial *vser)
     unsigned int i, max_nr_ports;
 
     max_nr_ports = vser->serial.max_virtserial_ports;
-    for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
+    for (i = 0; i < DIV_ROUND_UP(max_nr_ports, 32); i++) {
         uint32_t map, zeroes;
 
         map = vser->ports_map[i];
@@ -1075,7 +1075,7 @@  static void virtio_serial_device_realize(DeviceState *dev, Error **errp)
         vser->ovqs[i] = virtio_add_queue(vdev, 128, handle_output);
     }
 
-    vser->ports_map = g_malloc0(((vser->serial.max_virtserial_ports + 31) / 32)
+    vser->ports_map = g_malloc0((DIV_ROUND_UP(vser->serial.max_virtserial_ports, 32))
         * sizeof(vser->ports_map[0]));
     /*
      * Reserve location 0 for a console port for backward compat