use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d))
Subsystems (3)
cover use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d))
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
Signature · 1 line
2.5.5
PATCH 1/16 coccinelle: use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d))
sample from http://coccinellery.org/
--- scripts/coccinelle/round.cocci | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 scripts/coccinelle/round.cocci
scripts/coccinelle/round.cocci new file +19 -0
@@ -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)
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH 01/16] coccinelle: use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d))
Quoted 14 lines · Laurent Vivier
sample from http://coccinellery.org/
Signed-off-by Laurent Vivier <[email protected]>--- scripts/coccinelle/round.cocci | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 scripts/coccinelle/round.cocciscripts/coccinelle/round.cocci new file +0
-0
scripts/coccinelle/round.cocci line 8
Quoted 8 lines
scripts/coccinelle/round.cocci new file +8
-0@@ -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.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 01/16] coccinelle: use macro DIV_ROUND_UP instead of (((n) + (d) - 1) /(d))
Quoted 26 lines · Eric Blake
Quoted 14 lines · Laurent Vivier
sample from http://coccinellery.org/
Signed-off-by Laurent Vivier <[email protected]>--- scripts/coccinelle/round.cocci | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 scripts/coccinelle/round.cocciscripts/coccinelle/round.cocci new file +0
-0scripts/coccinelle/round.cocci line 8
Quoted 8 lines
scripts/coccinelle/round.cocci new file +8
-0@@ -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:
Quoted 1 line
((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.
Quoted 8 lines
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 <[email protected]>
Thanks,
Laurent
PATCH 2/16 parallels: Use DIV_ROUND_UP
In reply to Laurent VivierReplace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
This patch is the result of coccinelle scriptscripts/coccinelle/round.cocci
--- block/parallels.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/parallels.c +1 -1
@@ -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;
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH 02/16] parallels: Use DIV_ROUND_UP
Quoted 10 lines · Laurent Vivier
Replace (((n) + (d) - 1) /(d)) by
DIV_ROUND_UP(n,d).This patch is the result of coccinelle script
scripts/coccinelle/round.cocciSigned-off-by Laurent Vivier <[email protected]>--- block/parallels.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 3/16 qcow/qcow2: Use DIV_ROUND_UP
In reply to Laurent VivierReplace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
This patch is the result of coccinelle scriptscripts/coccinelle/round.cocci
--- block/qcow.c | 4 ++-- block/qcow2-cluster.c | 4 ++-- block/qcow2-refcount.c | 6 ++---- 3 files changed, 6 insertions(+), 8 deletions(-)
block/qcow.c +2 -2
@@ -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 ) {
block/qcow2-cluster.c +2 -2
@@ -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 );
block/qcow2-refcount.c +2 -4
@@ -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);
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH 03/16] qcow/qcow2: Use DIV_ROUND_UP
Quoted 5 lines · Laurent Vivier
Replace (((n) + (d) - 1) /(d)) by
DIV_ROUND_UP(n,d).This patch is the result of coccinelle script
scripts/coccinelle/round.cocci
Quoted 8 lines
Signed-off-by Laurent Vivier <[email protected]>--- block/qcow.c | 4 ++-- block/qcow2-cluster.c | 4 ++-- block/qcow2-refcount.c | 6 ++---- 3 files changed, 6 insertions(+), 8 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 4/16 qed: Use DIV_ROUND_UP
In reply to Laurent VivierReplace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
This patch is the result of coccinelle scriptscripts/coccinelle/round.cocci
--- block/qed-check.c | 3 +-- block/qed.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
block/qed-check.c +1 -2
@@ -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 */
block/qed.c +1 -2
@@ -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);
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH 04/16] qed: Use DIV_ROUND_UP
Quoted 5 lines · Laurent Vivier
Replace (((n) + (d) - 1) /(d)) by
DIV_ROUND_UP(n,d).This patch is the result of coccinelle script
scripts/coccinelle/round.cocci
Quoted 7 lines
Signed-off-by Laurent Vivier <[email protected]>--- block/qed-check.c | 3 +-- block/qed.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 5/16 block: Use DIV_ROUND_UP
In reply to Laurent VivierReplace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
This patch is the result of coccinelle scriptscripts/coccinelle/round.cocci
--- block/vvfat.c | 3 +-- hw/block/tc58128.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-)
block/vvfat.c +1 -2
@@ -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; }
hw/block/tc58128.c +1 -1
@@ -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 ;
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH 05/16] block: Use DIV_ROUND_UP
Quoted 17 lines · Laurent Vivier
Replace (((n) + (d) - 1) /(d)) by
DIV_ROUND_UP(n,d).This patch is the result of coccinelle script
scripts/coccinelle/round.cocciSigned-off-by Laurent Vivier <[email protected]>--- block/vvfat.c | 3 +-- hw/block/tc58128.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-)block/vvfat.c +0
-0
block/vvfat.c DLOG(fprintf(stderr, "check direntry %d:\n", i); print_direntry(direntries + i)) · line 1963
Quoted 6 lines
block/vvfat.c +1
-2@@ -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.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 6/16 crypto: Use DIV_ROUND_UP
In reply to Laurent VivierReplace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
This patch is the result of coccinelle scriptscripts/coccinelle/round.cocci
--- crypto/block-luks.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
crypto/block-luks.c +2 -4
@@ -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 );
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH 06/16] crypto: Use DIV_ROUND_UP
Quoted 10 lines · Laurent Vivier
Replace (((n) + (d) - 1) /(d)) by
DIV_ROUND_UP(n,d).This patch is the result of coccinelle script
scripts/coccinelle/round.cocciCC Daniel P. Berrange <[email protected]>Signed-off-by Laurent Vivier <[email protected]>--- crypto/block-luks.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
Regards,
Daniel
Signature · 4 lines
|: 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 :|
PATCH 7/16 xen: Use DIV_ROUND_UP
In reply to Laurent VivierReplace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
This patch is the result of coccinelle scriptscripts/coccinelle/round.cocci
--- hw/display/xenfb.c | 4 ++-- xen-hvm.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
hw/display/xenfb.c +2 -2
@@ -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);
xen-hvm.c +1 -1
@@ -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 ;
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH 07/16] xen: Use DIV_ROUND_UP
Quoted 7 lines · Laurent Vivier
Replace (((n) + (d) - 1) /(d)) by
DIV_ROUND_UP(n,d).This patch is the result of coccinelle script
scripts/coccinelle/round.cocciCC Stefano Stabellini <[email protected]>Signed-off-by Laurent Vivier <[email protected]>
Quoted 36 lines
hw/display/xenfb.c | 4 ++-- xen-hvm.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)hw/display/xenfb.c +2
-2@@ -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);xen-hvm.c +1
-1@@ -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 ;Signature · 1 line
2.5.5
PATCH 8/16 audio: Use DIV_ROUND_UP
In reply to Laurent VivierReplace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
This patch is the result of coccinelle scriptscripts/coccinelle/round.cocci
--- hw/audio/pcspk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/audio/pcspk.c +1 -1
@@ -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)
Signature · 1 line
2.5.5
PATCH 9/16 SPICE: Use DIV_ROUND_UP
In reply to Laurent VivierReplace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
This patch is the result of coccinelle scriptscripts/coccinelle/round.cocci
--- ui/spice-display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ui/spice-display.c +1 -1
@@ -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);
Signature · 1 line
2.5.5
PATCH 10/16 rocker: Use DIV_ROUND_UP
In reply to Laurent VivierReplace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
This patch is the result of coccinelle scriptscripts/coccinelle/round.cocci
--- hw/net/rocker/rocker_of_dpa.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
hw/net/rocker/rocker_of_dpa.c +2 -3
@@ -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;
Signature · 1 line
2.5.5
PATCH 11/16 usb: Use DIV_ROUND_UP
In reply to Laurent VivierReplace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
This patch is the result of coccinelle scriptscripts/coccinelle/round.cocci
--- hw/usb/redirect.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/usb/redirect.c +3 -3
@@ -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 )) {
Signature · 1 line
2.5.5
PATCH 12/16 slirp: Use DIV_ROUND_UP
In reply to Laurent VivierReplace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
This patch is the result of coccinelle scriptscripts/coccinelle/round.cocci
--- slirp/dnssearch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
slirp/dnssearch.c +2 -2
@@ -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 ;
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH 12/16] slirp: Use DIV_ROUND_UP
Quoted 6 lines · 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.cocciSigned-off-by Laurent Vivier <[email protected]>
Quoted 29 lines
--- slirp/dnssearch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)slirp/dnssearch.c +2
-2@@ -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 ;Signature · 1 line
2.5.5
Signature · 6 lines
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)PATCH 13/16 linux-user: Use DIV_ROUND_UP
In reply to Laurent VivierReplace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
This patch is the result of coccinelle scriptscripts/coccinelle/round.cocci
--- linux-user/syscall.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/syscall.c +2 -2
@@ -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,
Signature · 1 line
2.5.5
PATCH 14/16 pc-bios/s390-ccw: Use DIV_ROUND_UP
In reply to Laurent VivierReplace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
This patch is the result of coccinelle scriptscripts/coccinelle/round.cocci
--- pc-bios/s390-ccw/bootmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
pc-bios/s390-ccw/bootmap.c +1 -1
@@ -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" );
Signature · 1 line
2.5.5
PATCH 15/16 qemu-timer: Use DIV_ROUND_UP
In reply to Laurent VivierReplace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
This patch is the result of coccinelle scriptscripts/coccinelle/round.cocci
--- qemu-timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-timer.c +1 -1
@@ -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 ) {
Signature · 1 line
2.5.5
PATCH 16/16 hbitmap: Use DIV_ROUND_UP
In reply to Laurent VivierReplace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
This patch is the result of coccinelle scriptscripts/coccinelle/round.cocci
--- tests/test-hbitmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tests/test-hbitmap.c +3 -3
@@ -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 ; }
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH 16/16] hbitmap: Use DIV_ROUND_UP
Quoted 35 lines · Laurent Vivier
Replace (((n) + (d) - 1) /(d)) by
DIV_ROUND_UP(n,d).This patch is the result of coccinelle script
scripts/coccinelle/round.cocciCC Paolo Bonzini <[email protected]>Signed-off-by Laurent Vivier <[email protected]>--- tests/test-hbitmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)tests/test-hbitmap.c +2
-2@@ -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 ; }
tests/test-hbitmap.c static void hbitmap_test_reset_all(TestHBitmapData *data) · line 192
Quoted 8 lines
tests/test-hbitmap.c +1
-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 ; }
Michael Tokarev
AppliedQuoted 12 lines · Laurent Vivier
This patch series is the result of coccinelle
scriptscripts/coccinelle/round.coccii, added by the first patch.Laurent Vivier (16):
coccinelle: use macroDIV_ROUND_UPinstead of (((n) + (d) - 1) /(d))
parallels: UseDIV_ROUND_UP
qcow/qcow2: UseDIV_ROUND_UP
qed: UseDIV_ROUND_UP
block: UseDIV_ROUND_UP
crypto: UseDIV_ROUND_UP
xen: UseDIV_ROUND_UP
audio: UseDIV_ROUND_UP
Quoted 8 lines
SPICE: Use
DIV_ROUND_UP
rocker: UseDIV_ROUND_UP
usb: UseDIV_ROUND_UP
slirp: UseDIV_ROUND_UP
linux-user: UseDIV_ROUND_UP
pc-bios/s390-ccw: UseDIV_ROUND_UP
qemu-timer: UseDIV_ROUND_UP
hbitmap: UseDIV_ROUND_UP
Applied all to -trivial, thank you!
/mjt