coccinelle script to enforce qemu/osdep.h macros usage
Subsystems (3)
cover coccinelle script to enforce qemu/osdep.h macros usage
Hi,
Another cocci script... Here the idea is to have the same script with all the osdep.h macros related rules altogether.
First run with QEMU_IS_ALIGNED() and ARRAY_SIZE().
Regards,
Phil.
PD: I used the "enforce" word because I plan to have some continuous integration job running such scripts (also the clang-tidy good stuff).
Philippe Mathieu-Daudé (29):
coccinelle: add a script to enforce qemu/osdep.h macros usage
pci: remove superfluous parenthesis
qemu-img: use QEMU_IS_ALIGNED macro
scsi-disk: use QEMU_IS_ALIGNED macro
block: use QEMU_IS_ALIGNED macro
migration/block: use QEMU_IS_ALIGNED macro
ds1338: use QEMU_IS_ALIGNED macro
ui: use QEMU_IS_ALIGNED macro
net: use QEMU_IS_ALIGNED macro
net/rocker: use QEMU_IS_ALIGNED macro
s390x/sclp: use QEMU_IS_ALIGNED macro
sm501: use QEMU_IS_ALIGNED macro
tcg: use QEMU_IS_ALIGNED macro
cris: use QEMU_IS_ALIGNED macro
microblaze: use QEMU_IS_ALIGNED macro
lm32: use QEMU_IS_ALIGNED macro
sparc: use QEMU_IS_ALIGNED macro
nios2: use QEMU_IS_ALIGNED macro
disas: use QEMU_IS_ALIGNED macro
disas: use ARRAY_SIZE macro
qga: use ARRAY_SIZE macro
vmsvga: use ARRAY_SIZE macro
async: use ARRAY_SIZE macro
tests/acpi: use ARRAY_SIZE macro
tests/qos: use ARRAY_SIZE macro
tests/tcg: use ARRAY_SIZE macro
tests/hbitmap: use ARRAY_SIZE macro
tests/qapi: use QEMU_IS_ALIGNED macro
tests/qapi: use ARRAY_SIZE macro
accel/tcg/translate-all.c | 2 +- block/io.c | 4 +-- block/qcow2-cache.c | 2 +- block/vhdx-log.c | 2 +- block/vvfat.c | 2 +- disas.c | 2 +- disas/ia64.c | 4 +-- disas/m68k.c | 5 ++-- disas/ppc.c | 12 +++----- disas/s390.c | 3 +- hw/display/sm501_template.h | 2 +- hw/display/vmware_vga.c | 5 ++-- hw/misc/pci-testdev.c | 4 +-- hw/net/rocker/rocker.c | 2 +- hw/s390x/sclp.c | 4 +-- hw/scsi/scsi-disk.c | 4 +-- hw/timer/ds1338.c | 4 +-- migration/block.c | 2 +- net/eth.c | 2 +- qemu-img.c | 2 +- qga/commands-posix.c | 2 +- scripts/coccinelle/use_osdep.cocci | 60 +++++++++++++++++++++++++++++++++++++ target/cris/translate.c | 6 ++-- target/lm32/translate.c | 2 +- target/microblaze/op_helper.c | 3 +- target/microblaze/translate.c | 3 +- target/nios2/translate.c | 2 +- target/sparc/cpu.c | 4 +-- tests/acpi-utils.h | 2 +- tests/libqos/libqos.c | 2 +- tests/tcg/alpha/test-cond.c | 2 +- tests/tcg/alpha/test-ovf.c | 2 +- tests/test-hbitmap.c | 6 ++-- tests/test-qobject-output-visitor.c | 2 +- tests/test-string-output-visitor.c | 2 +- ui/console-gl.c | 2 +- util/aio-posix.c | 2 +- 37 files changed, 114 insertions(+), 59 deletions(-) create mode 100644 scripts/coccinelle/use_osdep.cocci
Signature · 1 line
2.13.2
PATCH 1/29 coccinelle: add a script to enforce qemu/osdep.h macros usage
--- scripts/coccinelle/use_osdep.cocci | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 scripts/coccinelle/use_osdep.cocci
scripts/coccinelle/use_osdep.cocci new file +60 -0
@@ -0,0 +1,60 @@ +// Use macros from qemu/osdep.h +// +// Copyright: (C) 2017 Philippe Mathieu-Daudé. GPLv2+. +// Confidence: High +// Options: --macro-file scripts/cocci-macro-file.h +// +// docker run --rm -v `pwd`:`pwd` -w `pwd` philmd/coccinelle \ +// --macro-file scripts/cocci-macro-file.h \ +// --sp-file scripts/coccinelle/add_osdep.cocci \ +// --keep-comments --in-place \ +// --use-gitgrep --dir . + +// Use QEMU_IS_ALIGNED() +@@ +typedef uintptr_t; +uintptr_t ptr; +expression n, m; +@@ +( +-ptr % m == 0 ++QEMU_PTR_IS_ALIGNED(ptr, m) +| +-n % m == 0 ++QEMU_IS_ALIGNED(n, m) +) + +// Use QEMU_ALIGN_DOWN() +@@ +expression n, m; +@@ +-n / m * m ++QEMU_ALIGN_DOWN(n, m) + +// Use ARRAY_SIZE() +@@ +expression x; +@@ +-sizeof(x) / sizeof((x)[0]) ++ARRAY_SIZE(x) + +// Drop superfluous parenthesis +@@ +expression n, m; +@@ +( +-(QEMU_IS_ALIGNED(n, m)) ++QEMU_IS_ALIGNED(n, m) +| +-QEMU_IS_ALIGNED((n), m) ++QEMU_IS_ALIGNED(n, m) +| +-(QEMU_PTR_IS_ALIGNED(n, m)) ++QEMU_PTR_IS_ALIGNED(n, m) +| +-QEMU_ALIGN_DOWN((n), m) ++QEMU_ALIGN_DOWN(n, m) +| +-(ARRAY_SIZE(n)) ++ARRAY_SIZE(n) +)
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 01/29] coccinelle: add a script to enforce qemu/osdep.h macros usage
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Might be worth mentioning which macros in the commit message body, so that a grep of 'git log' spots this commit easier.
scripts/coccinelle/use_osdep.cocci line 11
Quoted 10 lines
--- scripts/coccinelle/use_osdep.cocci | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 scripts/coccinelle/use_osdep.cocciscripts/coccinelle/use_osdep.cocci new file +5
-0+// docker run --rm -v `pwd`:`pwd` -w `pwd` philmd/coccinelle \ +// --macro-file scripts/cocci-macro-file.h \ +// --sp-file scripts/coccinelle/add_osdep.cocci \ +// --keep-comments --in-place \ +// --use-gitgrep --dir .
Is '--use-gitgrep' a relatively new option to spatch (not present in my F26 coccinelle-1.0.6-7), or is it a directive specific to the docker coccinelle package you are using? It's somewhat nice if there is a clean separation between which arguments are for spatch and which are for docker.
Quoted 4 lines
scripts/coccinelle/use_osdep.cocci new file +4
-0+ +// Use QEMU_IS_ALIGNED() +@@ +typedef uintptr_t;
scripts/coccinelle/use_osdep.cocci line 25
Quoted 10 lines
scripts/coccinelle/use_osdep.cocci new file +10
-0+uintptr_t ptr; +expression n, m; +@@ +( +-ptr % m == 0 ++QEMU_PTR_IS_ALIGNED(ptr, m) +| +-n % m == 0 ++QEMU_IS_ALIGNED(n, m) +)
Is it worth also trying to flag '(n & (m - 1)) == 0' (for when m is a power of 2)?
scripts/coccinelle/use_osdep.cocci line 32
Quoted 7 lines
scripts/coccinelle/use_osdep.cocci new file +7
-0+ +// Use QEMU_ALIGN_DOWN() +@@ +expression n, m; +@@ +-n / m * m ++QEMU_ALIGN_DOWN(n, m)
Is it worth also trying to catch (n >> m) << m?
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
PATCH 2/29 pci: remove superfluous parenthesis
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- hw/misc/pci-testdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/misc/pci-testdev.c +2 -2
@@ -63,8 +63,8 @@ static const char *iotest_type[] = {#define IOTEST_TEST (i) (iotest_test[((i) % ARRAY_SIZE(iotest_test))])#define IOTEST_TYPE (i) (iotest_type[((i) / ARRAY_SIZE(iotest_test))]) -#define IOTEST_MAX_TEST (ARRAY_SIZE(iotest_test)) -#define IOTEST_MAX_TYPE (ARRAY_SIZE(iotest_type)) +#define IOTEST_MAX_TEST ARRAY_SIZE(iotest_test) +#define IOTEST_MAX_TYPE ARRAY_SIZE(iotest_type)#define IOTEST_MAX (IOTEST_MAX_TEST * IOTEST_MAX_TYPE)enum {
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 02/29] pci: remove superfluous parenthesis
Quoted 2 lines · Philippe Mathieu-Daudé
#define IOTEST_TEST(i) (iotest_test[((i) % ARRAY_SIZE(iotest_test))]) #define IOTEST_TYPE(i) (iotest_type[((i) / ARRAY_SIZE(iotest_test))])
Looks like array[(x)] is another candidate.
hw/misc/pci-testdev.c static const char *iotest_type[] = { · line 67
Quoted 4 lines
hw/misc/pci-testdev.c +2
-2-#define IOTEST_MAX_TEST (ARRAY_SIZE(iotest_test)) -#define IOTEST_MAX_TYPE (ARRAY_SIZE(iotest_type)) +#define IOTEST_MAX_TEST ARRAY_SIZE(iotest_test) +#define IOTEST_MAX_TYPE ARRAY_SIZE(iotest_type)
r~
PATCH 3/29 qemu-img: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- qemu-img.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-img.c +1 -1
@@ -3804,7 +3804,7 @@ static void bench_cb(void *opaque, int ret) b->in_flight--;/* Time for flush? Drain queue if requested, then flush */ -if (b->flush_interval && remaining % b->flush_interval ==0 ) { +if (b->flush_interval &&QEMU_IS_ALIGNED (remaining, b->flush_interval)) {if (!b->in_flight || !b->drain_on_flush) {BlockCompletionFunc *cb;
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 03/29] qemu-img: use QEMU_IS_ALIGNED macro
Quoted 6 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- qemu-img.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
qemu-img.c +1
-1@@ -3804,7 +3804,7 @@ static void bench_cb(void *opaque, int ret) b->in_flight--;/* Time for flush? Drain queue if requested, then flush */ -if (b->flush_interval && remaining % b->flush_interval ==0 ) { +if (b->flush_interval &&QEMU_IS_ALIGNED (remaining, b->flush_interval)) {if (!b->in_flight || !b->drain_on_flush) {BlockCompletionFunc *cb;
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
PATCH 4/29 scsi-disk: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- hw/scsi/scsi-disk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/scsi/scsi-disk.c +2 -2
@@ -2620,8 +2620,8 @@ static BlockAIOCB *scsi_block_do_sgio(SCSIBlockReq *req,* reads and writes that are not aligned to one logical sectors * _and_ cover multiple MemoryRegions. */ -assert (offset % s->qdev.blocksize ==0 ); -assert (iov->size % s->qdev.blocksize ==0 ); +assert (QEMU_IS_ALIGNED (offset, s->qdev.blocksize)); +assert (QEMU_IS_ALIGNED (iov->size, s->qdev.blocksize)); io_header->interface_id ='S' ;
Signature · 1 line
2.13.2
PATCH 5/29 block: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- block/io.c | 4 ++-- block/qcow2-cache.c | 2 +- block/vhdx-log.c | 2 +- block/vvfat.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
block/io.c +2 -2
@@ -1232,7 +1232,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,int max_transfer =MIN_NON_ZERO (bs->bl.max_transfer,MAX_WRITE_ZEROES_BOUNCE_BUFFER ); -assert (alignment % bs->bl.request_alignment ==0 ); +assert (QEMU_IS_ALIGNED (alignment, bs->bl.request_alignment)); head = offset % alignment; tail = (offset + bytes) % alignment; max_write_zeroes =QEMU_ALIGN_DOWN (max_write_zeroes, alignment);
@@ -2342,7 +2342,7 @@ int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset,* unaligned requests (by returning -ENOTSUP), so we must fragment * the request accordingly. */ align =MAX (bs->bl.pdiscard_alignment, bs->bl.request_alignment); -assert (align % bs->bl.request_alignment ==0 ); +assert (QEMU_IS_ALIGNED (align, bs->bl.request_alignment)); head = offset % align; tail = (offset + bytes) % align;
block/qcow2-cache.c +1 -1
@@ -58,7 +58,7 @@ static inline int qcow2_cache_get_table_idx(BlockDriverState *bs,BDRVQcow2State *s = bs->opaque;ptrdiff_t table_offset = (uint8_t *) table - (uint8_t *) c->table_array;int idx = table_offset / s->cluster_size; -assert (idx >=0 && idx < c->size && table_offset % s->cluster_size ==0 ); +assert (idx >=0 && idx < c->size &&QEMU_IS_ALIGNED (table_offset, s->cluster_size));return idx; }
block/vhdx-log.c +1 -1
@@ -282,7 +282,7 @@ static bool vhdx_log_desc_is_valid(VHDXLogDescriptor *desc, }if (desc->signature ==VHDX_LOG_ZERO_SIGNATURE ) { -if (desc->zero_length %VHDX_LOG_SECTOR_SIZE ==0 ) { +if (QEMU_IS_ALIGNED (desc->zero_length,VHDX_LOG_SECTOR_SIZE )) {/* valid */ ret = true; }
block/vvfat.c +1 -1
@@ -454,7 +454,7 @@ static direntry_t *create_long_filename(BDRVVVFATState *s, const char *filename) entry=array_get (&(s->directory),s->directory.next-1 -(i/26 ));if (i >=2 * length +2 ) { entry->name[offset] =0xff ; - }else if (i %2 ==0 ) { + }else if (QEMU_IS_ALIGNED (i,2 )) { entry->name[offset] = longname[i /2 ] &0xff ; }else { entry->name[offset] = longname[i /2 ] >>8 ;
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 05/29] block: use QEMU_IS_ALIGNED macro
Quoted 3 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>
Re: [Qemu-devel] [PATCH 05/29] block: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-DaudéQuoted 9 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- block/io.c | 4 ++-- block/qcow2-cache.c | 2 +- block/vhdx-log.c | 2 +- block/vvfat.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
The first three look okay,
block/vvfat.c static direntry_t *create_long_filename(BDRVVVFATState *s, const char *filename) · line 460
Quoted 11 lines
block/vvfat.c +1
-1@@ -454,7 +454,7 @@ static direntry_t *create_long_filename(BDRVVVFATState *s, const char *filename) entry=array_get (&(s->directory),s->directory.next-1 -(i/26 ));if (i >=2 * length +2 ) { entry->name[offset] =0xff ; - }else if (i %2 ==0 ) { + }else if (QEMU_IS_ALIGNED (i,2 )) { entry->name[offset] = longname[i /2 ] &0xff ; }else { entry->name[offset] = longname[i /2 ] >>8 ;
but this one looks a bit odd. Code-wise, it's identical, but semantically, this doesn't feel like an alignment check, so much as an even-or-odd check.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
PATCH 6/29 migration/block: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- migration/block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
migration/block.c +1 -1
@@ -933,7 +933,7 @@ static int block_load(QEMUFile *f, void *opaque, int version_id) ret =bdrv_get_info (blk_bs (blk), &bdi);if (ret ==0 && bdi.cluster_size >0 && bdi.cluster_size <=BLOCK_SIZE && -BLOCK_SIZE % bdi.cluster_size ==0 ) { +QEMU_IS_ALIGNED (BLOCK_SIZE , bdi.cluster_size)) { cluster_size = bdi.cluster_size; }else { cluster_size =BLOCK_SIZE ;
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 06/29] migration/block: use QEMU_IS_ALIGNED macro
Quoted 12 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- migration/block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)migration/block.c +0
-0
migration/block.c static int block_load(QEMUFile *f, void *opaque, int version_id) · line 939
Quoted 8 lines
migration/block.c +1
-1@@ -933,7 +933,7 @@ static int block_load(QEMUFile *f, void *opaque, int version_id) ret =bdrv_get_info (blk_bs (blk), &bdi);if (ret ==0 && bdi.cluster_size >0 && bdi.cluster_size <=BLOCK_SIZE && -BLOCK_SIZE % bdi.cluster_size ==0 ) { +QEMU_IS_ALIGNED (BLOCK_SIZE , bdi.cluster_size)) { cluster_size = bdi.cluster_size; }else { cluster_size =BLOCK_SIZE ;
Should I take this patch, or does it go through the block layer? Your call.
Later, Juan.
Re: [Qemu-devel] [PATCH 06/29] migration/block: use QEMU_IS_ALIGNED macro
Quoted 24 lines · Juan Quintela
Quoted 12 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- migration/block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)migration/block.c +0
-0migration/block.c static int block_load(QEMUFile *f, void *opaque, int version_id) · line 939
Quoted 8 lines
migration/block.c +1
-1@@ -933,7 +933,7 @@ static int block_load(QEMUFile *f, void *opaque, int version_id) ret =bdrv_get_info (blk_bs (blk), &bdi);if (ret ==0 && bdi.cluster_size >0 && bdi.cluster_size <=BLOCK_SIZE && -BLOCK_SIZE % bdi.cluster_size ==0 ) { +QEMU_IS_ALIGNED (BLOCK_SIZE , bdi.cluster_size)) { cluster_size = bdi.cluster_size; }else { cluster_size =BLOCK_SIZE ;Reviewed-by Juan Quintela <[email protected]>
Quoted 2 lines
Should I take this patch, or does it go through the block layer? Your call.
Given it is part of a set would it not make more sense going through -trivial with the rest of them?
--
Alex Bennée
PATCH 7/29 ds1338: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- hw/timer/ds1338.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/timer/ds1338.c +2 -2
@@ -65,7 +65,7 @@ static void capture_current_time(DS1338State *s) s->nvram[1 ] =to_bcd (now.tm_min);if (s->nvram[2 ] &HOURS_12 ) {int tmp = now.tm_hour; -if (tmp %12 ==0 ) { +if (QEMU_IS_ALIGNED (tmp,12 )) { tmp +=12 ; }if (tmp <=12 ) {
@@ -154,7 +154,7 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data)if (data &HOURS_PM ) { tmp +=12 ; } -if (tmp %12 ==0 ) { +if (QEMU_IS_ALIGNED (tmp,12 )) { tmp -=12 ; } now.tm_hour = tmp;
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 07/29] ds1338: use QEMU_IS_ALIGNED macro
I'm not sure this makes sense - we're dealing with time here.
Signature · 3 lines
Alastair D'Silva mob: 0423 762 819 skype: alastair_dsilva msn: [email protected] blog: http://alastair.d-silva.org Twitter: @EvilDeece
Quoted 48 lines
-----Original Message-----
From: Philippe Mathieu-Daudé [mailto:[email protected]] On Behalf Of Philippe Mathieu-Daudé
Sent: Tuesday, 18 July 2017 4:10 PM
To: [email protected]; Peter Maydell <[email protected]>; Alastair D'Silva <[email protected]>; Corey Minyard <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>; [email protected]; Eric Blake <[email protected]>
Subject: [PATCH 07/29] ds1338: useQEMU_IS_ALIGNEDmacroApplied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/timer/ds1338.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/timer/ds1338.c index renamed from hw/timer/ds1338.c +0
-0
3849b74a68..a77fe14514100644hw/timer/ds1338.c +2
-3@@ -65,7 +65,7 @@ static void capture_current_time(DS1338State *s) s->nvram[1 ] =to_bcd (now.tm_min);if (s->nvram[2 ] &HOURS_12 ) {int tmp = now.tm_hour; -if (tmp %12 ==0 ) { +if (QEMU_IS_ALIGNED (tmp,12 )) { tmp +=12 ; }if (tmp <=12 ) {@@ -154,7 +154,7 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data)if (data &HOURS_PM ) { tmp +=12 ; } -if (tmp %12 ==0 ) { +if (QEMU_IS_ALIGNED (tmp,12 )) { tmp -=12 ; } now.tm_hour = tmp; --2.13.2
---
This email has been checked for viruses by AVG.
http://www.avg.com
Re: [Qemu-devel] [PATCH 07/29] ds1338: use QEMU_IS_ALIGNED macro
Quoted 1 line · Alastair D'Silva
I'm not sure this makes sense - we're dealing with time here.
Indeed, thanks for your review!
Quoted 20 lines
Quoted 20 lines
hw/timer/ds1338.c +2
-2@@ -65,7 +65,7 @@ static void capture_current_time(DS1338State *s) s->nvram[1 ] =to_bcd (now.tm_min);if (s->nvram[2 ] &HOURS_12 ) {int tmp = now.tm_hour; -if (tmp %12 ==0 ) { +if (QEMU_IS_ALIGNED (tmp,12 )) { tmp +=12 ; }if (tmp <=12 ) {@@ -154,7 +154,7 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data)if (data &HOURS_PM ) { tmp +=12 ; } -if (tmp %12 ==0 ) { +if (QEMU_IS_ALIGNED (tmp,12 )) { tmp -=12 ; } now.tm_hour = tmp;
PATCH 8/29 ui: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- ui/console-gl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ui/console-gl.c +1 -1
@@ -80,7 +80,7 @@ void surface_gl_create_texture(ConsoleGLState *gls, DisplaySurface *surface) {assert (gls); -assert (surface_stride (surface) %surface_bytes_per_pixel (surface) ==0 ); +assert (QEMU_IS_ALIGNED (surface_stride (surface),surface_bytes_per_pixel (surface)));switch (surface->format) {case PIXMAN_BE_b8g8r8x8:
Signature · 1 line
2.13.2
PATCH 9/29 net: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- net/eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/eth.c +1 -1
@@ -332,7 +332,7 @@ eth_setup_ip4_fragmentation(const void *l2hdr, size_t l2hdr_len,uint16_t frag_off_units = frag_offset /IP_FRAG_UNIT_SIZE ;uint16_t new_ip_off; -assert (frag_offset %IP_FRAG_UNIT_SIZE ==0 ); +assert (QEMU_IS_ALIGNED (frag_offset,IP_FRAG_UNIT_SIZE ));assert ((frag_off_units & ~IP_OFFMASK ) ==0 ); orig_flags =be16_to_cpu (iphdr->ip_off) & ~(IP_OFFMASK |IP_MF );
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 09/29] net: use QEMU_IS_ALIGNED macro
Quoted 12 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- net/eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/eth.c +0
-0
net/eth.c eth_setup_ip4_fragmentation(const void *l2hdr, size_t l2hdr_len, · line 336
Quoted 6 lines
net/eth.c +1
-1@@ -332,7 +332,7 @@ eth_setup_ip4_fragmentation(const void *l2hdr, size_t l2hdr_len,uint16_t frag_off_units = frag_offset /IP_FRAG_UNIT_SIZE ;uint16_t new_ip_off; -assert (frag_offset %IP_FRAG_UNIT_SIZE ==0 ); +assert (QEMU_IS_ALIGNED (frag_offset,IP_FRAG_UNIT_SIZE ));assert ((frag_off_units & ~IP_OFFMASK ) ==0 );
This line is also a candidate for using the macro, albeit in the form QEMU_IS_ALIGNED(frag_off_units, IP_OFFMASK + 1), which might not make as much sense (but it DOES re-visit my question of whether the coccinelle script should be taught more patterns)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
PATCH 10/29 net/rocker: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- hw/net/rocker/rocker.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/rocker/rocker.c +1 -1
@@ -1419,7 +1419,7 @@ static int pci_rocker_init(PCIDevice *dev)desc_ring_set_consume (ring, cmd_consume,ROCKER_MSIX_VEC_CMD ); }else if (i ==ROCKER_RING_EVENT ) {desc_ring_set_consume (ring,NULL ,ROCKER_MSIX_VEC_EVENT ); - }else if (i %2 ==0 ) { + }else if (QEMU_IS_ALIGNED (i,2 )) {desc_ring_set_consume (ring, tx_consume,ROCKER_MSIX_VEC_TX ((i -2 ) /2 )); }else if (i %2 ==1 ) {
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 10/29] net/rocker: use QEMU_IS_ALIGNED macro
Quoted 13 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/net/rocker/rocker.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/net/rocker/rocker.c +0
-0
hw/net/rocker/rocker.c static int pci_rocker_init(PCIDevice *dev) · line 1425
Quoted 8 lines
hw/net/rocker/rocker.c +1
-1@@ -1419,7 +1419,7 @@ static int pci_rocker_init(PCIDevice *dev)desc_ring_set_consume (ring, cmd_consume,ROCKER_MSIX_VEC_CMD ); }else if (i ==ROCKER_RING_EVENT ) {desc_ring_set_consume (ring,NULL ,ROCKER_MSIX_VEC_EVENT ); - }else if (i %2 ==0 ) { + }else if (QEMU_IS_ALIGNED (i,2 )) {desc_ring_set_consume (ring, tx_consume,ROCKER_MSIX_VEC_TX ((i -2 ) /2 )); }else if (i %2 ==1 ) {
Given the if chain, I think you don't want this one.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 10/29] net/rocker: use QEMU_IS_ALIGNED macro
Quoted 8 lines · Eric Blake
Quoted 7 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/net/rocker/rocker.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 6 lines
hw/net/rocker/rocker.c +0
-0hw/net/rocker/rocker.c static int pci_rocker_init(PCIDevice *dev) · line 1425
Quoted 8 lines
hw/net/rocker/rocker.c +1
-1@@ -1419,7 +1419,7 @@ static int pci_rocker_init(PCIDevice *dev)desc_ring_set_consume (ring, cmd_consume,ROCKER_MSIX_VEC_CMD ); }else if (i ==ROCKER_RING_EVENT ) {desc_ring_set_consume (ring,NULL ,ROCKER_MSIX_VEC_EVENT ); - }else if (i %2 ==0 ) { + }else if (QEMU_IS_ALIGNED (i,2 )) {desc_ring_set_consume (ring, tx_consume,ROCKER_MSIX_VEC_TX ((i -2 ) /2 )); }else if (i %2 ==1 ) {Given the if chain, I think you don't want this one.
Indeed, dropped. Thanks for your review!
PATCH 11/29 s390x/sclp: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- hw/s390x/sclp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/s390x/sclp.c +2 -2
@@ -237,7 +237,7 @@ static void assign_storage(SCLPDevice *sclp, SCCB *sccb) } assign_addr = (assign_info->rn -1 ) * mhd->rzm; -if ((assign_addr %MEM_SECTION_SIZE ==0 ) && +if (QEMU_IS_ALIGNED (assign_addr,MEM_SECTION_SIZE ) && (assign_addr >= mhd->padded_ram_size)) {/* Re-use existing memory region if found */ mr =memory_region_find (sysmem, assign_addr,1 ).mr;
@@ -297,7 +297,7 @@ static void unassign_storage(SCLPDevice *sclp, SCCB *sccb) unassign_addr = (assign_info->rn -1 ) * mhd->rzm;/* if the addr is a multiple of 256 MB */ -if ((unassign_addr %MEM_SECTION_SIZE ==0 ) && +if (QEMU_IS_ALIGNED (unassign_addr,MEM_SECTION_SIZE ) && (unassign_addr >= mhd->padded_ram_size)) { mhd->standby_state_map[(unassign_addr - mhd->padded_ram_size) /MEM_SECTION_SIZE ] =0 ;
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 11/29] s390x/sclp: use QEMU_IS_ALIGNED macro
Quoted 21 lines · On Tue, 18 Jul 2017 03:09:47 -0300 Philippe Mathieu-Daudé <[email protected]>…
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/s390x/sclp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/s390x/sclp.c +1
-1@@ -237,7 +237,7 @@ static void assign_storage(SCLPDevice *sclp, SCCB *sccb) } assign_addr = (assign_info->rn -1 ) * mhd->rzm; -if ((assign_addr %MEM_SECTION_SIZE ==0 ) && +if (QEMU_IS_ALIGNED (assign_addr,MEM_SECTION_SIZE ) && (assign_addr >= mhd->padded_ram_size)) {/* Re-use existing memory region if found */ mr =memory_region_find (sysmem, assign_addr,1 ).mr;
hw/s390x/sclp.c static void unassign_storage(SCLPDevice *sclp, SCCB *sccb) · line 303
Quoted 8 lines
hw/s390x/sclp.c +1
-1@@ -297,7 +297,7 @@ static void unassign_storage(SCLPDevice *sclp, SCCB *sccb) unassign_addr = (assign_info->rn -1 ) * mhd->rzm;/* if the addr is a multiple of 256 MB */ -if ((unassign_addr %MEM_SECTION_SIZE ==0 ) && +if (QEMU_IS_ALIGNED (unassign_addr,MEM_SECTION_SIZE ) && (unassign_addr >= mhd->padded_ram_size)) { mhd->standby_state_map[(unassign_addr - mhd->padded_ram_size) /MEM_SECTION_SIZE ] =0 ;
Re: [Qemu-devel] [PATCH 11/29] s390x/sclp: use QEMU_IS_ALIGNED macro
Quoted 26 lines · On Tue, 18 Jul 2017 11:58:40 +0200 Cornelia Huck <[email protected]> wrote:
Quoted 23 lines · On Tue, 18 Jul 2017 03:09:47 -0300 Philippe Mathieu-Daudé <[email protected]>…
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/s390x/sclp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/s390x/sclp.c +1
-1@@ -237,7 +237,7 @@ static void assign_storage(SCLPDevice *sclp, SCCB *sccb) } assign_addr = (assign_info->rn -1 ) * mhd->rzm; -if ((assign_addr %MEM_SECTION_SIZE ==0 ) && +if (QEMU_IS_ALIGNED (assign_addr,MEM_SECTION_SIZE ) && (assign_addr >= mhd->padded_ram_size)) {/* Re-use existing memory region if found */ mr =memory_region_find (sysmem, assign_addr,1 ).mr;@@ -297,7 +297,7 @@ static void unassign_storage(SCLPDevice *sclp, SCCB *sccb) unassign_addr = (assign_info->rn -1 ) * mhd->rzm;
Quoted 8 lines
hw/s390x/sclp.c static void unassign_storage(SCLPDevice *sclp, SCCB *sccb) · line 303
Quoted 6 lines
hw/s390x/sclp.c +1
-1/* if the addr is a multiple of 256 MB */ -if ((unassign_addr %MEM_SECTION_SIZE ==0 ) && +if (QEMU_IS_ALIGNED (unassign_addr,MEM_SECTION_SIZE ) && (unassign_addr >= mhd->padded_ram_size)) { mhd->standby_state_map[(unassign_addr - mhd->padded_ram_size) /MEM_SECTION_SIZE ] =0 ;Acked-by Cornelia Huck <[email protected]>
Oh, and I assume this will go through trivial, right?
PATCH 12/29 sm501: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- hw/display/sm501_template.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/sm501_template.h +1 -1
@@ -105,7 +105,7 @@ static void glue(draw_hwc_line_, PIXEL_NAME)(uint8_t *d, const uint8_t *s,for (i =0 ; i <SM501_HWC_WIDTH && c_x + i < width; i++) {/* get pixel value */ -if (i %4 ==0 ) { +if (QEMU_IS_ALIGNED (i,4 )) { bitset =ldub_p (s); s++; }
Signature · 1 line
2.13.2
PATCH 13/29 tcg: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- accel/tcg/translate-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
accel/tcg/translate-all.c +1 -1
@@ -151,7 +151,7 @@ static void page_table_config_init(void) v_l2_levels = v_l1_shift /V_L2_BITS -1 ;assert (v_l1_bits <=V_L1_MAX_BITS ); -assert (v_l1_shift %V_L2_BITS ==0 ); +assert (QEMU_IS_ALIGNED (v_l1_shift,V_L2_BITS ));assert (v_l2_levels >=0 ); }
Signature · 1 line
2.13.2
PATCH 14/29 cris: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- target/cris/translate.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
target/cris/translate.c +3 -3
@@ -3332,14 +3332,14 @@ void cris_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,for (i =0 ; i <16 ; i++) {cpu_fprintf (f,"%s=%8.8x " , regnames[i], env->regs[i]); -if ((i +1 ) %4 ==0 ) { +if (QEMU_IS_ALIGNED (i +1 ,4 )) {cpu_fprintf (f,"\n" ); } }cpu_fprintf (f,"\nspecial regs:\n" );for (i =0 ; i <16 ; i++) {cpu_fprintf (f,"%s=%8.8x " , pregnames[i], env->pregs[i]); -if ((i +1 ) %4 ==0 ) { +if (QEMU_IS_ALIGNED (i +1 ,4 )) {cpu_fprintf (f,"\n" ); } }
@@ -3350,7 +3350,7 @@ void cris_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,for (i =0 ; i <16 ; i++) {cpu_fprintf (f,"s%2.2d=%8.8x " , i, env->sregs[srs][i]); -if ((i +1 ) %4 ==0 ) { +if (QEMU_IS_ALIGNED (i +1 ,4 )) {cpu_fprintf (f,"\n" ); } }
Signature · 1 line
2.13.2
PATCH 15/29 microblaze: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci (also added braces to satisfy checkpatch)
--- target/microblaze/op_helper.c | 3 ++- target/microblaze/translate.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
target/microblaze/op_helper.c +2 -1
@@ -108,8 +108,9 @@ void helper_debug(CPUMBState *env) (env->sregs[SR_MSR] & MSR_IE));for (i =0 ; i <32 ; i++) {qemu_log ("r%2.2d=%8.8x " , i, env->regs[i]); -if ((i +1 ) %4 ==0 ) +if (QEMU_IS_ALIGNED (i +1 ,4 )) {qemu_log ("\n" ); + } }qemu_log ("\n\n" ); }
target/microblaze/translate.c +2 -1
@@ -1839,9 +1839,10 @@ void mb_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,for (i =0 ; i <32 ; i++) {cpu_fprintf (f,"r%2.2d=%8.8x " , i, env->regs[i]); -if ((i +1 ) %4 ==0 ) +if (QEMU_IS_ALIGNED (i +1 ,4 )) {cpu_fprintf (f,"\n" ); } + }cpu_fprintf (f,"\n\n" ); }
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 15/29] microblaze: use QEMU_IS_ALIGNED macro
Quoted 4 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocci(also added braces to satisfy checkpatch)Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 40 lines
--- target/microblaze/op_helper.c | 3 ++- target/microblaze/translate.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)target/microblaze/op_helper.c +2
-1@@ -108,8 +108,9 @@ void helper_debug(CPUMBState *env) (env->sregs[SR_MSR] & MSR_IE));for (i =0 ; i <32 ; i++) {qemu_log ("r%2.2d=%8.8x " , i, env->regs[i]); -if ((i +1 ) %4 ==0 ) +if (QEMU_IS_ALIGNED (i +1 ,4 )) {qemu_log ("\n" ); + } }qemu_log ("\n\n" ); }target/microblaze/translate.c +2
-2@@ -1839,9 +1839,10 @@ void mb_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,for (i =0 ; i <32 ; i++) {cpu_fprintf (f,"r%2.2d=%8.8x " , i, env->regs[i]); -if ((i +1 ) %4 ==0 ) +if (QEMU_IS_ALIGNED (i +1 ,4 )) {cpu_fprintf (f,"\n" ); } + }cpu_fprintf (f,"\n\n" ); } --2.13.2
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 15/29] microblaze: use QEMU_IS_ALIGNED macro
Quoted 4 lines · Marc-André Lureau
Quoted 2 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocci(also added braces to satisfy checkpatch)
[...]
Quoted 21 lines
Quoted 21 lines
target/microblaze/op_helper.c +2
-1@@ -108,8 +108,9 @@ void helper_debug(CPUMBState *env) (env->sregs[SR_MSR] & MSR_IE));for (i =0 ; i <32 ; i++) {qemu_log ("r%2.2d=%8.8x " , i, env->regs[i]); -if ((i +1 ) %4 ==0 ) +if (QEMU_IS_ALIGNED (i +1 ,4 )) {qemu_log ("\n" ); + } }qemu_log ("\n\n" ); }target/microblaze/translate.c +0
-0@@ -1839,9 +1839,10 @@ void mb_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
Quoted 9 lines
target/microblaze/translate.c void mb_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, · line 1847
Quoted 9 lines
target/microblaze/translate.c +2
-1for (i =0 ; i <32 ; i++) {cpu_fprintf (f,"r%2.2d=%8.8x " , i, env->regs[i]); -if ((i +1 ) %4 ==0 ) +if (QEMU_IS_ALIGNED (i +1 ,4 )) {cpu_fprintf (f,"\n" ); } + }cpu_fprintf (f,"\n\n" ); }
I'd also vote to keep the original code here ... it's about pretty printing, not about checking the alignment of addresses.
Thomas
PATCH 16/29 lm32: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- target/lm32/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/lm32/translate.c +1 -1
@@ -1185,7 +1185,7 @@ void lm32_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,for (i =0 ; i <32 ; i++) {cpu_fprintf (f,"r%2.2d=%8.8x " , i, env->regs[i]); -if ((i +1 ) %4 ==0 ) { +if (QEMU_IS_ALIGNED (i +1 ,4 )) {cpu_fprintf (f,"\n" ); } }
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 16/29] lm32: use QEMU_IS_ALIGNED macro
Am 2017-07-18 08:09, schrieb Philippe Mathieu-Daudé:
Quoted 3 lines
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>
QEMU_IS_ALIGNED() sounds like it is used to check if a memory access is aligned. Although it does the same, the line in question is used for formatted output. I'm not sure if this macro should be used here.
-michael
Quoted 18 lines
--- target/lm32/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/lm32/translate.c +1
-1@@ -1185,7 +1185,7 @@ void lm32_cpu_dump_state(CPUState *cs, FILE *f,fprintf_function cpu_fprintf, for (i = 0; i < 32; i++) {cpu_fprintf (f,"r%2.2d=%8.8x " , i, env->regs[i]); -if ((i +1 ) %4 ==0 ) { +if (QEMU_IS_ALIGNED (i +1 ,4 )) {cpu_fprintf (f,"\n" ); }}
Re: [Qemu-devel] [PATCH 16/29] lm32: use QEMU_IS_ALIGNED macro
Quoted 9 lines · Michael Walle
Am 2017-07-18 08:09, schrieb Philippe Mathieu-Daudé:
Quoted 4 lines
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>
QEMU_IS_ALIGNED()sounds like it is used to check if a memory access is aligned. Although it does the same, the line in question is used for formatted output. I'm not sure if this macro should be used here.
+1
I think we should not replace every usage of % blindly. It does really look wrong in this case here.
Thomas
Re: [Qemu-devel] [PATCH 16/29] lm32: use QEMU_IS_ALIGNED macro
Quoted 7 lines · Thomas Huth
Quoted 6 lines · Michael Walle
Am 2017-07-18 08:09, schrieb Philippe Mathieu-Daudé:
Quoted 4 lines
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 8 lines
Quoted 3 lines
QEMU_IS_ALIGNED()sounds like it is used to check if a memory access is aligned. Although it does the same, the line in question is used for formatted output. I'm not sure if this macro should be used here.+1
I think we should not replace every usage of % blindly. It does really look wrong in this case here.
Dropped, will wear my glasses next time ;)
PATCH 18/29 nios2: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- target/nios2/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/nios2/translate.c +1 -1
@@ -925,7 +925,7 @@ void nios2_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,for (i =0 ; i <NUM_CORE_REGS ; i++) {cpu_fprintf (f,"%9s=%8.8x " , regnames[i], env->regs[i]); -if ((i +1 ) %4 ==0 ) { +if (QEMU_IS_ALIGNED (i +1 ,4 )) {cpu_fprintf (f,"\n" ); } }
Signature · 1 line
2.13.2
PATCH 19/29 disas: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
---
There is no entry for this file in MAINTAINERS, should it go under TCG/Overall?
disas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
disas.c +1 -1
@@ -151,7 +151,7 @@ static int print_insn_objdump(bfd_vma pc, disassemble_info *info, info->read_memory_func (pc, buf, n, info);for (i =0 ; i < n; ++i) { -if (i %32 ==0 ) { +if (QEMU_IS_ALIGNED (i,32 )) { info->fprintf_func (info->stream,"\n%s: " , prefix); } info->fprintf_func (info->stream,"%02x" , buf[i]);
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 19/29] disas: use QEMU_IS_ALIGNED macro
Hi
Quoted 3 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 3 lines
---
There is no entry for this file in
MAINTAINERS, should it go under TCG/Overall?
That would make sense to me.
Quoted 21 lines
disas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)disas.c +1
-2@@ -151,7 +151,7 @@ static int print_insn_objdump(bfd_vma pc, disassemble_info *info, info->read_memory_func (pc, buf, n, info);for (i =0 ; i < n; ++i) { -if (i %32 ==0 ) { +if (QEMU_IS_ALIGNED (i,32 )) { info->fprintf_func (info->stream,"\n%s: " , prefix); } info->fprintf_func (info->stream,"%02x" , buf[i]); --2.13.2
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 19/29] disas: use QEMU_IS_ALIGNED macro
Quoted 5 lines · Marc-André Lureau
Hi
Quoted 1 line · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocci
[...]
Quoted 7 lines
Quoted 7 lines
disas.c +0
-0@@ -151,7 +151,7 @@ static int print_insn_objdump(bfd_vma pc, disassemble_info *info, info->read_memory_func (pc, buf, n, info);
Quoted 6 lines
disas.c static int print_insn_objdump(bfd_vma pc, disassemble_info *info, · line 157
Quoted 6 lines
disas.c +1
-1for (i =0 ; i < n; ++i) { -if (i %32 ==0 ) { +if (QEMU_IS_ALIGNED (i,32 )) { info->fprintf_func (info->stream,"\n%s: " , prefix); } info->fprintf_func (info->stream,"%02x" , buf[i]);
This looks wrong to me. QEMU_IS_ALIGNED should be used for addresses and similar things. This part here is about pretty printing a hex dump.
The code should likely be converted to use qemu_hexdump() instead, I guess.
Thomas
Re: [Qemu-devel] [PATCH 19/29] disas: use QEMU_IS_ALIGNED macro
Quoted 24 lines · Thomas Huth
Quoted 5 lines · Marc-André Lureau
Hi
Quoted 1 line · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocci[...]
Quoted 7 lines
Quoted 7 lines
disas.c +0
-0@@ -151,7 +151,7 @@ static int print_insn_objdump(bfd_vma pc, disassemble_info *info, info->read_memory_func (pc, buf, n, info);Quoted 6 lines
disas.c static int print_insn_objdump(bfd_vma pc, disassemble_info *info, · line 157
Quoted 6 lines
disas.c +1
-1for (i =0 ; i < n; ++i) { -if (i %32 ==0 ) { +if (QEMU_IS_ALIGNED (i,32 )) { info->fprintf_func (info->stream,"\n%s: " , prefix); } info->fprintf_func (info->stream,"%02x" , buf[i]);This looks wrong to me.
QEMU_IS_ALIGNEDshould be used for addresses and similar things. This part here is about pretty printing a hex dump.
Quoted 1 line
The code should likely be converted to use
qemu_hexdump()instead, I guess.
qemu_hexdump only works with FILE*.
But I agree that QEMU_IS_ALIGNED looks weird here. I think it should mostly be used when the argument is a pointer, to hide the cast. Uses for non-pointer arguments should be decided on a one-by-one basis; "is the first argument an address" is definitely a good thing to consider. Another might be "is the second argument a variable", because "i % n == 0" is less efficient than "(i & (n - 1)) == 0".
Paolo
Paolo
Re: [Qemu-devel] [PATCH 19/29] disas: use QEMU_IS_ALIGNED macro
Quoted 7 lines · Paolo Bonzini
But I agree that
QEMU_IS_ALIGNEDlooks weird here. I think it should mostly be used when the argument is a pointer, to hide the cast. Uses for non-pointer arguments should be decided on a one-by-one basis; "is the first argument an address" is definitely a good thing to consider. Another might be "is the second argument a variable", because "i % n == 0" is less efficient than "(i & (n - 1)) == 0".
How often is QEMU_IS_ALIGNED used on non-power-of-2? Would it be worth rewriting it into bit-wise ops, at the expense of declaring that any code aligning to other values must open-code their own %? Can we have the compiler help us ensure that the second argument is a power-of-2? Conversely, if the compiler is given a constant for the second argument, and is not optimizing modulo power of two into bitwise ops (at least at CFLAGS=-O2), then that's a compiler bug.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 19/29] disas: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-Daudédisas.c static int print_insn_objdump(bfd_vma pc, disassemble_info *info, · line 157
Quoted 9 lines · Philippe Mathieu-Daudé
disas.c +1
-1@@ -151,7 +151,7 @@ static int print_insn_objdump(bfd_vma pc, disassemble_info *info, info->read_memory_func (pc, buf, n, info);for (i =0 ; i < n; ++i) { -if (i %32 ==0 ) { +if (QEMU_IS_ALIGNED (i,32 )) { info->fprintf_func (info->stream,"\n%s: " , prefix); } info->fprintf_func (info->stream,"%02x" , buf[i]);
This does not seem to be related to _alignment_ per se, it is just formatting, 32 entries per line, so that output looks more-or less compact and stays readable. To me it is a strange move, not so much logical.
It doesn't matter much either way, but with IS_ALIGNED, to me at least, it looks a bit less logical than now.
Thanks,
/mjt
PATCH 20/29 disas: use ARRAY_SIZE macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- disas/ia64.c | 4 ++-- disas/m68k.c | 5 ++--- disas/ppc.c | 12 ++++-------- disas/s390.c | 3 +-- 4 files changed, 9 insertions(+), 15 deletions(-)
disas/ia64.c +2 -2
@@ -385,7 +385,7 @@ struct ia64_operand/* Disassemble as unsigned decimal (instead of hex): */ #define IA64_OPND_FLAG_DECIMAL_UNSIGNED (1<<1) -#define NELEMS (a) ((int) (sizeof (a) / sizeof (a[0]))) +#define NELEMS (a) ((int) ARRAY_SIZE(a))static const char * ins_rsvd (const struct ia64_operand *self ATTRIBUTE_UNUSED,
@@ -2857,7 +2857,7 @@ static const unsigned short dep257[] = { 2170, 2173, 2274, 2284, 2327, 4135, 20616, 28866, 29018, }; -#define NELS (X ) (sizeof(X)/sizeof(X[0])) +#define NELS (X ) ARRAY_SIZE(X)static const struct ia64_opcode_dependency op_dependencies[] = { {NELS (dep1), dep1,NELS (dep0), dep0, },
disas/m68k.c +2 -3
@@ -4197,7 +4197,7 @@ TBL("tblunb", "tblunw", "tblunl", 0, 0), {"wdebug", 4, two(0175750, 03), two(0177770, 0xffff), "ds", mcfisa_a }, }; -const int m68k_numopcodes =sizeof m68k_opcodes /sizeof m68k_opcodes[0 ]; +const int m68k_numopcodes =ARRAY_SIZE (m68k_opcodes);/* These aliases used to be in the above table, each one duplicating all of the entries for its primary exactly. This table was
@@ -4450,8 +4450,7 @@ const struct m68k_opcode_alias m68k_opcode_aliases[] = }; -const int m68k_numaliases = -sizeof m68k_opcode_aliases /sizeof m68k_opcode_aliases[0 ]; +const int m68k_numaliases =ARRAY_SIZE (m68k_opcode_aliases);/* **** End of m68k-opc.c */ /* **** floatformat.c from sourceware.org CVS 2005-08-14. */ /* IEEE floating point support routines, for GDB, the GNU Debugger.
disas/ppc.c +3 -6
@@ -893,8 +893,7 @@ const struct powerpc_operand powerpc_operands[] = { 0x1, 25, NULL, NULL, PPC_OPERAND_OPTIONAL}, }; -const unsigned int num_powerpc_operands = (sizeof (powerpc_operands) - /sizeof (powerpc_operands[0 ])); +const unsigned int num_powerpc_operands =ARRAY_SIZE (powerpc_operands);/* The functions used to insert and extract complicated operands. */
@@ -5029,10 +5028,8 @@ const struct powerpc_opcode powerpc_opcodes[] = { }; -const int powerpc_num_opcodes = -sizeof (powerpc_opcodes) /sizeof (powerpc_opcodes[0 ]); - -/* The macro table. This is only used by the assembler. */ +const int powerpc_num_opcodes =ARRAY_SIZE (powerpc_opcodes); +/* The macro table. This is only used by the assembler. */ /* The expressions of the form (-x ! 31) & (x | 31) have the value 0
when x=0; 32-x when x is between 1 and 31; are negative if x is
@@ -5086,8 +5083,7 @@ const struct powerpc_macro powerpc_macros[] = {
{ "clrlslwi.",4, PPCCOM, "rlwinm. %0,%1,%3,(%2)-(%3),31-(%3)" },
};
-const int powerpc_num_macros =
- sizeof (powerpc_macros) / sizeof (powerpc_macros[0]); +const int powerpc_num_macros = ARRAY_SIZE(powerpc_macros);
/* This file provides several disassembler functions, all of which use
disas/s390.c +1 -2
@@ -1893,5 +1893,4 @@ static const struct s390_opcode s390_opcodes[] = { "pr", OP16(0x0101LL), MASK_E, INSTR_E, 3, 0}, }; -static const int s390_num_opcodes = -sizeof (s390_opcodes) /sizeof (s390_opcodes[0 ]); +static const int s390_num_opcodes =ARRAY_SIZE (s390_opcodes);
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 20/29] disas: use ARRAY_SIZE macro
Quoted 24 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- disas/ia64.c | 4 ++-- disas/m68k.c | 5 ++--- disas/ppc.c | 12 ++++-------- disas/s390.c | 3 +-- 4 files changed, 9 insertions(+), 15 deletions(-)disas/ia64.c +1
-1@@ -385,7 +385,7 @@ struct ia64_operand/* Disassemble as unsigned decimal (instead of hex): */ #define IA64_OPND_FLAG_DECIMAL_UNSIGNED (1<<1) -#define NELEMS (a) ((int) (sizeof (a) / sizeof (a[0]))) +#define NELEMS (a) ((int) ARRAY_SIZE(a))static const char * ins_rsvd (const struct ia64_operand *self ATTRIBUTE_UNUSED,
disas/ia64.c static const unsigned short dep257[] = { · line 2860
Quoted 5 lines
disas/ia64.c +1
-1@@ -2857,7 +2857,7 @@ static const unsigned short dep257[] = { 2170, 2173, 2274, 2284, 2327, 4135, 20616, 28866, 29018, }; -#define NELS (X ) (sizeof(X)/sizeof(X[0])) +#define NELS (X ) ARRAY_SIZE(X)
You may want to replace NELEMS & NELS with ARRAY_SIZE instead.
Quoted 78 lines
disas/ia64.c +0
-0static const struct ia64_opcode_dependency op_dependencies[] = { {NELS (dep1), dep1,NELS (dep0), dep0, },disas/m68k.c +2
-3@@ -4197,7 +4197,7 @@ TBL("tblunb", "tblunw", "tblunl", 0, 0), {"wdebug", 4, two(0175750, 03), two(0177770, 0xffff), "ds", mcfisa_a }, }; -const int m68k_numopcodes =sizeof m68k_opcodes /sizeof m68k_opcodes[0 ]; +const int m68k_numopcodes =ARRAY_SIZE (m68k_opcodes);/* These aliases used to be in the above table, each one duplicating all of the entries for its primary exactly. This table was @@ -4450,8 +4450,7 @@ const struct m68k_opcode_alias m68k_opcode_aliases[] = }; -const int m68k_numaliases = -sizeof m68k_opcode_aliases /sizeof m68k_opcode_aliases[0 ]; +const int m68k_numaliases =ARRAY_SIZE (m68k_opcode_aliases);/* **** End of m68k-opc.c */ /* **** floatformat.c from sourceware.org CVS 2005-08-14. */ /* IEEE floating point support routines, for GDB, the GNU Debugger. disas/ppc.c +4
-8@@ -893,8 +893,7 @@ const struct powerpc_operand powerpc_operands[] = { 0x1, 25, NULL, NULL, PPC_OPERAND_OPTIONAL}, }; -const unsigned int num_powerpc_operands = (sizeof (powerpc_operands) - /sizeof (powerpc_operands[0 ])); +const unsigned int num_powerpc_operands =ARRAY_SIZE (powerpc_operands);/* The functions used to insert and extract complicated operands. */ @@ -5029,10 +5028,8 @@ const struct powerpc_opcode powerpc_opcodes[] = { }; -const int powerpc_num_opcodes = -sizeof (powerpc_opcodes) /sizeof (powerpc_opcodes[0 ]); - -/* The macro table. This is only used by the assembler. */ +const int powerpc_num_opcodes =ARRAY_SIZE (powerpc_opcodes); +/* The macro table. This is only used by the assembler. */ /* The expressions of the form (-x ! 31) & (x | 31) have the value 0 when x=0; 32-x when x is between 1 and 31; are negative if x is @@ -5086,8 +5083,7 @@ const struct powerpc_macro powerpc_macros[] = { { "clrlslwi.",4, PPCCOM, "rlwinm. %0,%1,%3,(%2)-(%3),31-(%3)" }, }; -const int powerpc_num_macros = -sizeof (powerpc_macros) /sizeof (powerpc_macros[0 ]); +const int powerpc_num_macros =ARRAY_SIZE (powerpc_macros);/* This file provides several disassembler functions, all of which use disas/s390.c +1
-3@@ -1893,5 +1893,4 @@ static const struct s390_opcode s390_opcodes[] = { "pr", OP16(0x0101LL), MASK_E, INSTR_E, 3, 0}, }; -static const int s390_num_opcodes = -sizeof (s390_opcodes) /sizeof (s390_opcodes[0 ]); +static const int s390_num_opcodes =ARRAY_SIZE (s390_opcodes); --2.13.2
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 20/29] disas: use ARRAY_SIZE macro
In reply to Philippe Mathieu-DaudéQuoted 3 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>
ppc parts,
Although.. I note that this disas stuff is pulled in from binutils / gas. Are local changes going to make it harder to update from there again?
Quoted 100 lines
--- disas/ia64.c | 4 ++-- disas/m68k.c | 5 ++--- disas/ppc.c | 12 ++++-------- disas/s390.c | 3 +-- 4 files changed, 9 insertions(+), 15 deletions(-)disas/ia64.c +2
-2@@ -385,7 +385,7 @@ struct ia64_operand/* Disassemble as unsigned decimal (instead of hex): */ #define IA64_OPND_FLAG_DECIMAL_UNSIGNED (1<<1) -#define NELEMS (a) ((int) (sizeof (a) / sizeof (a[0]))) +#define NELEMS (a) ((int) ARRAY_SIZE(a))static const char * ins_rsvd (const struct ia64_operand *self ATTRIBUTE_UNUSED,@@ -2857,7 +2857,7 @@ static const unsigned short dep257[] = { 2170, 2173, 2274, 2284, 2327, 4135, 20616, 28866, 29018, }; -#define NELS (X ) (sizeof(X)/sizeof(X[0])) +#define NELS (X ) ARRAY_SIZE(X)static const struct ia64_opcode_dependency op_dependencies[] = { {NELS (dep1), dep1,NELS (dep0), dep0, },disas/m68k.c +2
-3@@ -4197,7 +4197,7 @@ TBL("tblunb", "tblunw", "tblunl", 0, 0), {"wdebug", 4, two(0175750, 03), two(0177770, 0xffff), "ds", mcfisa_a }, }; -const int m68k_numopcodes =sizeof m68k_opcodes /sizeof m68k_opcodes[0 ]; +const int m68k_numopcodes =ARRAY_SIZE (m68k_opcodes);/* These aliases used to be in the above table, each one duplicating all of the entries for its primary exactly. This table was @@ -4450,8 +4450,7 @@ const struct m68k_opcode_alias m68k_opcode_aliases[] = }; -const int m68k_numaliases = -sizeof m68k_opcode_aliases /sizeof m68k_opcode_aliases[0 ]; +const int m68k_numaliases =ARRAY_SIZE (m68k_opcode_aliases);/* **** End of m68k-opc.c */ /* **** floatformat.c from sourceware.org CVS 2005-08-14. */ /* IEEE floating point support routines, for GDB, the GNU Debugger. disas/ppc.c +4
-8@@ -893,8 +893,7 @@ const struct powerpc_operand powerpc_operands[] = { 0x1, 25, NULL, NULL, PPC_OPERAND_OPTIONAL}, }; -const unsigned int num_powerpc_operands = (sizeof (powerpc_operands) - /sizeof (powerpc_operands[0 ])); +const unsigned int num_powerpc_operands =ARRAY_SIZE (powerpc_operands);/* The functions used to insert and extract complicated operands. */ @@ -5029,10 +5028,8 @@ const struct powerpc_opcode powerpc_opcodes[] = { }; -const int powerpc_num_opcodes = -sizeof (powerpc_opcodes) /sizeof (powerpc_opcodes[0 ]); - -/* The macro table. This is only used by the assembler. */ +const int powerpc_num_opcodes =ARRAY_SIZE (powerpc_opcodes); +/* The macro table. This is only used by the assembler. */ /* The expressions of the form (-x ! 31) & (x | 31) have the value 0 when x=0; 32-x when x is between 1 and 31; are negative if x is @@ -5086,8 +5083,7 @@ const struct powerpc_macro powerpc_macros[] = { { "clrlslwi.",4, PPCCOM, "rlwinm. %0,%1,%3,(%2)-(%3),31-(%3)" }, }; -const int powerpc_num_macros = -sizeof (powerpc_macros) /sizeof (powerpc_macros[0 ]); +const int powerpc_num_macros =ARRAY_SIZE (powerpc_macros);/* This file provides several disassembler functions, all of which use disas/s390.c +1
-2@@ -1893,5 +1893,4 @@ static const struct s390_opcode s390_opcodes[] = { "pr", OP16(0x0101LL), MASK_E, INSTR_E, 3, 0}, }; -static const int s390_num_opcodes = -sizeof (s390_opcodes) /sizeof (s390_opcodes[0 ]); +static const int s390_num_opcodes =ARRAY_SIZE (s390_opcodes);
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH 21/29 qga: use ARRAY_SIZE macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- qga/commands-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qga/commands-posix.c +1 -1
@@ -896,7 +896,7 @@ static void build_guest_fsinfo_for_real_device(char const *syspath,if (p &&sscanf (q,"%u" , &host) ==1 ) { has_host = true; nhosts =build_hosts (syspath, p, has_ata, hosts, -sizeof (hosts) /sizeof (hosts[0 ]), errp); +ARRAY_SIZE (hosts), errp);if (nhosts <0 ) { goto cleanup; }
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 21/29] qga: use ARRAY_SIZE macro
Quoted 3 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 21 lines
--- qga/commands-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)qga/commands-posix.c +1
-2@@ -896,7 +896,7 @@ static void build_guest_fsinfo_for_real_device(char const *syspath,if (p &&sscanf (q,"%u" , &host) ==1 ) { has_host = true; nhosts =build_hosts (syspath, p, has_ata, hosts, -sizeof (hosts) /sizeof (hosts[0 ]), errp); +ARRAY_SIZE (hosts), errp);if (nhosts <0 ) { goto cleanup; } --2.13.2
Signature · 1 line
Marc-André Lureau
PATCH 22/29 vmsvga: use ARRAY_SIZE macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
---
No entry in MAINTAINERS, should it go under Graphics or Vmware?
hw/display/vmware_vga.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
hw/display/vmware_vga.c +2 -3
@@ -679,10 +679,9 @@ static void vmsvga_fifo_run(struct vmsvga_state_s *s)if (cursor.width >256 || cursor.height >256 || cursor.bpp >32 - ||SVGA_BITMAP_SIZE (x, y) - >sizeof (cursor.mask) /sizeof (cursor.mask[0 ]) + ||SVGA_BITMAP_SIZE (x, y) >ARRAY_SIZE (cursor.mask) ||SVGA_PIXMAP_SIZE (x, y, cursor.bpp) - >sizeof (cursor.image) /sizeof (cursor.image[0 ])) { + >ARRAY_SIZE (cursor.image)) { goto badcmd; }
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 22/29] vmsvga: use ARRAY_SIZE macro
Quoted 3 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 28 lines
---
No entry in
MAINTAINERS, should it go under Graphics or Vmware?hw/display/vmware_vga.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)hw/display/vmware_vga.c +2
-4@@ -679,10 +679,9 @@ static void vmsvga_fifo_run(struct vmsvga_state_s *s)if (cursor.width >256 || cursor.height >256 || cursor.bpp >32 - ||SVGA_BITMAP_SIZE (x, y) - >sizeof (cursor.mask) /sizeof (cursor.mask[0 ]) + ||SVGA_BITMAP_SIZE (x, y) >ARRAY_SIZE (cursor.mask) ||SVGA_PIXMAP_SIZE (x, y, cursor.bpp) - >sizeof (cursor.image) /sizeof (cursor.image[0 ])) { + >ARRAY_SIZE (cursor.image)) { goto badcmd; } --2.13.2
Signature · 1 line
Marc-André Lureau
PATCH 23/29 async: use ARRAY_SIZE macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- util/aio-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/aio-posix.c +1 -1
@@ -119,7 +119,7 @@ static int aio_epoll(AioContext *ctx, GPollFD *pfds, }if (timeout <=0 || ret >0 ) { ret =epoll_wait (ctx->epollfd, events, -sizeof (events) /sizeof (events[0 ]), +ARRAY_SIZE (events), timeout);if (ret <=0 ) { goto out;
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 23/29] async: use ARRAY_SIZE macro
Quoted 3 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 21 lines
--- util/aio-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)util/aio-posix.c +1
-2@@ -119,7 +119,7 @@ static int aio_epoll(AioContext *ctx, GPollFD *pfds, }if (timeout <=0 || ret >0 ) { ret =epoll_wait (ctx->epollfd, events, -sizeof (events) /sizeof (events[0 ]), +ARRAY_SIZE (events), timeout);if (ret <=0 ) { goto out; --2.13.2
Signature · 1 line
Marc-André Lureau
PATCH 24/29 tests/acpi: use ARRAY_SIZE macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- tests/acpi-utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/acpi-utils.h +1 -1
@@ -58,7 +58,7 @@ typedef struct { }while (0 );#define ACPI_READ_ARRAY (arr, addr) \ - ACPI_READ_ARRAY_PTR(arr, sizeof(arr) / sizeof(arr[0]), addr) + ACPI_READ_ARRAY_PTR(arr, ARRAY_SIZE(arr), addr)#define ACPI_READ_TABLE_HEADER (table, addr) \ do { \
Signature · 1 line
2.13.2
PATCH 25/29 libqos: use ARRAY_SIZE macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
---
No entry in MAINTAINERS for tests/libqos/* does it deserve it's own entry?
tests/libqos/libqos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/libqos/libqos.c +1 -1
@@ -258,7 +258,7 @@ void generate_pattern(void *buffer, size_t len, size_t cycle_len) p =rand () %256 ;for (i =0 ; i < len; i++) { tx[i] = p++ %256 ; -if (i % cycle_len ==0 ) { +if (QEMU_IS_ALIGNED (i, cycle_len)) { p =rand () %256 ; } }
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 25/29] libqos: use ARRAY_SIZE macro
Quoted 4 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>---
Quoted 3 lines
No entry in
MAINTAINERSfor tests/libqos/* does it deserve it's own entry?
It would, do you want to candidate? :)
Quoted 20 lines
tests/libqos/libqos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/libqos/libqos.c +1
-2@@ -258,7 +258,7 @@ void generate_pattern(void *buffer, size_t len, size_t cycle_len) p =rand () %256 ;for (i =0 ; i < len; i++) { tx[i] = p++ %256 ; -if (i % cycle_len ==0 ) { +if (QEMU_IS_ALIGNED (i, cycle_len)) { p =rand () %256 ; } } --2.13.2
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 25/29] libqos: use ARRAY_SIZE macro
In reply to Philippe Mathieu-DaudéQuoted 16 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>---
No entry in
MAINTAINERSfor tests/libqos/* does it deserve it's own entry?tests/libqos/libqos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/libqos/libqos.c +0
-0
tests/libqos/libqos.c void generate_pattern(void *buffer, size_t len, size_t cycle_len) · line 264
Quoted 8 lines
tests/libqos/libqos.c +1
-1@@ -258,7 +258,7 @@ void generate_pattern(void *buffer, size_t len, size_t cycle_len) p =rand () %256 ;for (i =0 ; i < len; i++) { tx[i] = p++ %256 ; -if (i % cycle_len ==0 ) { +if (QEMU_IS_ALIGNED (i, cycle_len)) { p =rand () %256 ; } }
The title doesn't reflect the real change.
otherwise:
Laurent
Re: [Qemu-devel] [PATCH 25/29] libqos: use ARRAY_SIZE macro
Quoted 1 line · Laurent Vivier
On 18/07/2017 08:10, Philippe Mathieu-Daudé wrote:
[...]
Quoted 2 lines
The title doesn't reflect the real change.
Good catch ;) too much rebase...
Quoted 4 lines
otherwise:
Reviewed-by Laurent Vivier <[email protected]>
Thanks!
Quoted 2 lines
Laurent
PATCH 26/29 tests/tcg: use ARRAY_SIZE macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- tests/tcg/alpha/test-cond.c | 2 +- tests/tcg/alpha/test-ovf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tests/tcg/alpha/test-cond.c +1 -1
@@ -77,7 +77,7 @@ int main (void) {int i; -for (i =0 ; i <sizeof (vectors)/sizeof (vectors[0 ]); i++) +for (i =0 ; i <ARRAY_SIZE (vectors); i++)if ((*vectors[i].func)(vectors[i].v) != vectors[i].r) {write (1 ,"Failed\n" ,7 );return 1 ;
tests/tcg/alpha/test-ovf.c +1 -1
@@ -20,7 +20,7 @@ int main (void) {int i; -for (i =0 ; i <sizeof (vectors)/sizeof (vectors[0 ]); i++) +for (i =0 ; i <ARRAY_SIZE (vectors); i++)if ((*vectors[i].func)(vectors[i].a, vectors[i].b) != vectors[i].r) {write (1 ,"Failed\n" ,7 ); }
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 26/29] tests/tcg: use ARRAY_SIZE macro
Hi
Quoted 8 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- tests/tcg/alpha/test-cond.c | 2 +- tests/tcg/alpha/test-ovf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
I think those do not include osdep.h
(sigh, tests/tcg would need some love ;)
Quoted 30 lines
tests/tcg/alpha/test-cond.c +1
-1@@ -77,7 +77,7 @@ int main (void) {int i; -for (i =0 ; i <sizeof (vectors)/sizeof (vectors[0 ]); i++) +for (i =0 ; i <ARRAY_SIZE (vectors); i++)if ((*vectors[i].func)(vectors[i].v) != vectors[i].r) {write (1 ,"Failed\n" ,7 );return 1 ;tests/tcg/alpha/test-ovf.c +1
-2@@ -20,7 +20,7 @@ int main (void) {int i; -for (i =0 ; i <sizeof (vectors)/sizeof (vectors[0 ]); i++) +for (i =0 ; i <ARRAY_SIZE (vectors); i++)if ((*vectors[i].func)(vectors[i].a, vectors[i].b) != vectors[i].r) {write (1 ,"Failed\n" ,7 ); } --2.13.2
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 26/29] tests/tcg: use ARRAY_SIZE macro
Quoted 13 lines · Marc-André Lureau
Hi
Quoted 8 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- tests/tcg/alpha/test-cond.c | 2 +- tests/tcg/alpha/test-ovf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Quoted 3 lines
I think those do not include
osdep.h(sigh, tests/tcg would need some love ;)
Pranith has had a couple of revs at this:
Subject: [PATCH v5 00/19] Cleanup of TCG tests
Date: Thu, 1 Dec 2016 00:14:14 -0500
Message-Id: <[email protected]>
We have the cross-compilers available as a fallback via docker although not every one can seamlessly use it for building stuff. Is getting a working cross-compiler setup too much of a hurdle fore those that want to build cross-arch tests?
Quoted 22 lines
Quoted 22 lines
tests/tcg/alpha/test-cond.c +1
-1@@ -77,7 +77,7 @@ int main (void) {int i; -for (i =0 ; i <sizeof (vectors)/sizeof (vectors[0 ]); i++) +for (i =0 ; i <ARRAY_SIZE (vectors); i++)if ((*vectors[i].func)(vectors[i].v) != vectors[i].r) {write (1 ,"Failed\n" ,7 );return 1 ;tests/tcg/alpha/test-ovf.c +0
-0@@ -20,7 +20,7 @@ int main (void) {int i;
Quoted 9 lines
Quoted 9 lines
tests/tcg/alpha/test-ovf.c +1
-2-for (i =0 ; i <sizeof (vectors)/sizeof (vectors[0 ]); i++) +for (i =0 ; i <ARRAY_SIZE (vectors); i++)if ((*vectors[i].func)(vectors[i].a, vectors[i].b) != vectors[i].r) {write (1 ,"Failed\n" ,7 ); } --2.13.2
--
Alex Bennée
Re: [Qemu-devel] [PATCH 26/29] tests/tcg: use ARRAY_SIZE macro
Hi
Quoted 22 lines · Alex Bennée
Quoted 13 lines · Marc-André Lureau
Hi
Quoted 8 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- tests/tcg/alpha/test-cond.c | 2 +- tests/tcg/alpha/test-ovf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)Quoted 3 lines
I think those do not include
osdep.h(sigh, tests/tcg would need some love ;)
Pranith has had a couple of revs at this:
Quoted 8 lines
Subject: [PATCH v5 00/19] Cleanup of TCG tests
Date: Thu, 1 Dec 2016 00:14:14 -0500
Message-Id: <[email protected]>We have the cross-compilers available as a fallback via docker although not every one can seamlessly use it for building stuff. Is getting a working cross-compiler setup too much of a hurdle fore those that want to build cross-arch tests?
Yes, I also did some experiments in cleaning up tests/tcg
(https://github.com/elmarco/qemu/tree/tcg-tests)
The trouble is I don't see an official/automated way to run tests/tcg tests. Which cross-compiler should I use? When I played with this, they all had various quirks, on Fedora, Debian or crosstool-ng. I haven't looked at the docker tests, is this running tests/tcg test somehow?
Re: [Qemu-devel] [PATCH 26/29] tests/tcg: use ARRAY_SIZE macro
Quoted 34 lines · Marc-André Lureau
Hi
Quoted 22 lines · Alex Bennée
Quoted 13 lines · Marc-André Lureau
Hi
Quoted 8 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- tests/tcg/alpha/test-cond.c | 2 +- tests/tcg/alpha/test-ovf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)Quoted 3 lines
I think those do not include
osdep.h(sigh, tests/tcg would need some love ;)
Pranith has had a couple of revs at this:
Quoted 8 lines
Subject: [PATCH v5 00/19] Cleanup of TCG tests
Date: Thu, 1 Dec 2016 00:14:14 -0500
Message-Id: <[email protected]>We have the cross-compilers available as a fallback via docker although not every one can seamlessly use it for building stuff. Is getting a working cross-compiler setup too much of a hurdle fore those that want to build cross-arch tests?
Quoted 6 lines
Yes, I also did some experiments in cleaning up tests/tcg
(https://github.com/elmarco/qemu/tree/tcg-tests)The trouble is I don't see an official/automated way to run tests/tcg tests. Which cross-compiler should I use? When I played with this, they all had various quirks, on Fedora, Debian or crosstool-ng.
Debian at least have put a lot of work into getting cross-compilers installed as part of the native distro with good multi-arch support. We now use plain Debian 9 for most of the QEMU cross compiles - a few older architectures still need Debian 8 with the emdebian overlay.
Quoted 2 lines
I haven't looked at the docker tests, is this running tests/tcg test somehow?
No but as tests/tcg are all pretty simple and have less cross-compile dependencies than QEMU itself it is fairly trivial to invoke docker to do a cross-build for you in-place. e.g.:
docker run --rm -t -u (id -u) -v (pwd):(pwd) -w (pwd) qemu:debian-armhf-cross arm-linux-gnueabihf-gcc tests/tcg/hello-arm.c
This is perhaps a bad example as there is a bit-rot that needs fixing. The alternative is to mine the users PATH for fairly standard cross-compile prefixes which work at least on Debian systems. I recently submitted a patch to RISU that allowed you to use either in its build-all-arches script:
https://git.linaro.org/people/peter.maydell/risu.git/tree/build-all-archs
--
Alex Bennée
Re: [Qemu-devel] [PATCH 26/29] tests/tcg: use ARRAY_SIZE macro
In reply to Alex BennéeQuoted 11 lines · Alex Bennée
Pranith has had a couple of revs at this:
Subject: [PATCH v5 00/19] Cleanup of TCG tests
Date: Thu, 1 Dec 2016 00:14:14 -0500
Message-Id: <[email protected]>We have the cross-compilers available as a fallback via docker although not every one can seamlessly use it for building stuff. Is getting a working cross-compiler setup too much of a hurdle fore those that want to build cross-arch tests?
I have a WiP branch using qemu to cross-run tests it _works_ funny but when it fails it is not funny to understand what is really buggy... /to be continued.../
Phil.
PATCH 27/29 tests/hbitmap: use ARRAY_SIZE macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- tests/test-hbitmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tests/test-hbitmap.c +3 -3
@@ -813,7 +813,7 @@ static void test_hbitmap_serialize_basic(TestHBitmapData *data,size_t buf_size;uint8_t *buf;uint64_t positions[] = {0 ,1 ,L1 -1 ,L1 ,L2 -1 ,L2 ,L2 +1 ,L3 -1 }; -int num_positions =sizeof (positions) /sizeof (positions[0 ]); +int num_positions =ARRAY_SIZE (positions);hbitmap_test_init (data,L3 ,0 );g_assert (hbitmap_is_serializable (data->hb));
@@ -838,7 +838,7 @@ static void test_hbitmap_serialize_part(TestHBitmapData *data,size_t buf_size;uint8_t *buf;uint64_t positions[] = {0 ,1 ,L1 -1 ,L1 ,L2 -1 ,L2 ,L2 +1 ,L3 -1 }; -int num_positions =sizeof (positions) /sizeof (positions[0 ]); +int num_positions =ARRAY_SIZE (positions);hbitmap_test_init (data,L3 ,0 ); buf_size =L2 ;
@@ -880,7 +880,7 @@ static void test_hbitmap_serialize_zeroes(TestHBitmapData *data,int64_t next;uint64_t min_l1 =MAX (L1 ,64 );uint64_t positions[] = {0 , min_l1,L2 ,L3 - min_l1}; -int num_positions =sizeof (positions) /sizeof (positions[0 ]); +int num_positions =ARRAY_SIZE (positions);hbitmap_test_init (data,L3 ,0 );
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 27/29] tests/hbitmap: use ARRAY_SIZE macro
Quoted 3 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 39 lines
--- tests/test-hbitmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)tests/test-hbitmap.c +3
-4@@ -813,7 +813,7 @@ static void test_hbitmap_serialize_basic(TestHBitmapData *data,size_t buf_size;uint8_t *buf;uint64_t positions[] = {0 ,1 ,L1 -1 ,L1 ,L2 -1 ,L2 ,L2 +1 ,L3 -1 }; -int num_positions =sizeof (positions) /sizeof (positions[0 ]); +int num_positions =ARRAY_SIZE (positions);hbitmap_test_init (data,L3 ,0 );g_assert (hbitmap_is_serializable (data->hb));@@ -838,7 +838,7 @@ static void test_hbitmap_serialize_part(TestHBitmapData *data,size_t buf_size;uint8_t *buf;uint64_t positions[] = {0 ,1 ,L1 -1 ,L1 ,L2 -1 ,L2 ,L2 +1 ,L3 -1 }; -int num_positions =sizeof (positions) /sizeof (positions[0 ]); +int num_positions =ARRAY_SIZE (positions);hbitmap_test_init (data,L3 ,0 ); buf_size =L2 ;@@ -880,7 +880,7 @@ static void test_hbitmap_serialize_zeroes(TestHBitmapData *data,int64_t next;uint64_t min_l1 =MAX (L1 ,64 );uint64_t positions[] = {0 , min_l1,L2 ,L3 - min_l1}; -int num_positions =sizeof (positions) /sizeof (positions[0 ]); +int num_positions =ARRAY_SIZE (positions);hbitmap_test_init (data,L3 ,0 ); --2.13.2
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 27/29] tests/hbitmap: use ARRAY_SIZE macro
In reply to Philippe Mathieu-DaudéQuoted 3 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>
PATCH 28/29 tests/qapi: use QEMU_IS_ALIGNED macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- tests/test-qobject-output-visitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/test-qobject-output-visitor.c +1 -1
@@ -558,7 +558,7 @@ static void init_native_list(UserDefNativeListUnion *cvalue)boolList **list = &cvalue->u.boolean.data;for (i =0 ; i <32 ; i++) { *list =g_new0 (boolList,1 ); - (*list)->value = (i %3 ==0 ); + (*list)->value =QEMU_IS_ALIGNED (i,3 ); (*list)->next =NULL ; list = &(*list)->next; }
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 28/29] tests/qapi: use QEMU_IS_ALIGNED macro
Quoted 3 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 21 lines
--- tests/test-qobject-output-visitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/test-qobject-output-visitor.c +1
-2@@ -558,7 +558,7 @@ static void init_native_list(UserDefNativeListUnion *cvalue)boolList **list = &cvalue->u.boolean.data;for (i =0 ; i <32 ; i++) { *list =g_new0 (boolList,1 ); - (*list)->value = (i %3 ==0 ); + (*list)->value =QEMU_IS_ALIGNED (i,3 ); (*list)->next =NULL ; list = &(*list)->next; } --2.13.2
Signature · 1 line
Marc-André Lureau
PATCH 29/29 tests/qapi: use ARRAY_SIZE macro
In reply to Philippe Mathieu-DaudéApplied using the Coccinelle semantic patch scripts/coccinelle/use_osdep.cocci
--- tests/test-string-output-visitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/test-string-output-visitor.c +1 -1
@@ -97,7 +97,7 @@ static void test_visitor_out_intList(TestOutputVisitorData *data,Error *err =NULL ;char *str; -for (i =0 ; i <sizeof (value) /sizeof (value[0 ]); i++) { +for (i =0 ; i <ARRAY_SIZE (value); i++) { *tmp =g_malloc0 (sizeof (**tmp)); (*tmp)->value = value[i]; tmp = &(*tmp)->next;
Signature · 1 line
2.13.2
Re: [Qemu-devel] [PATCH 29/29] tests/qapi: use ARRAY_SIZE macro
Quoted 3 lines · Philippe Mathieu-Daudé
Applied using the Coccinelle semantic patch
scripts/coccinelle/use_osdep.cocciSigned-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 21 lines
--- tests/test-string-output-visitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/test-string-output-visitor.c +1
-2@@ -97,7 +97,7 @@ static void test_visitor_out_intList(TestOutputVisitorData *data,Error *err =NULL ;char *str; -for (i =0 ; i <sizeof (value) /sizeof (value[0 ]); i++) { +for (i =0 ; i <ARRAY_SIZE (value); i++) { *tmp =g_malloc0 (sizeof (**tmp)); (*tmp)->value = value[i]; tmp = &(*tmp)->next; --2.13.2
Signature · 1 line
Marc-André Lureau