All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d))
@ 2016-05-31 16:35 Laurent Vivier
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 01/16] coccinelle: " Laurent Vivier
                   ` (16 more replies)
  0 siblings, 17 replies; 28+ messages in thread
From: Laurent Vivier @ 2016-05-31 16:35 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel; +Cc: Laurent Vivier

This patch series is the result of coccinelle
script scripts/coccinelle/round.coccii, added by the first patch.

Laurent Vivier (16):
  coccinelle: use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d))
  parallels: Use DIV_ROUND_UP
  qcow/qcow2: Use DIV_ROUND_UP
  qed: Use DIV_ROUND_UP
  block: Use DIV_ROUND_UP
  crypto: Use DIV_ROUND_UP
  xen: Use DIV_ROUND_UP
  audio: Use DIV_ROUND_UP
  SPICE: Use DIV_ROUND_UP
  rocker: Use DIV_ROUND_UP
  usb: Use DIV_ROUND_UP
  slirp: Use DIV_ROUND_UP
  linux-user: Use DIV_ROUND_UP
  pc-bios/s390-ccw: Use DIV_ROUND_UP
  qemu-timer: Use DIV_ROUND_UP
  hbitmap: Use DIV_ROUND_UP

 block/parallels.c              |  2 +-
 block/qcow.c                   |  4 ++--
 block/qcow2-cluster.c          |  4 ++--
 block/qcow2-refcount.c         |  6 ++----
 block/qed-check.c              |  3 +--
 block/qed.c                    |  3 +--
 block/vvfat.c                  |  3 +--
 crypto/block-luks.c            |  6 ++----
 hw/audio/pcspk.c               |  2 +-
 hw/block/tc58128.c             |  2 +-
 hw/display/xenfb.c             |  4 ++--
 hw/net/rocker/rocker_of_dpa.c  |  5 ++---
 hw/usb/redirect.c              |  6 +++---
 linux-user/syscall.c           |  4 ++--
 pc-bios/s390-ccw/bootmap.c     |  2 +-
 qemu-timer.c                   |  2 +-
 scripts/coccinelle/round.cocci | 19 +++++++++++++++++++
 slirp/dnssearch.c              |  4 ++--
 tests/test-hbitmap.c           |  6 +++---
 ui/spice-display.c             |  2 +-
 xen-hvm.c                      |  2 +-
 21 files changed, 51 insertions(+), 40 deletions(-)
 create mode 100644 scripts/coccinelle/round.cocci

-- 
2.5.5

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [Qemu-devel] [PATCH 01/16] coccinelle: use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d))
  2016-05-31 16:35 [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Laurent Vivier
@ 2016-05-31 16:35 ` Laurent Vivier
  2016-05-31 17:12   ` Eric Blake
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 02/16] parallels: Use DIV_ROUND_UP Laurent Vivier
                   ` (15 subsequent siblings)
  16 siblings, 1 reply; 28+ messages in thread
From: Laurent Vivier @ 2016-05-31 16:35 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel; +Cc: Laurent Vivier

sample from http://coccinellery.org/

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 scripts/coccinelle/round.cocci | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 scripts/coccinelle/round.cocci

diff --git a/scripts/coccinelle/round.cocci b/scripts/coccinelle/round.cocci
new file mode 100644
index 0000000..ed06773
--- /dev/null
+++ b/scripts/coccinelle/round.cocci
@@ -0,0 +1,19 @@
+// Use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d))
+@@
+expression e1;
+expression e2;
+@@
+(
+- ((e1) + e2 - 1) / (e2)
++ DIV_ROUND_UP(e1,e2)
+|
+- ((e1) + (e2 - 1)) / (e2)
++ DIV_ROUND_UP(e1,e2)
+)
+
+@@
+expression e1;
+expression e2;
+@@
+-(DIV_ROUND_UP(e1,e2))
++DIV_ROUND_UP(e1,e2)
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Qemu-devel] [PATCH 02/16] parallels: Use DIV_ROUND_UP
  2016-05-31 16:35 [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Laurent Vivier
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 01/16] coccinelle: " Laurent Vivier
@ 2016-05-31 16:35 ` Laurent Vivier
  2016-05-31 17:18   ` Eric Blake
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 03/16] qcow/qcow2: " Laurent Vivier
                   ` (14 subsequent siblings)
  16 siblings, 1 reply; 28+ messages in thread
From: Laurent Vivier @ 2016-05-31 16:35 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel; +Cc: Laurent Vivier, qemu-block

Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).

This patch is the result of coccinelle script
scripts/coccinelle/round.cocci

CC: qemu-block@nongnu.org
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 block/parallels.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/parallels.c b/block/parallels.c
index 99fc0f7..b9b5c6d 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -204,7 +204,7 @@ static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num,
         return -EINVAL;
     }
 
-    to_allocate = (sector_num + *pnum + s->tracks - 1) / s->tracks - idx;
+    to_allocate = DIV_ROUND_UP(sector_num + *pnum, s->tracks) - idx;
     space = to_allocate * s->tracks;
     if (s->data_end + space > bdrv_getlength(bs->file->bs) >> BDRV_SECTOR_BITS) {
         int ret;
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Qemu-devel] [PATCH 03/16] qcow/qcow2: Use DIV_ROUND_UP
  2016-05-31 16:35 [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Laurent Vivier
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 01/16] coccinelle: " Laurent Vivier
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 02/16] parallels: Use DIV_ROUND_UP Laurent Vivier
@ 2016-05-31 16:35 ` Laurent Vivier
  2016-05-31 17:20   ` Eric Blake
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 04/16] qed: " Laurent Vivier
                   ` (13 subsequent siblings)
  16 siblings, 1 reply; 28+ messages in thread
From: Laurent Vivier @ 2016-05-31 16:35 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel; +Cc: Laurent Vivier, qemu-block

Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).

This patch is the result of coccinelle script
scripts/coccinelle/round.cocci

CC: qemu-block@nongnu.org
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 block/qcow.c           | 4 ++--
 block/qcow2-cluster.c  | 4 ++--
 block/qcow2-refcount.c | 6 ++----
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/block/qcow.c b/block/qcow.c
index cb4bf02..c5cf813 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -868,8 +868,8 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
     }
 
     tmp = g_malloc0(BDRV_SECTOR_SIZE);
-    for (i = 0; i < ((sizeof(uint64_t)*l1_size + BDRV_SECTOR_SIZE - 1)/
-        BDRV_SECTOR_SIZE); i++) {
+    for (i = 0; i < DIV_ROUND_UP(sizeof(uint64_t) * l1_size, BDRV_SECTOR_SIZE);
+         i++) {
         ret = blk_pwrite(qcow_blk, header_size + BDRV_SECTOR_SIZE * i,
                          tmp, BDRV_SECTOR_SIZE, 0);
         if (ret != BDRV_SECTOR_SIZE) {
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 892e0fb..c737973 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1868,8 +1868,8 @@ int qcow2_expand_zero_clusters(BlockDriverState *bs,
     }
 
     for (i = 0; i < s->nb_snapshots; i++) {
-        int l1_sectors = (s->snapshots[i].l1_size * sizeof(uint64_t) +
-                BDRV_SECTOR_SIZE - 1) / BDRV_SECTOR_SIZE;
+        int l1_sectors = DIV_ROUND_UP(s->snapshots[i].l1_size *
+                                      sizeof(uint64_t), BDRV_SECTOR_SIZE);
 
         l1_table = g_realloc(l1_table, l1_sectors * BDRV_SECTOR_SIZE);
 
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 7fa972a..66f187a 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -490,14 +490,12 @@ static int alloc_refcount_block(BlockDriverState *bs,
         uint64_t table_clusters =
             size_to_clusters(s, table_size * sizeof(uint64_t));
         blocks_clusters = 1 +
-            ((table_clusters + s->refcount_block_size - 1)
-            / s->refcount_block_size);
+            DIV_ROUND_UP(table_clusters, s->refcount_block_size);
         uint64_t meta_clusters = table_clusters + blocks_clusters;
 
         last_table_size = table_size;
         table_size = next_refcount_table_size(s, blocks_used +
-            ((meta_clusters + s->refcount_block_size - 1)
-            / s->refcount_block_size));
+            DIV_ROUND_UP(meta_clusters, s->refcount_block_size));
 
     } while (last_table_size != table_size);
 
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Qemu-devel] [PATCH 04/16] qed: Use DIV_ROUND_UP
  2016-05-31 16:35 [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Laurent Vivier
                   ` (2 preceding siblings ...)
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 03/16] qcow/qcow2: " Laurent Vivier
@ 2016-05-31 16:35 ` Laurent Vivier
  2016-05-31 17:49   ` Eric Blake
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 05/16] block: " Laurent Vivier
                   ` (12 subsequent siblings)
  16 siblings, 1 reply; 28+ messages in thread
From: Laurent Vivier @ 2016-05-31 16:35 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel; +Cc: Laurent Vivier, qemu-block

Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).

This patch is the result of coccinelle script
scripts/coccinelle/round.cocci

CC: qemu-block@nongnu.org
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 block/qed-check.c | 3 +--
 block/qed.c       | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/block/qed-check.c b/block/qed-check.c
index 622f308..dcd4f03 100644
--- a/block/qed-check.c
+++ b/block/qed-check.c
@@ -234,8 +234,7 @@ int qed_check(BDRVQEDState *s, BdrvCheckResult *result, bool fix)
     }
 
     check.result->bfi.total_clusters =
-        (s->header.image_size + s->header.cluster_size - 1) /
-            s->header.cluster_size;
+        DIV_ROUND_UP(s->header.image_size, s->header.cluster_size);
     ret = qed_check_l1_table(&check, s->l1_table);
     if (ret == 0) {
         /* Only check for leaks if entire image was scanned successfully */
diff --git a/block/qed.c b/block/qed.c
index b591d4a..0f62192 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -143,8 +143,7 @@ static void qed_write_header(BDRVQEDState *s, BlockCompletionFunc cb,
      * them, and write back.
      */
 
-    int nsectors = (sizeof(QEDHeader) + BDRV_SECTOR_SIZE - 1) /
-                   BDRV_SECTOR_SIZE;
+    int nsectors = DIV_ROUND_UP(sizeof(QEDHeader), BDRV_SECTOR_SIZE);
     size_t len = nsectors * BDRV_SECTOR_SIZE;
     QEDWriteHeaderCB *write_header_cb = gencb_alloc(sizeof(*write_header_cb),
                                                     cb, opaque);
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Qemu-devel] [PATCH 05/16] block: Use DIV_ROUND_UP
  2016-05-31 16:35 [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Laurent Vivier
                   ` (3 preceding siblings ...)
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 04/16] qed: " Laurent Vivier
@ 2016-05-31 16:35 ` Laurent Vivier
  2016-05-31 17:50   ` Eric Blake
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 06/16] crypto: " Laurent Vivier
                   ` (11 subsequent siblings)
  16 siblings, 1 reply; 28+ messages in thread
From: Laurent Vivier @ 2016-05-31 16:35 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel; +Cc: Laurent Vivier, qemu-block

Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).

This patch is the result of coccinelle script
scripts/coccinelle/round.cocci

CC: qemu-block@nongnu.org
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 block/vvfat.c      | 3 +--
 hw/block/tc58128.c | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index a39dbe6..6d2e21c 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -1960,8 +1960,7 @@ DLOG(fprintf(stderr, "check direntry %d:\n", i); print_direntry(direntries + i))
 		/* check file size with FAT */
 		cluster_count = get_cluster_count_for_direntry(s, direntries + i, path2);
 		if (cluster_count !=
-			(le32_to_cpu(direntries[i].size) + s->cluster_size
-			 - 1) / s->cluster_size) {
+            DIV_ROUND_UP(le32_to_cpu(direntries[i].size), s->cluster_size)) {
 		    DLOG(fprintf(stderr, "Cluster count mismatch\n"));
 		    goto fail;
 		}
diff --git a/hw/block/tc58128.c b/hw/block/tc58128.c
index 7909d50..1d9f7ee 100644
--- a/hw/block/tc58128.c
+++ b/hw/block/tc58128.c
@@ -45,7 +45,7 @@ static void init_dev(tc58128_dev * dev, const char *filename)
             }
 	} else {
 	    /* Build first block with number of blocks */
-	    blocks = (ret + 528 * 32 - 1) / (528 * 32);
+            blocks = DIV_ROUND_UP(ret, 528 * 32);
 	    dev->flash_contents[0] = blocks & 0xff;
 	    dev->flash_contents[1] = (blocks >> 8) & 0xff;
 	    dev->flash_contents[2] = (blocks >> 16) & 0xff;
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Qemu-devel] [PATCH 06/16] crypto: Use DIV_ROUND_UP
  2016-05-31 16:35 [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Laurent Vivier
                   ` (4 preceding siblings ...)
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 05/16] block: " Laurent Vivier
@ 2016-05-31 16:35 ` Laurent Vivier
  2016-05-31 16:45   ` Daniel P. Berrange
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 07/16] xen: " Laurent Vivier
                   ` (10 subsequent siblings)
  16 siblings, 1 reply; 28+ messages in thread
From: Laurent Vivier @ 2016-05-31 16:35 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel; +Cc: Laurent Vivier, Daniel P. Berrange

Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).

This patch is the result of coccinelle script
scripts/coccinelle/round.cocci

CC: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 crypto/block-luks.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/crypto/block-luks.c b/crypto/block-luks.c
index 17c4300..63649f1 100644
--- a/crypto/block-luks.c
+++ b/crypto/block-luks.c
@@ -1081,8 +1081,7 @@ qcrypto_block_luks_create(QCryptoBlock *block,
         luks->header.key_slots[i].key_offset =
             (QCRYPTO_BLOCK_LUKS_KEY_SLOT_OFFSET /
              QCRYPTO_BLOCK_LUKS_SECTOR_SIZE) +
-            (ROUND_UP(((splitkeylen + (QCRYPTO_BLOCK_LUKS_SECTOR_SIZE - 1)) /
-                       QCRYPTO_BLOCK_LUKS_SECTOR_SIZE),
+            (ROUND_UP(DIV_ROUND_UP(splitkeylen, QCRYPTO_BLOCK_LUKS_SECTOR_SIZE),
                       (QCRYPTO_BLOCK_LUKS_KEY_SLOT_OFFSET /
                        QCRYPTO_BLOCK_LUKS_SECTOR_SIZE)) * i);
     }
@@ -1182,8 +1181,7 @@ qcrypto_block_luks_create(QCryptoBlock *block,
     luks->header.payload_offset =
         (QCRYPTO_BLOCK_LUKS_KEY_SLOT_OFFSET /
          QCRYPTO_BLOCK_LUKS_SECTOR_SIZE) +
-        (ROUND_UP(((splitkeylen + (QCRYPTO_BLOCK_LUKS_SECTOR_SIZE - 1)) /
-                   QCRYPTO_BLOCK_LUKS_SECTOR_SIZE),
+        (ROUND_UP(DIV_ROUND_UP(splitkeylen, QCRYPTO_BLOCK_LUKS_SECTOR_SIZE),
                   (QCRYPTO_BLOCK_LUKS_KEY_SLOT_OFFSET /
                    QCRYPTO_BLOCK_LUKS_SECTOR_SIZE)) *
          QCRYPTO_BLOCK_LUKS_NUM_KEY_SLOTS);
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Qemu-devel] [PATCH 07/16] xen: Use DIV_ROUND_UP
  2016-05-31 16:35 [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Laurent Vivier
                   ` (5 preceding siblings ...)
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 06/16] crypto: " Laurent Vivier
@ 2016-05-31 16:35 ` Laurent Vivier
  2016-06-01  9:33   ` Stefano Stabellini
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 08/16] audio: " Laurent Vivier
                   ` (9 subsequent siblings)
  16 siblings, 1 reply; 28+ messages in thread
From: Laurent Vivier @ 2016-05-31 16:35 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel; +Cc: Laurent Vivier, Stefano Stabellini

Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).

This patch is the result of coccinelle script
scripts/coccinelle/round.cocci

CC: Stefano Stabellini <sstabellini@kernel.org>
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 hw/display/xenfb.c | 4 ++--
 xen-hvm.c          | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c
index 9866dfd..570b097 100644
--- a/hw/display/xenfb.c
+++ b/hw/display/xenfb.c
@@ -472,9 +472,9 @@ static int xenfb_map_fb(struct XenFB *xenfb)
         xenfb->pixels = NULL;
     }
 
-    xenfb->fbpages = (xenfb->fb_len + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;
+    xenfb->fbpages = DIV_ROUND_UP(xenfb->fb_len, XC_PAGE_SIZE);
     n_fbdirs = xenfb->fbpages * mode / 8;
-    n_fbdirs = (n_fbdirs + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;
+    n_fbdirs = DIV_ROUND_UP(n_fbdirs, XC_PAGE_SIZE);
 
     pgmfns = g_malloc0(sizeof(xen_pfn_t) * n_fbdirs);
     fbmfns = g_malloc0(sizeof(xen_pfn_t) * xenfb->fbpages);
diff --git a/xen-hvm.c b/xen-hvm.c
index 01ee25d..a0da8d7 100644
--- a/xen-hvm.c
+++ b/xen-hvm.c
@@ -567,7 +567,7 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
 {
     hwaddr npages = size >> TARGET_PAGE_BITS;
     const int width = sizeof(unsigned long) * 8;
-    unsigned long bitmap[(npages + width - 1) / width];
+    unsigned long bitmap[DIV_ROUND_UP(npages, width)];
     int rc, i, j;
     const XenPhysmap *physmap = NULL;
 
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Qemu-devel] [PATCH 08/16] audio: Use DIV_ROUND_UP
  2016-05-31 16:35 [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Laurent Vivier
                   ` (6 preceding siblings ...)
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 07/16] xen: " Laurent Vivier
@ 2016-05-31 16:35 ` Laurent Vivier
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 09/16] SPICE: " Laurent Vivier
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 28+ messages in thread
From: Laurent Vivier @ 2016-05-31 16:35 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel; +Cc: Laurent Vivier, Gerd Hoffmann

Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).

This patch is the result of coccinelle script
scripts/coccinelle/round.cocci

CC: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 hw/audio/pcspk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index f9afc8e..d259960 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -35,7 +35,7 @@
 #define PCSPK_BUF_LEN 1792
 #define PCSPK_SAMPLE_RATE 32000
 #define PCSPK_MAX_FREQ (PCSPK_SAMPLE_RATE >> 1)
-#define PCSPK_MIN_COUNT ((PIT_FREQ + PCSPK_MAX_FREQ - 1) / PCSPK_MAX_FREQ)
+#define PCSPK_MIN_COUNT DIV_ROUND_UP(PIT_FREQ, PCSPK_MAX_FREQ)
 
 #define PC_SPEAKER(obj) OBJECT_CHECK(PCSpkState, (obj), TYPE_PC_SPEAKER)
 
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Qemu-devel] [PATCH 09/16] SPICE: Use DIV_ROUND_UP
  2016-05-31 16:35 [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Laurent Vivier
                   ` (7 preceding siblings ...)
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 08/16] audio: " Laurent Vivier
@ 2016-05-31 16:35 ` Laurent Vivier
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 10/16] rocker: " Laurent Vivier
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 28+ messages in thread
From: Laurent Vivier @ 2016-05-31 16:35 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel; +Cc: Laurent Vivier, Gerd Hoffmann

Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).

This patch is the result of coccinelle script
scripts/coccinelle/round.cocci

CC: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 ui/spice-display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ui/spice-display.c b/ui/spice-display.c
index 0553c5e..34095fb 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -197,7 +197,7 @@ static void qemu_spice_create_one_update(SimpleSpiceDisplay *ssd,
 static void qemu_spice_create_update(SimpleSpiceDisplay *ssd)
 {
     static const int blksize = 32;
-    int blocks = (surface_width(ssd->ds) + blksize - 1) / blksize;
+    int blocks = DIV_ROUND_UP(surface_width(ssd->ds), blksize);
     int dirty_top[blocks];
     int y, yoff1, yoff2, x, xoff, blk, bw;
     int bpp = surface_bytes_per_pixel(ssd->ds);
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Qemu-devel] [PATCH 10/16] rocker: Use DIV_ROUND_UP
  2016-05-31 16:35 [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Laurent Vivier
                   ` (8 preceding siblings ...)
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 09/16] SPICE: " Laurent Vivier
@ 2016-05-31 16:35 ` Laurent Vivier
  2016-05-31 16:36 ` [Qemu-devel] [PATCH 11/16] usb: " Laurent Vivier
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 28+ messages in thread
From: Laurent Vivier @ 2016-05-31 16:35 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel; +Cc: Laurent Vivier, Scott Feldman

Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).

This patch is the result of coccinelle script
scripts/coccinelle/round.cocci

CC: Scott Feldman <sfeldma@gmail.com>
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 hw/net/rocker/rocker_of_dpa.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/net/rocker/rocker_of_dpa.c b/hw/net/rocker/rocker_of_dpa.c
index 0a134eb..9b1e0d2 100644
--- a/hw/net/rocker/rocker_of_dpa.c
+++ b/hw/net/rocker/rocker_of_dpa.c
@@ -103,9 +103,8 @@ typedef struct of_dpa_flow_key {
 
 /* Width of key which includes field 'f' in u64s, rounded up */
 #define FLOW_KEY_WIDTH(f) \
-    ((offsetof(OfDpaFlowKey, f) + \
-      sizeof(((OfDpaFlowKey *)0)->f) + \
-      sizeof(uint64_t) - 1) / sizeof(uint64_t))
+    DIV_ROUND_UP(offsetof(OfDpaFlowKey, f) + sizeof(((OfDpaFlowKey *)0)->f), \
+    sizeof(uint64_t))
 
 typedef struct of_dpa_flow_action {
     uint32_t goto_tbl;
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Qemu-devel] [PATCH 11/16] usb: Use DIV_ROUND_UP
  2016-05-31 16:35 [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Laurent Vivier
                   ` (9 preceding siblings ...)
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 10/16] rocker: " Laurent Vivier
@ 2016-05-31 16:36 ` Laurent Vivier
  2016-05-31 16:36 ` [Qemu-devel] [PATCH 12/16] slirp: " Laurent Vivier
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 28+ messages in thread
From: Laurent Vivier @ 2016-05-31 16:36 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel; +Cc: Laurent Vivier, Gerd Hoffmann

Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).

This patch is the result of coccinelle script
scripts/coccinelle/round.cocci

CC: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 hw/usb/redirect.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index 8d80540..8ec8484 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -542,9 +542,9 @@ static void usbredir_handle_iso_data(USBRedirDevice *dev, USBPacket *p,
             start_iso.pkts_per_urb = 32;
         }
 
-        start_iso.no_urbs = (dev->endpoint[EP2I(ep)].bufpq_target_size +
-                             start_iso.pkts_per_urb - 1) /
-                            start_iso.pkts_per_urb;
+        start_iso.no_urbs = DIV_ROUND_UP(
+                                     dev->endpoint[EP2I(ep)].bufpq_target_size,
+                                     start_iso.pkts_per_urb);
         /* Output endpoints pre-fill only 1/2 of the packets, keeping the rest
            as overflow buffer. Also see the usbredir protocol documentation */
         if (!(ep & USB_DIR_IN)) {
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Qemu-devel] [PATCH 12/16] slirp: Use DIV_ROUND_UP
  2016-05-31 16:35 [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Laurent Vivier
                   ` (10 preceding siblings ...)
  2016-05-31 16:36 ` [Qemu-devel] [PATCH 11/16] usb: " Laurent Vivier
@ 2016-05-31 16:36 ` Laurent Vivier
  2016-05-31 16:41   ` Samuel Thibault
  2016-05-31 16:36 ` [Qemu-devel] [PATCH 13/16] linux-user: " Laurent Vivier
                   ` (4 subsequent siblings)
  16 siblings, 1 reply; 28+ messages in thread
From: Laurent Vivier @ 2016-05-31 16:36 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel; +Cc: Laurent Vivier, Samuel Thibault

Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).

This patch is the result of coccinelle script
scripts/coccinelle/round.cocci

CC: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 slirp/dnssearch.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/slirp/dnssearch.c b/slirp/dnssearch.c
index aed2f13..9b16757 100644
--- a/slirp/dnssearch.c
+++ b/slirp/dnssearch.c
@@ -262,7 +262,7 @@ int translate_dnssearch(Slirp *s, const char **names)
     }
 
     /* reserve extra 2 header bytes for each 255 bytes of output */
-    memreq += ((memreq + MAX_OPT_LEN - 1) / MAX_OPT_LEN) * OPT_HEADER_LEN;
+    memreq += DIV_ROUND_UP(memreq, MAX_OPT_LEN) * OPT_HEADER_LEN;
     result = g_malloc(memreq * sizeof(*result));
 
     outptr = result;
@@ -289,7 +289,7 @@ int translate_dnssearch(Slirp *s, const char **names)
     domain_mkxrefs(domains, domains + num_domains - 1, 0);
     memreq = domain_compactify(domains, num_domains);
 
-    blocks = (memreq + MAX_OPT_LEN - 1) / MAX_OPT_LEN;
+    blocks = DIV_ROUND_UP(memreq, MAX_OPT_LEN);
     bsrc_end = memreq;
     bsrc_start = (blocks - 1) * MAX_OPT_LEN;
     bdst_start = bsrc_start + blocks * OPT_HEADER_LEN;
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Qemu-devel] [PATCH 13/16] linux-user: Use DIV_ROUND_UP
  2016-05-31 16:35 [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Laurent Vivier
                   ` (11 preceding siblings ...)
  2016-05-31 16:36 ` [Qemu-devel] [PATCH 12/16] slirp: " Laurent Vivier
@ 2016-05-31 16:36 ` Laurent Vivier
  2016-05-31 16:36 ` [Qemu-devel] [PATCH 14/16] pc-bios/s390-ccw: " Laurent Vivier
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 28+ messages in thread
From: Laurent Vivier @ 2016-05-31 16:36 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel; +Cc: Laurent Vivier, Riku Voipio

Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).

This patch is the result of coccinelle script
scripts/coccinelle/round.cocci

CC: Riku Voipio <riku.voipio@iki.fi>
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 linux-user/syscall.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index df70255..96ec801 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -829,7 +829,7 @@ static inline abi_long copy_from_user_fdset(fd_set *fds,
     int i, nw, j, k;
     abi_ulong b, *target_fds;
 
-    nw = (n + TARGET_ABI_BITS - 1) / TARGET_ABI_BITS;
+    nw = DIV_ROUND_UP(n, TARGET_ABI_BITS);
     if (!(target_fds = lock_user(VERIFY_READ,
                                  target_fds_addr,
                                  sizeof(abi_ulong) * nw,
@@ -876,7 +876,7 @@ static inline abi_long copy_to_user_fdset(abi_ulong target_fds_addr,
     abi_long v;
     abi_ulong *target_fds;
 
-    nw = (n + TARGET_ABI_BITS - 1) / TARGET_ABI_BITS;
+    nw = DIV_ROUND_UP(n, TARGET_ABI_BITS);
     if (!(target_fds = lock_user(VERIFY_WRITE,
                                  target_fds_addr,
                                  sizeof(abi_ulong) * nw,
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Qemu-devel] [PATCH 14/16] pc-bios/s390-ccw: Use DIV_ROUND_UP
  2016-05-31 16:35 [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Laurent Vivier
                   ` (12 preceding siblings ...)
  2016-05-31 16:36 ` [Qemu-devel] [PATCH 13/16] linux-user: " Laurent Vivier
@ 2016-05-31 16:36 ` Laurent Vivier
  2016-05-31 16:36 ` [Qemu-devel] [PATCH 15/16] qemu-timer: " Laurent Vivier
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 28+ messages in thread
From: Laurent Vivier @ 2016-05-31 16:36 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel; +Cc: Laurent Vivier, Cornelia Huck

Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).

This patch is the result of coccinelle script
scripts/coccinelle/round.cocci

CC: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 pc-bios/s390-ccw/bootmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c
index 611102e..ecdc52d 100644
--- a/pc-bios/s390-ccw/bootmap.c
+++ b/pc-bios/s390-ccw/bootmap.c
@@ -599,7 +599,7 @@ static void load_iso_bc_entry(IsoBcSection *load)
 
     if (real_size) {
         /* Round up blocks to load */
-        blks_to_load = (real_size + ISO_SECTOR_SIZE - 1) / ISO_SECTOR_SIZE;
+        blks_to_load = DIV_ROUND_UP(real_size, ISO_SECTOR_SIZE);
         sclp_print("ISO boot image size verified\n");
     } else {
         sclp_print("ISO boot image size could not be verified\n");
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Qemu-devel] [PATCH 15/16] qemu-timer: Use DIV_ROUND_UP
  2016-05-31 16:35 [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Laurent Vivier
                   ` (13 preceding siblings ...)
  2016-05-31 16:36 ` [Qemu-devel] [PATCH 14/16] pc-bios/s390-ccw: " Laurent Vivier
@ 2016-05-31 16:36 ` Laurent Vivier
  2016-05-31 16:36 ` [Qemu-devel] [PATCH 16/16] hbitmap: " Laurent Vivier
  2016-06-05  7:16 ` [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Michael Tokarev
  16 siblings, 0 replies; 28+ messages in thread
From: Laurent Vivier @ 2016-05-31 16:36 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel; +Cc: Laurent Vivier, Paolo Bonzini

Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).

This patch is the result of coccinelle script
scripts/coccinelle/round.cocci

CC: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 qemu-timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qemu-timer.c b/qemu-timer.c
index 4441fe6..eb22e92 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -292,7 +292,7 @@ int qemu_timeout_ns_to_ms(int64_t ns)
     /* Always round up, because it's better to wait too long than to wait too
      * little and effectively busy-wait
      */
-    ms = (ns + SCALE_MS - 1) / SCALE_MS;
+    ms = DIV_ROUND_UP(ns, SCALE_MS);
 
     /* To avoid overflow problems, limit this to 2^31, i.e. approx 25 days */
     if (ms > (int64_t) INT32_MAX) {
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [Qemu-devel] [PATCH 16/16] hbitmap: Use DIV_ROUND_UP
  2016-05-31 16:35 [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Laurent Vivier
                   ` (14 preceding siblings ...)
  2016-05-31 16:36 ` [Qemu-devel] [PATCH 15/16] qemu-timer: " Laurent Vivier
@ 2016-05-31 16:36 ` Laurent Vivier
  2016-06-03 18:17   ` John Snow
  2016-06-05  7:16 ` [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Michael Tokarev
  16 siblings, 1 reply; 28+ messages in thread
From: Laurent Vivier @ 2016-05-31 16:36 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel; +Cc: Laurent Vivier, Paolo Bonzini

Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).

This patch is the result of coccinelle script
scripts/coccinelle/round.cocci

CC: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 tests/test-hbitmap.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c
index abe1427..097fe8e 100644
--- a/tests/test-hbitmap.c
+++ b/tests/test-hbitmap.c
@@ -80,7 +80,7 @@ static void hbitmap_test_init(TestHBitmapData *data,
     size_t n;
     data->hb = hbitmap_alloc(size, granularity);
 
-    n = (size + BITS_PER_LONG - 1) / BITS_PER_LONG;
+    n = DIV_ROUND_UP(size, BITS_PER_LONG);
     if (n == 0) {
         n = 1;
     }
@@ -94,7 +94,7 @@ static void hbitmap_test_init(TestHBitmapData *data,
 
 static inline size_t hbitmap_test_array_size(size_t bits)
 {
-    size_t n = (bits + BITS_PER_LONG - 1) / BITS_PER_LONG;
+    size_t n = DIV_ROUND_UP(bits, BITS_PER_LONG);
     return n ? n : 1;
 }
 
@@ -186,7 +186,7 @@ static void hbitmap_test_reset_all(TestHBitmapData *data)
 
     hbitmap_reset_all(data->hb);
 
-    n = (data->size + BITS_PER_LONG - 1) / BITS_PER_LONG;
+    n = DIV_ROUND_UP(data->size, BITS_PER_LONG);
     if (n == 0) {
         n = 1;
     }
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [Qemu-devel] [PATCH 12/16] slirp: Use DIV_ROUND_UP
  2016-05-31 16:36 ` [Qemu-devel] [PATCH 12/16] slirp: " Laurent Vivier
@ 2016-05-31 16:41   ` Samuel Thibault
  0 siblings, 0 replies; 28+ messages in thread
From: Samuel Thibault @ 2016-05-31 16:41 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: qemu-trivial, qemu-devel

Laurent Vivier, on Tue 31 May 2016 18:36:01 +0200, wrote:
> Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
> 
> This patch is the result of coccinelle script
> scripts/coccinelle/round.cocci
> 
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>

Acked-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  slirp/dnssearch.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/slirp/dnssearch.c b/slirp/dnssearch.c
> index aed2f13..9b16757 100644
> --- a/slirp/dnssearch.c
> +++ b/slirp/dnssearch.c
> @@ -262,7 +262,7 @@ int translate_dnssearch(Slirp *s, const char **names)
>      }
>  
>      /* reserve extra 2 header bytes for each 255 bytes of output */
> -    memreq += ((memreq + MAX_OPT_LEN - 1) / MAX_OPT_LEN) * OPT_HEADER_LEN;
> +    memreq += DIV_ROUND_UP(memreq, MAX_OPT_LEN) * OPT_HEADER_LEN;
>      result = g_malloc(memreq * sizeof(*result));
>  
>      outptr = result;
> @@ -289,7 +289,7 @@ int translate_dnssearch(Slirp *s, const char **names)
>      domain_mkxrefs(domains, domains + num_domains - 1, 0);
>      memreq = domain_compactify(domains, num_domains);
>  
> -    blocks = (memreq + MAX_OPT_LEN - 1) / MAX_OPT_LEN;
> +    blocks = DIV_ROUND_UP(memreq, MAX_OPT_LEN);
>      bsrc_end = memreq;
>      bsrc_start = (blocks - 1) * MAX_OPT_LEN;
>      bdst_start = bsrc_start + blocks * OPT_HEADER_LEN;
> -- 
> 2.5.5
> 

-- 
Samuel
AUTHOR
     FvwmM4 is the result of a random  bit  mutation  on  a  hard
     disk,  presumably  a  result  of  a  cosmic-ray or some such
     thing.
(extrait de la page de man de FvwmM4)

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Qemu-devel] [PATCH 06/16] crypto: Use DIV_ROUND_UP
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 06/16] crypto: " Laurent Vivier
@ 2016-05-31 16:45   ` Daniel P. Berrange
  0 siblings, 0 replies; 28+ messages in thread
From: Daniel P. Berrange @ 2016-05-31 16:45 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: qemu-trivial, qemu-devel

On Tue, May 31, 2016 at 06:35:55PM +0200, Laurent Vivier wrote:
> Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
> 
> This patch is the result of coccinelle script
> scripts/coccinelle/round.cocci
> 
> CC: Daniel P. Berrange <berrange@redhat.com>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---
>  crypto/block-luks.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)

Reviewed-by: Daniel P. Berrange <berrange@redhat.com>


Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Qemu-devel] [PATCH 01/16] coccinelle: use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d))
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 01/16] coccinelle: " Laurent Vivier
@ 2016-05-31 17:12   ` Eric Blake
  2016-05-31 17:24     ` Laurent Vivier
  0 siblings, 1 reply; 28+ messages in thread
From: Eric Blake @ 2016-05-31 17:12 UTC (permalink / raw)
  To: Laurent Vivier, qemu-trivial, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1271 bytes --]

On 05/31/2016 10:35 AM, Laurent Vivier wrote:
> sample from http://coccinellery.org/
> 
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---
>  scripts/coccinelle/round.cocci | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
>  create mode 100644 scripts/coccinelle/round.cocci
> 
> diff --git a/scripts/coccinelle/round.cocci b/scripts/coccinelle/round.cocci
> new file mode 100644
> index 0000000..ed06773
> --- /dev/null
> +++ b/scripts/coccinelle/round.cocci
> @@ -0,0 +1,19 @@
> +// Use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d))
> +@@
> +expression e1;
> +expression e2;
> +@@
> +(
> +- ((e1) + e2 - 1) / (e2)
> ++ DIV_ROUND_UP(e1,e2)

Should this also cover things like:

((e1) & e2) / (e2 + 1)

or with bit-shifts in place of division? I don't know how much
coccinelle can spot other issues (at least until I review the rest of
your series), but at any rate your patch looks like a good first start.
I also like the fact that we are committing the script into the repo, so
that we can reuse it to catch future additions of the open-coded forms.

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Qemu-devel] [PATCH 02/16] parallels: Use DIV_ROUND_UP
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 02/16] parallels: Use DIV_ROUND_UP Laurent Vivier
@ 2016-05-31 17:18   ` Eric Blake
  0 siblings, 0 replies; 28+ messages in thread
From: Eric Blake @ 2016-05-31 17:18 UTC (permalink / raw)
  To: Laurent Vivier, qemu-trivial, qemu-devel; +Cc: qemu-block

[-- Attachment #1: Type: text/plain, Size: 521 bytes --]

On 05/31/2016 10:35 AM, Laurent Vivier wrote:
> Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
> 
> This patch is the result of coccinelle script
> scripts/coccinelle/round.cocci
> 
> CC: qemu-block@nongnu.org
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---
>  block/parallels.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Qemu-devel] [PATCH 03/16] qcow/qcow2: Use DIV_ROUND_UP
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 03/16] qcow/qcow2: " Laurent Vivier
@ 2016-05-31 17:20   ` Eric Blake
  0 siblings, 0 replies; 28+ messages in thread
From: Eric Blake @ 2016-05-31 17:20 UTC (permalink / raw)
  To: Laurent Vivier, qemu-trivial, qemu-devel; +Cc: qemu-block

[-- Attachment #1: Type: text/plain, Size: 609 bytes --]

On 05/31/2016 10:35 AM, Laurent Vivier wrote:
> Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
> 
> This patch is the result of coccinelle script
> scripts/coccinelle/round.cocci
> 
> CC: qemu-block@nongnu.org
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---
>  block/qcow.c           | 4 ++--
>  block/qcow2-cluster.c  | 4 ++--
>  block/qcow2-refcount.c | 6 ++----
>  3 files changed, 6 insertions(+), 8 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Qemu-devel] [PATCH 01/16] coccinelle: use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d))
  2016-05-31 17:12   ` Eric Blake
@ 2016-05-31 17:24     ` Laurent Vivier
  0 siblings, 0 replies; 28+ messages in thread
From: Laurent Vivier @ 2016-05-31 17:24 UTC (permalink / raw)
  To: Eric Blake, qemu-trivial, qemu-devel



On 31/05/2016 19:12, Eric Blake wrote:
> On 05/31/2016 10:35 AM, Laurent Vivier wrote:
>> sample from http://coccinellery.org/
>>
>> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
>> ---
>>  scripts/coccinelle/round.cocci | 19 +++++++++++++++++++
>>  1 file changed, 19 insertions(+)
>>  create mode 100644 scripts/coccinelle/round.cocci
>>
>> diff --git a/scripts/coccinelle/round.cocci b/scripts/coccinelle/round.cocci
>> new file mode 100644
>> index 0000000..ed06773
>> --- /dev/null
>> +++ b/scripts/coccinelle/round.cocci
>> @@ -0,0 +1,19 @@
>> +// Use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d))
>> +@@
>> +expression e1;
>> +expression e2;
>> +@@
>> +(
>> +- ((e1) + e2 - 1) / (e2)
>> ++ DIV_ROUND_UP(e1,e2)
> 
> Should this also cover things like:
> 
> ((e1) & e2) / (e2 + 1)

It's true only if (e2 + 1) is a power of two... and I don't know if we
can check that with coccinelle... perhaps we can filter them manually then.

> or with bit-shifts in place of division? I don't know how much
> coccinelle can spot other issues (at least until I review the rest of
> your series), but at any rate your patch looks like a good first start.
> I also like the fact that we are committing the script into the repo, so
> that we can reuse it to catch future additions of the open-coded forms.
> 
> Reviewed-by: Eric Blake <eblake@redhat.com>
> 

Thanks,
Laurent

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Qemu-devel] [PATCH 04/16] qed: Use DIV_ROUND_UP
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 04/16] qed: " Laurent Vivier
@ 2016-05-31 17:49   ` Eric Blake
  0 siblings, 0 replies; 28+ messages in thread
From: Eric Blake @ 2016-05-31 17:49 UTC (permalink / raw)
  To: Laurent Vivier, qemu-trivial, qemu-devel; +Cc: qemu-block

[-- Attachment #1: Type: text/plain, Size: 559 bytes --]

On 05/31/2016 10:35 AM, Laurent Vivier wrote:
> Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
> 
> This patch is the result of coccinelle script
> scripts/coccinelle/round.cocci
> 
> CC: qemu-block@nongnu.org
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---
>  block/qed-check.c | 3 +--
>  block/qed.c       | 3 +--
>  2 files changed, 2 insertions(+), 4 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Qemu-devel] [PATCH 05/16] block: Use DIV_ROUND_UP
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 05/16] block: " Laurent Vivier
@ 2016-05-31 17:50   ` Eric Blake
  0 siblings, 0 replies; 28+ messages in thread
From: Eric Blake @ 2016-05-31 17:50 UTC (permalink / raw)
  To: Laurent Vivier, qemu-trivial, qemu-devel; +Cc: qemu-block

[-- Attachment #1: Type: text/plain, Size: 1318 bytes --]

On 05/31/2016 10:35 AM, Laurent Vivier wrote:
> Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
> 
> This patch is the result of coccinelle script
> scripts/coccinelle/round.cocci
> 
> CC: qemu-block@nongnu.org
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---
>  block/vvfat.c      | 3 +--
>  hw/block/tc58128.c | 2 +-
>  2 files changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/block/vvfat.c b/block/vvfat.c
> index a39dbe6..6d2e21c 100644
> --- a/block/vvfat.c
> +++ b/block/vvfat.c
> @@ -1960,8 +1960,7 @@ DLOG(fprintf(stderr, "check direntry %d:\n", i); print_direntry(direntries + i))
>  		/* check file size with FAT */
>  		cluster_count = get_cluster_count_for_direntry(s, direntries + i, path2);
>  		if (cluster_count !=
> -			(le32_to_cpu(direntries[i].size) + s->cluster_size
> -			 - 1) / s->cluster_size) {
> +            DIV_ROUND_UP(le32_to_cpu(direntries[i].size), s->cluster_size)) {

The tab-vs.-space issues in this file make the patch look weird.  It's
not your fault, but you may want to manually touch up the result so that
visual indentation under 8-spaces-per-tab still looks okay.

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Qemu-devel] [PATCH 07/16] xen: Use DIV_ROUND_UP
  2016-05-31 16:35 ` [Qemu-devel] [PATCH 07/16] xen: " Laurent Vivier
@ 2016-06-01  9:33   ` Stefano Stabellini
  0 siblings, 0 replies; 28+ messages in thread
From: Stefano Stabellini @ 2016-06-01  9:33 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: qemu-trivial, qemu-devel, Stefano Stabellini

On Tue, 31 May 2016, Laurent Vivier wrote:
> Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
> 
> This patch is the result of coccinelle script
> scripts/coccinelle/round.cocci
> 
> CC: Stefano Stabellini <sstabellini@kernel.org>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


>  hw/display/xenfb.c | 4 ++--
>  xen-hvm.c          | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c
> index 9866dfd..570b097 100644
> --- a/hw/display/xenfb.c
> +++ b/hw/display/xenfb.c
> @@ -472,9 +472,9 @@ static int xenfb_map_fb(struct XenFB *xenfb)
>          xenfb->pixels = NULL;
>      }
>  
> -    xenfb->fbpages = (xenfb->fb_len + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;
> +    xenfb->fbpages = DIV_ROUND_UP(xenfb->fb_len, XC_PAGE_SIZE);
>      n_fbdirs = xenfb->fbpages * mode / 8;
> -    n_fbdirs = (n_fbdirs + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;
> +    n_fbdirs = DIV_ROUND_UP(n_fbdirs, XC_PAGE_SIZE);
>  
>      pgmfns = g_malloc0(sizeof(xen_pfn_t) * n_fbdirs);
>      fbmfns = g_malloc0(sizeof(xen_pfn_t) * xenfb->fbpages);
> diff --git a/xen-hvm.c b/xen-hvm.c
> index 01ee25d..a0da8d7 100644
> --- a/xen-hvm.c
> +++ b/xen-hvm.c
> @@ -567,7 +567,7 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
>  {
>      hwaddr npages = size >> TARGET_PAGE_BITS;
>      const int width = sizeof(unsigned long) * 8;
> -    unsigned long bitmap[(npages + width - 1) / width];
> +    unsigned long bitmap[DIV_ROUND_UP(npages, width)];
>      int rc, i, j;
>      const XenPhysmap *physmap = NULL;
>  
> -- 
> 2.5.5
> 

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Qemu-devel] [PATCH 16/16] hbitmap: Use DIV_ROUND_UP
  2016-05-31 16:36 ` [Qemu-devel] [PATCH 16/16] hbitmap: " Laurent Vivier
@ 2016-06-03 18:17   ` John Snow
  0 siblings, 0 replies; 28+ messages in thread
From: John Snow @ 2016-06-03 18:17 UTC (permalink / raw)
  To: Laurent Vivier, qemu-trivial, qemu-devel; +Cc: Paolo Bonzini



On 05/31/2016 12:36 PM, Laurent Vivier wrote:
> Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
> 
> This patch is the result of coccinelle script
> scripts/coccinelle/round.cocci
> 
> CC: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---
>  tests/test-hbitmap.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c
> index abe1427..097fe8e 100644
> --- a/tests/test-hbitmap.c
> +++ b/tests/test-hbitmap.c
> @@ -80,7 +80,7 @@ static void hbitmap_test_init(TestHBitmapData *data,
>      size_t n;
>      data->hb = hbitmap_alloc(size, granularity);
>  
> -    n = (size + BITS_PER_LONG - 1) / BITS_PER_LONG;
> +    n = DIV_ROUND_UP(size, BITS_PER_LONG);
>      if (n == 0) {
>          n = 1;
>      }
> @@ -94,7 +94,7 @@ static void hbitmap_test_init(TestHBitmapData *data,
>  
>  static inline size_t hbitmap_test_array_size(size_t bits)
>  {
> -    size_t n = (bits + BITS_PER_LONG - 1) / BITS_PER_LONG;
> +    size_t n = DIV_ROUND_UP(bits, BITS_PER_LONG);
>      return n ? n : 1;
>  }
>  
> @@ -186,7 +186,7 @@ static void hbitmap_test_reset_all(TestHBitmapData *data)
>  
>      hbitmap_reset_all(data->hb);
>  
> -    n = (data->size + BITS_PER_LONG - 1) / BITS_PER_LONG;
> +    n = DIV_ROUND_UP(data->size, BITS_PER_LONG);
>      if (n == 0) {
>          n = 1;
>      }
> 

Reviewed-by: John Snow <jsnow@redhat.com>

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d))
  2016-05-31 16:35 [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Laurent Vivier
                   ` (15 preceding siblings ...)
  2016-05-31 16:36 ` [Qemu-devel] [PATCH 16/16] hbitmap: " Laurent Vivier
@ 2016-06-05  7:16 ` Michael Tokarev
  16 siblings, 0 replies; 28+ messages in thread
From: Michael Tokarev @ 2016-06-05  7:16 UTC (permalink / raw)
  To: Laurent Vivier, qemu-trivial, qemu-devel

31.05.2016 19:35, Laurent Vivier wrote:
> This patch series is the result of coccinelle
> script scripts/coccinelle/round.coccii, added by the first patch.
> 
> Laurent Vivier (16):
>   coccinelle: use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d))
>   parallels: Use DIV_ROUND_UP
>   qcow/qcow2: Use DIV_ROUND_UP
>   qed: Use DIV_ROUND_UP
>   block: Use DIV_ROUND_UP
>   crypto: Use DIV_ROUND_UP
>   xen: Use DIV_ROUND_UP
>   audio: Use DIV_ROUND_UP
>   SPICE: Use DIV_ROUND_UP
>   rocker: Use DIV_ROUND_UP
>   usb: Use DIV_ROUND_UP
>   slirp: Use DIV_ROUND_UP
>   linux-user: Use DIV_ROUND_UP
>   pc-bios/s390-ccw: Use DIV_ROUND_UP
>   qemu-timer: Use DIV_ROUND_UP
>   hbitmap: Use DIV_ROUND_UP

Applied all to -trivial, thank you!

/mjt

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2016-06-05  7:16 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-31 16:35 [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Laurent Vivier
2016-05-31 16:35 ` [Qemu-devel] [PATCH 01/16] coccinelle: " Laurent Vivier
2016-05-31 17:12   ` Eric Blake
2016-05-31 17:24     ` Laurent Vivier
2016-05-31 16:35 ` [Qemu-devel] [PATCH 02/16] parallels: Use DIV_ROUND_UP Laurent Vivier
2016-05-31 17:18   ` Eric Blake
2016-05-31 16:35 ` [Qemu-devel] [PATCH 03/16] qcow/qcow2: " Laurent Vivier
2016-05-31 17:20   ` Eric Blake
2016-05-31 16:35 ` [Qemu-devel] [PATCH 04/16] qed: " Laurent Vivier
2016-05-31 17:49   ` Eric Blake
2016-05-31 16:35 ` [Qemu-devel] [PATCH 05/16] block: " Laurent Vivier
2016-05-31 17:50   ` Eric Blake
2016-05-31 16:35 ` [Qemu-devel] [PATCH 06/16] crypto: " Laurent Vivier
2016-05-31 16:45   ` Daniel P. Berrange
2016-05-31 16:35 ` [Qemu-devel] [PATCH 07/16] xen: " Laurent Vivier
2016-06-01  9:33   ` Stefano Stabellini
2016-05-31 16:35 ` [Qemu-devel] [PATCH 08/16] audio: " Laurent Vivier
2016-05-31 16:35 ` [Qemu-devel] [PATCH 09/16] SPICE: " Laurent Vivier
2016-05-31 16:35 ` [Qemu-devel] [PATCH 10/16] rocker: " Laurent Vivier
2016-05-31 16:36 ` [Qemu-devel] [PATCH 11/16] usb: " Laurent Vivier
2016-05-31 16:36 ` [Qemu-devel] [PATCH 12/16] slirp: " Laurent Vivier
2016-05-31 16:41   ` Samuel Thibault
2016-05-31 16:36 ` [Qemu-devel] [PATCH 13/16] linux-user: " Laurent Vivier
2016-05-31 16:36 ` [Qemu-devel] [PATCH 14/16] pc-bios/s390-ccw: " Laurent Vivier
2016-05-31 16:36 ` [Qemu-devel] [PATCH 15/16] qemu-timer: " Laurent Vivier
2016-05-31 16:36 ` [Qemu-devel] [PATCH 16/16] hbitmap: " Laurent Vivier
2016-06-03 18:17   ` John Snow
2016-06-05  7:16 ` [Qemu-devel] [PATCH 00/16] use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d)) Michael Tokarev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.