-Wshadow=local patches patches for 2023-09-29
Subsystems (7)
The following changes since commit 36e9aab3c569d4c9ad780473596e18479838d1aa:
migration: Move return path cleanup to main migration thread (2023-09-27 13:58:02 -0400)
are available in the Git repository at:
https://repo.or.cz/qemu/armbru.git tags/pull-shadow-2023-09-29
for you to fetch changes up to 4dba9141f97e66fdd920df37c4aa7b2ffe0d6a4a:
disas/m68k: clean up local variable shadowing (2023-09-29 10:07:21 +0200)
----------------------------------------------------------------
-Wshadow=local patches patches for 2023-09-29
----------------------------------------------------------------
Alberto Garcia (1):
test-throttle: don't shadow 'index' variable in do_test_accounting()
Alistair Francis (4):
hw/riscv: opentitan: Fixup local variables shadowing target/riscv: cpu: Fixup local variables shadowing target/riscv: vector_helper: Fixup local variables shadowing softmmu/device_tree: Fixup local variables shadowing
Ani Sinha (1):
hw/acpi: changes towards enabling -Wshadow=local
Cédric Le Goater (12):
hw/ppc: Clean up local variable shadowing in _FDT helper routine pnv/psi: Clean up local variable shadowing
spapr: Clean up local variable shadowing in spapr_dt_cpus()
spapr: Clean up local variable shadowing in spapr_init_cpus()
spapr: Clean up local variable shadowing in spapr_get_fw_dev_path() spapr/drc: Clean up local variable shadowing in rtas_ibm_configure_connector() spapr/pci: Clean up local variable shadowing in spapr_phb_realize() spapr/drc: Clean up local variable shadowing in prop_get_fdt() aspeed/i2c: Clean up local variable shadowing
aspeed: Clean up local variable shadowing
aspeed/i3c: Rename variable shadowing a local
aspeed/timer: Clean up local variable shadowing
Daniel P. Berrangé (2):
crypto: remove shadowed 'ret' variable
seccomp: avoid shadowing of 'action' variable
Eric Blake (1):
qemu-nbd: changes towards enabling -Wshadow=local
Klaus Jensen (1):
hw/nvme: Clean up local variable shadowing in nvme_ns_init()
Laurent Vivier (1):
disas/m68k: clean up local variable shadowing
Markus Armbruster (7):
migration/rdma: Fix save_page method to fail on polling error
migration: Clean up local variable shadowing
ui: Clean up local variable shadowing block/dirty-bitmap: Clean up local variable shadowing block/vdi: Clean up local variable shadowing
block: Clean up local variable shadowing
qobject atomics osdep: Make a few macros more hygienic
Peter Maydell (4):
hw/intc/arm_gicv3_its: Avoid shadowing variable in do_process_its_cmd() hw/misc/arm_sysctl.c: Avoid shadowing local variable hw/arm/smmuv3.c: Avoid shadowing variable hw/arm/smmuv3-internal.h: Don't use locals in statement macros
Peter Xu (1):
intel_iommu: Fix shadow local variables on "size"
Philippe Mathieu-Daudé (21):
tcg: Clean up local variable shadowing target/arm/tcg: Clean up local variable shadowing target/arm/hvf: Clean up local variable shadowing target/mips: Clean up local variable shadowing target/m68k: Clean up local variable shadowing target/tricore: Clean up local variable shadowing hw/arm/armv7m: Clean up local variable shadowing hw/arm/virt: Clean up local variable shadowing hw/arm/allwinner: Clean up local variable shadowing hw/m68k: Clean up local variable shadowing hw/microblaze: Clean up local variable shadowing hw/nios2: Clean up local variable shadowing net/eth: Clean up local variable shadowing crypto/cipher-gnutls.c: Clean up local variable shadowing util/vhost-user-server: Clean up local variable shadowing linux-user/strace: Clean up local variable shadowing sysemu/device_tree: Clean up local variable shadowing softmmu/memory: Clean up local variable shadowing softmmu/physmem: Clean up local variable shadowing hw/core/machine: Clean up local variable shadowing hw/intc/openpic: Clean up local variable shadowing
hw/arm/smmuv3-internal.h | 41 ++++++++++--------------------- hw/m68k/bootinfo.h | 10 +++----- include/hw/ppc/fdt.h | 8 +++--- include/qapi/qmp/qobject.h | 10 ++++++-- include/qemu/atomic.h | 17 +++++++++---- include/qemu/compiler.h | 3 +++ include/qemu/osdep.h | 27 ++++++++++++++------ include/sysemu/device_tree.h | 6 ++--- accel/tcg/tb-maint.c | 3 +-- block.c | 9 ++++--- block/monitor/bitmap-qmp-cmds.c | 19 ++++++++------- block/qcow2-bitmap.c | 3 +-- block/rbd.c | 2 +- block/stream.c | 1 - block/vdi.c | 7 +++--- block/vvfat.c | 35 +++++++++++++------------- crypto/tls-cipher-suites.c | 1 - disas/m68k.c | 8 +++--- hw/acpi/cpu_hotplug.c | 25 ++++++++++--------- hw/arm/allwinner-r40.c | 7 +++--- hw/arm/armsse.c | 16 +++++------- hw/arm/armv7m.c | 2 +- hw/arm/aspeed_ast2600.c | 10 ++++---- hw/arm/smmuv3.c | 4 +-- hw/arm/virt.c | 3 +-- hw/block/xen-block.c | 6 ++--- hw/core/machine.c | 2 -- hw/i2c/aspeed_i2c.c | 1 - hw/i386/acpi-build.c | 24 +++++++++--------- hw/i386/intel_iommu.c | 8 +++--- hw/intc/arm_gicv3_its.c | 6 ++--- hw/intc/openpic.c | 7 ++---- hw/microblaze/petalogix_ml605_mmu.c | 2 +- hw/misc/arm_sysctl.c | 6 ++--- hw/misc/aspeed_i3c.c | 6 ++--- hw/nios2/10m50_devboard.c | 4 +-- hw/nvme/ns.c | 4 +-- hw/ppc/pnv_psi.c | 5 ++-- hw/ppc/spapr.c | 42 +++++++++++++++++--------------- hw/ppc/spapr_drc.c | 12 ++++----- hw/ppc/spapr_pci.c | 6 ++--- hw/riscv/opentitan.c | 2 +- hw/smbios/smbios.c | 37 ++++++++++++++-------------- hw/timer/aspeed_timer.c | 2 +- linux-user/strace.c | 1 - migration/block.c | 4 +-- migration/ram.c | 8 +++--- migration/rdma.c | 14 +++++++---- migration/vmstate.c | 2 +- net/eth.c | 2 -- qemu-nbd.c | 9 +++---- softmmu/device_tree.c | 6 ++--- softmmu/memory.c | 1 - softmmu/physmem.c | 10 ++++---- softmmu/qemu-seccomp.c | 4 +-- target/arm/hvf/hvf.c | 8 +++--- target/arm/tcg/mve_helper.c | 16 ++++++------ target/arm/tcg/translate-m-nocp.c | 2 +- target/m68k/translate.c | 2 +- target/mips/tcg/msa_helper.c | 8 +++--- target/mips/tcg/translate.c | 8 +++--- target/riscv/cpu.c | 4 +-- target/riscv/vector_helper.c | 7 +++--- target/tricore/translate.c | 6 ++--- tcg/tcg.c | 16 ++++++------ tests/unit/test-throttle.c | 2 +- ui/gtk.c | 14 +++++------ ui/spice-display.c | 9 ++++--- ui/vnc-palette.c | 2 -- ui/vnc.c | 12 ++++----- util/vhost-user-server.c | 2 +- crypto/cipher-gnutls.c.inc | 4 +-- target/mips/tcg/nanomips_translate.c.inc | 6 ++--- ui/vnc-enc-zrle.c.inc | 9 +++---- 74 files changed, 326 insertions(+), 331 deletions(-)
Signature · 1 line
2.41.0
[PULL 01/56] migration/rdma: Fix save_page method to fail on polling error
qemu_rdma_save_page() reports polling error with error_report(), then succeeds anyway. This is because the variable holding the polling status *shadows* the variable the function returns. The latter remains zero.
Broken since day one, and duplicated more recently.
Message-ID: <[email protected]>
--- migration/rdma.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
migration/rdma.c +4 -2
@@ -3282,7 +3282,8 @@ static size_t qemu_rdma_save_page(QEMUFile *f,*/ while (1 ) {uint64_t wr_id, wr_id_in; -int ret =qemu_rdma_poll (rdma, rdma->recv_cq, &wr_id_in,NULL ); + ret =qemu_rdma_poll (rdma, rdma->recv_cq, &wr_id_in,NULL ); +if (ret <0 ) {error_report ("rdma migration: polling error! %d" , ret); goto err;
@@ -3297,7 +3298,8 @@ static size_t qemu_rdma_save_page(QEMUFile *f,while (1 ) {uint64_t wr_id, wr_id_in; -int ret =qemu_rdma_poll (rdma, rdma->send_cq, &wr_id_in,NULL ); + ret =qemu_rdma_poll (rdma, rdma->send_cq, &wr_id_in,NULL ); +if (ret <0 ) {error_report ("rdma migration: polling error! %d" , ret); goto err;
Signature · 1 line
2.41.0
[PULL 08/56] tcg: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
tcg/tcg.c:2551:27: error: declaration shadows a local variable [-Werror,-Wshadow]
MemOp op = get_memop(oi);
^
tcg/tcg.c:2437:12: note: previous declaration is here
TCGOp *op;
^
accel/tcg/tb-maint.c:245:18: error: declaration shadows a local variable [-Werror,-Wshadow]
for (int i = 0; i < V_L2_SIZE; i++) {
^
accel/tcg/tb-maint.c:210:9: note: previous declaration is here
int i;
^Message-ID: <[email protected]>
--- accel/tcg/tb-maint.c | 3 +-- tcg/tcg.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-)
accel/tcg/tb-maint.c +1 -2
@@ -207,13 +207,12 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, bool alloc) {PageDesc *pd;void **lp; -int i;/* Level 1. Always allocated. */ lp = l1_map + ((index >> v_l1_shift) & (v_l1_size -1 ));/* Level 2..N-1. */ -for (i = v_l2_levels; i >0 ; i--) { +for (int i = v_l2_levels; i >0 ; i--) {void **p =qatomic_rcu_read (lp);if (p ==NULL ) {
tcg/tcg.c +8 -8
@@ -2549,21 +2549,21 @@ static void tcg_dump_ops(TCGContext *s, FILE *f, bool have_prefs) {const char *s_al, *s_op, *s_at;MemOpIdx oi = op->args[k++]; -MemOp op =get_memop (oi); +MemOp mop =get_memop (oi);unsigned ix =get_mmuidx (oi); - s_al = alignment_name[(op &MO_AMASK ) >>MO_ASHIFT ]; - s_op = ldst_name[op & (MO_BSWAP |MO_SSIZE )]; - s_at = atom_name[(op &MO_ATOM_MASK ) >>MO_ATOM_SHIFT ]; - op &= ~(MO_AMASK |MO_BSWAP |MO_SSIZE |MO_ATOM_MASK ); + s_al = alignment_name[(mop &MO_AMASK ) >>MO_ASHIFT ]; + s_op = ldst_name[mop & (MO_BSWAP |MO_SSIZE )]; + s_at = atom_name[(mop &MO_ATOM_MASK ) >>MO_ATOM_SHIFT ]; + mop &= ~(MO_AMASK |MO_BSWAP |MO_SSIZE |MO_ATOM_MASK );/* If all fields are accounted for, print symbolically. */ -if (!op && s_al && s_op && s_at) { +if (!mop && s_al && s_op && s_at) { col +=ne_fprintf (f,",%s%s%s,%u" , s_at, s_al, s_op, ix); }else { - op =get_memop (oi); - col +=ne_fprintf (f,",$0x%x,%u" , op, ix); + mop =get_memop (oi); + col +=ne_fprintf (f,",$0x%x,%u" , mop, ix); } i =1 ; }
Signature · 1 line
2.41.0
[PULL 03/56] ui: Clean up local variable shadowing
In reply to Markus ArmbrusterLocal variables shadowing other local variables or parameters make the code needlessly hard to understand. Tracked down with -Wshadow=local. Clean up: delete inner declarations when they are actually redundant, else rename variables.
Message-ID: <[email protected]>
--- ui/gtk.c | 14 +++++++------- ui/spice-display.c | 9 +++++---- ui/vnc-palette.c | 2 -- ui/vnc.c | 12 ++++++------ ui/vnc-enc-zrle.c.inc | 9 ++++----- 5 files changed, 22 insertions(+), 24 deletions(-)
ui/gtk.c +7 -7
@@ -930,8 +930,8 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,GdkMonitor *monitor =gdk_display_get_monitor_at_window (dpy, win);GdkRectangle geometry; -int x = (int )motion->x_root; -int y = (int )motion->y_root; +int xr = (int )motion->x_root; +int yr = (int )motion->y_root;gdk_monitor_get_geometry (monitor, &geometry);
@@ -942,13 +942,13 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,* may still be only half way across the screen. Without * this warp, the server pointer would thus appear to hit * an invisible wall */ -if (x <= geometry.x || x - geometry.x >= geometry.width -1 || - y <= geometry.y || y - geometry.y >= geometry.height -1 ) { +if (xr <= geometry.x || xr - geometry.x >= geometry.width -1 || + yr <= geometry.y || yr - geometry.y >= geometry.height -1 ) {GdkDevice *dev =gdk_event_get_device ((GdkEvent *)motion); - x = geometry.x + geometry.width /2 ; - y = geometry.y + geometry.height /2 ; + xr = geometry.x + geometry.width /2 ; + yr = geometry.y + geometry.height /2 ; -gdk_device_warp (dev, screen, x, y); +gdk_device_warp (dev, screen, xr, yr); s->last_set = FALSE;return FALSE; }
ui/spice-display.c +5 -4
@@ -1081,15 +1081,16 @@ static void qemu_spice_gl_update(DisplayChangeListener *dcl, }if (render_cursor) { -int x, y; +int ptr_x, ptr_y; +qemu_mutex_lock (&ssd->lock); - x = ssd->ptr_x; - y = ssd->ptr_y; + ptr_x = ssd->ptr_x; + ptr_y = ssd->ptr_y;qemu_mutex_unlock (&ssd->lock);egl_texture_blit (ssd->gls, &ssd->blit_fb, &ssd->guest_fb, !y_0_top);egl_texture_blend (ssd->gls, &ssd->blit_fb, &ssd->cursor_fb, - !y_0_top, x, y,1.0 ,1.0 ); + !y_0_top, ptr_x, ptr_y,1.0 ,1.0 );glFlush (); }
ui/vnc-palette.c +0 -2
@@ -86,8 +86,6 @@ int palette_put(VncPalette *palette, uint32_t color)return 0 ; }if (!entry) { -VncPaletteEntry *entry; - entry = &palette->pool[palette->size]; entry->color = color; entry->idx = idx;
ui/vnc.c +6 -6
@@ -1584,15 +1584,15 @@ static void vnc_jobs_bh(void *opaque)*/ static int vnc_client_read (VncState *vs) { -size_t ret; +size_t sz;#ifdef CONFIG_VNC_SASL if (vs->sasl.conn && vs->sasl.runSSF) - ret =vnc_client_read_sasl (vs); + sz =vnc_client_read_sasl (vs); else#endif /* CONFIG_VNC_SASL */ - ret =vnc_client_read_plain (vs); -if (!ret) { + sz =vnc_client_read_plain (vs); +if (!sz) {if (vs->disconnecting) {vnc_disconnect_finish (vs);return -1 ;
@@ -3118,8 +3118,8 @@ static int vnc_refresh_server_surface(VncDisplay *vd) cmp_bytes =MIN (VNC_DIRTY_PIXELS_PER_BIT *VNC_SERVER_FB_BYTES , server_stride);if (vd->guest.format !=VNC_SERVER_FB_FORMAT ) { -int width =pixman_image_get_width (vd->server); - tmpbuf =qemu_pixman_linebuf_create (VNC_SERVER_FB_FORMAT , width); +int w =pixman_image_get_width (vd->server); + tmpbuf =qemu_pixman_linebuf_create (VNC_SERVER_FB_FORMAT , w); }else {int guest_bpp =PIXMAN_FORMAT_BPP (pixman_image_get_format (vd->guest.fb));
ui/vnc-enc-zrle.c.inc +4 -5
@@ -153,11 +153,12 @@ static void ZRLE_ENCODE_TILE(VncState *vs, ZRLE_PIXEL *data, int w, int h, } if (use_rle) { - ZRLE_PIXEL *ptr = data; - ZRLE_PIXEL *end = ptr + w * h; ZRLE_PIXEL *run_start; ZRLE_PIXEL pix; + ptr = data; + end = ptr + w * h; + while (ptr < end) { int len; int index = 0;
@@ -198,7 +199,7 @@ static void ZRLE_ENCODE_TILE(VncState *vs, ZRLE_PIXEL *data, int w, int h, } } else if (use_palette) { /* no RLE */ int bppp; - ZRLE_PIXEL *ptr = data; + ptr = data; /* packed pixels */
@@ -241,8 +242,6 @@ static void ZRLE_ENCODE_TILE(VncState *vs, ZRLE_PIXEL *data, int w, int h, #endif { #ifdef ZRLE_COMPACT_PIXEL - ZRLE_PIXEL *ptr; - for (ptr = data; ptr < data + w * h; ptr++) { ZRLE_WRITE_PIXEL(vs, *ptr); }
Signature · 1 line
2.41.0
[PULL 10/56] target/arm/hvf: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Per Peter Maydell analysis [*]:
The hvf_vcpu_exec() function is not documented, but in practice its caller expects it to return either EXCP_DEBUG (for "this was a guest debug exception you need to deal with") or something else (presumably the intention being 0 for OK).
The hvf_sysreg_read() and hvf_sysreg_write() functions are also not documented, but they return 0 on success, or 1 for a completely unrecognized sysreg where we've raised the UNDEF exception (but not if we raised an UNDEF exception for an unrecognized GIC sysreg -- I think this is a bug). We use this return value to decide whether we need to advance the PC past the insn or not. It's not the same as the return value we want to return from hvf_vcpu_exec().
Retain the variable as locally scoped but give it a name that doesn't clash with the other function-scoped variable.
This fixes:
target/arm/hvf/hvf.c:1936:13: error: declaration shadows a local variable [-Werror,-Wshadow]
int ret = 0;
^
target/arm/hvf/hvf.c:1807:9: note: previous declaration is here
int ret;
^Message-ID: <[email protected]>
--- target/arm/hvf/hvf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
target/arm/hvf/hvf.c +4 -4
@@ -1934,16 +1934,16 @@ int hvf_vcpu_exec(CPUState *cpu)uint32_t rt = (syndrome >>5 ) &0x1f ;uint32_t reg = syndrome &SYSREG_MASK ;uint64_t val; -int ret =0 ; +int sysreg_ret =0 ;if (isread) { - ret =hvf_sysreg_read (cpu, reg, rt); + sysreg_ret =hvf_sysreg_read (cpu, reg, rt); }else { val =hvf_get_reg (cpu, rt); - ret =hvf_sysreg_write (cpu, reg, val); + sysreg_ret =hvf_sysreg_write (cpu, reg, val); } - advance_pc = !ret; + advance_pc = !sysreg_ret;break ; }case EC_WFX_TRAP :
Signature · 1 line
2.41.0
[PULL 12/56] target/m68k: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
target/m68k/translate.c:828:18: error: declaration shadows a local variable [-Werror,-Wshadow]
TCGv tmp = tcg_temp_new();
^
target/m68k/translate.c:801:15: note: previous declaration is here
TCGv reg, tmp, result;
^Message-ID: <[email protected]>
--- target/m68k/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/m68k/translate.c +1 -1
@@ -824,7 +824,7 @@ static TCGv gen_ea_mode(CPUM68KState *env, DisasContext *s, int mode, int reg0, reg =get_areg (s, reg0); result =gen_ldst (s, opsize, reg, val, what, index);if (what ==EA_STORE || !addrp) { -TCGv tmp =tcg_temp_new (); + tmp =tcg_temp_new ();if (reg0 ==7 && opsize ==OS_BYTE &&m68k_feature (s->env,M68K_FEATURE_M68K )) {tcg_gen_addi_i32 (tmp, reg,2 );
Signature · 1 line
2.41.0
[PULL 19/56] hw/nios2: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
hw/nios2/10m50_devboard.c: In function ‘nios2_10m50_ghrd_init’:
hw/nios2/10m50_devboard.c:101:22: warning: declaration of ‘dev’ shadows a previous local [-Wshadow=compatible-local]
101 | DeviceState *dev = qdev_new(TYPE_NIOS2_VIC);
| ^~~
hw/nios2/10m50_devboard.c:60:18: note: shadowed declaration is here
60 | DeviceState *dev;
| ^~~ hw/nios2/10m50_devboard.c:110:18: warning: declaration of ‘i’ shadows a previous local [-Wshadow=compatible-local]
110 | for (int i = 0; i < 32; i++) {
| ^
hw/nios2/10m50_devboard.c:67:9: note: shadowed declaration is here
67 | int i;
| ^Message-ID: <[email protected]>
--- hw/nios2/10m50_devboard.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/nios2/10m50_devboard.c +2 -2
@@ -98,7 +98,7 @@ static void nios2_10m50_ghrd_init(MachineState *machine)qdev_realize_and_unref (DEVICE (cpu),NULL , &error_fatal);if (nms->vic) { -DeviceState *dev =qdev_new (TYPE_NIOS2_VIC ); + dev =qdev_new (TYPE_NIOS2_VIC );MemoryRegion *dev_mr;qemu_irq cpu_irq;
@@ -107,7 +107,7 @@ static void nios2_10m50_ghrd_init(MachineState *machine) cpu_irq =qdev_get_gpio_in_named (DEVICE (cpu),"EIC" ,0 );sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , cpu_irq); -for (int i =0 ; i <32 ; i++) { +for (i =0 ; i <32 ; i++) { irq[i] =qdev_get_gpio_in (dev, i); }
Signature · 1 line
2.41.0
[PULL 31/56] spapr: Clean up local variable shadowing in spapr_dt_cpus()
In reply to Markus ArmbrusterFrom: Cédric Le Goater <[email protected]>
Introduce a helper routine defining one CPU device node to fix this warning :
../hw/ppc/spapr.c: In function ‘spapr_dt_cpus’:
../hw/ppc/spapr.c:812:19: warning: declaration of ‘cs’ shadows a previous local [-Wshadow=compatible-local]
812 | CPUState *cs = rev[i];
| ^~
../hw/ppc/spapr.c:786:15: note: shadowed declaration is here
786 | CPUState *cs;
| ^~Message-ID: <[email protected]>
--- hw/ppc/spapr.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-)
hw/ppc/spapr.c +21 -15
@@ -780,6 +780,26 @@ static void spapr_dt_cpu(CPUState *cs, void *fdt, int offset, pcc->lrg_decr_bits))); } +static void spapr_dt_one_cpu (void *fdt,SpaprMachineState *spapr,CPUState *cs, +int cpus_offset) +{ +PowerPCCPU *cpu =POWERPC_CPU (cs); +int index =spapr_get_vcpu_id (cpu); +DeviceClass *dc =DEVICE_GET_CLASS (cs); + g_autofree char *nodename = NULL; +int offset; + +if (!spapr_is_thread0_in_vcore (spapr, cpu)) { +return ; + } + + nodename =g_strdup_printf ("%s@%x" , dc->fw_name, index); + offset =fdt_add_subnode (fdt, cpus_offset, nodename); +_FDT (offset); +spapr_dt_cpu (cs, fdt, offset, spapr); +} + +static void spapr_dt_cpus (void *fdt,SpaprMachineState *spapr) {CPUState **rev;
@@ -809,21 +829,7 @@ static void spapr_dt_cpus(void *fdt, SpaprMachineState *spapr) }for (i = n_cpus -1 ; i >=0 ; i--) { -CPUState *cs = rev[i]; -PowerPCCPU *cpu =POWERPC_CPU (cs); -int index =spapr_get_vcpu_id (cpu); -DeviceClass *dc =DEVICE_GET_CLASS (cs); - g_autofree char *nodename = NULL; -int offset; - -if (!spapr_is_thread0_in_vcore (spapr, cpu)) { -continue ; - } - - nodename =g_strdup_printf ("%s@%x" , dc->fw_name, index); - offset =fdt_add_subnode (fdt, cpus_offset, nodename); -_FDT (offset); -spapr_dt_cpu (cs, fdt, offset, spapr); +spapr_dt_one_cpu (fdt, spapr, rev[i], cpus_offset); }g_free (rev);
Signature · 1 line
2.41.0
[PULL 49/56] seccomp: avoid shadowing of 'action' variable
In reply to Markus ArmbrusterFrom: Daniel P. Berrangé <[email protected]>
This is confusing as one 'action' variable is used for storing a SCMP_ enum value, while the other 'action' variable is used for storing a SECCOMP_ enum value.
Message-ID: <[email protected]>
--- softmmu/qemu-seccomp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
softmmu/qemu-seccomp.c +2 -2
@@ -283,9 +283,9 @@ static uint32_t qemu_seccomp_update_action(uint32_t action)if (action ==SCMP_ACT_TRAP ) {static int kill_process =-1 ;if (kill_process ==-1 ) { -uint32_t action =SECCOMP_RET_KILL_PROCESS ; +uint32_t testaction =SECCOMP_RET_KILL_PROCESS ; -if (qemu_seccomp (SECCOMP_GET_ACTION_AVAIL ,0 , &action) ==0 ) { +if (qemu_seccomp (SECCOMP_GET_ACTION_AVAIL ,0 , &testaction) ==0 ) { kill_process =1 ; }else { kill_process =0 ;
Signature · 1 line
2.41.0
[PULL 37/56] test-throttle: don't shadow 'index' variable in do_test_accounting()
In reply to Markus ArmbrusterFrom: Alberto Garcia <[email protected]>
Fixes build with -Wshadow=local
Message-ID: <[email protected]>
--- tests/unit/test-throttle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/unit/test-throttle.c +1 -1
@@ -625,7 +625,7 @@ static bool do_test_accounting(bool is_ops, /* are we testing bps or ops */throttle_config_init (&cfg);for (i =0 ; i <3 ; i++) { -BucketType index = to_test[is_ops][i]; + index = to_test[is_ops][i]; cfg.buckets[index].avg = avg; }
Signature · 1 line
2.41.0
[PULL 39/56] hw/intc/arm_gicv3_its: Avoid shadowing variable in do_process_its_cmd()
In reply to Markus ArmbrusterFrom: Peter Maydell <[email protected]>
Avoid shadowing a local variable in do_process_its_cmd():
../../hw/intc/arm_gicv3_its.c:548:17: warning: declaration of ‘ite’ shadows a previous local [-Wshadow=compatible-local]
548 | ITEntry ite = {};
| ^~~../../hw/intc/arm_gicv3_its.c:518:13: note: shadowed declaration is here
518 | ITEntry ite;
| ^~~
Message-ID: <[email protected]>
--- hw/intc/arm_gicv3_its.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/intc/arm_gicv3_its.c +3 -3
@@ -545,10 +545,10 @@ static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, }if (cmdres ==CMD_CONTINUE_OK && cmd ==DISCARD ) { -ITEntry ite = {}; +ITEntry i = {};/* remove mapping from interrupt translation table */ - ite.valid = false; -return update_ite (s, eventid, &dte, &ite) ?CMD_CONTINUE_OK :CMD_STALL ; + i.valid = false; +return update_ite (s, eventid, &dte, &i) ?CMD_CONTINUE_OK :CMD_STALL ; }return CMD_CONTINUE_OK ; }
Signature · 1 line
2.41.0
[PULL 25/56] softmmu/memory: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
softmmu/memory.c: In function ‘mtree_print_mr’:
softmmu/memory.c:3236:27: warning: declaration of ‘ml’ shadows a previous local [-Wshadow=compatible-local]
3236 | MemoryRegionList *ml;
| ^~
softmmu/memory.c:3213:32: note: shadowed declaration is here
3213 | MemoryRegionList *new_ml, *ml, *next_ml;
| ^~
Message-ID: <[email protected]>
--- softmmu/memory.c | 1 - 1 file changed, 1 deletion(-)
softmmu/memory.c +0 -1
@@ -3245,7 +3245,6 @@ static void mtree_print_mr(const MemoryRegion *mr, unsigned int level, }if (mr->alias) { -MemoryRegionList *ml;bool found = false;/* check if the alias is already in the queue */
Signature · 1 line
2.41.0
[PULL 24/56] sysemu/device_tree: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
hw/mips/boston.c:472:5: error: declaration shadows a local variable [-Werror,-Wshadow]
qemu_fdt_setprop_cells(fdt, name, "reg", reg_base, reg_size);
^
include/sysemu/device_tree.h:129:13: note: expanded from macro 'qemu_fdt_setprop_cells'
int i;
^
hw/mips/boston.c:461:9: note: previous declaration is here
int i;
^Message-ID: <[email protected]>
--- include/sysemu/device_tree.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
include/sysemu/device_tree.h +2 -4
@@ -126,10 +126,8 @@ int qemu_fdt_add_path(void *fdt, const char *path);#define qemu_fdt_setprop_cells (fdt, node_path, property, ...) \ do { \ uint32_t qdt_tmp[] = { __VA_ARGS__ }; \ - int i; \ - \ - for (i = 0; i < ARRAY_SIZE(qdt_tmp); i++) { \ - qdt_tmp[i] = cpu_to_be32(qdt_tmp[i]); \ + for (unsigned i_ = 0; i_ < ARRAY_SIZE(qdt_tmp); i_++) { \ + qdt_tmp[i_] = cpu_to_be32(qdt_tmp[i_]); \ } \ qemu_fdt_setprop(fdt, node_path, property, qdt_tmp, \ sizeof(qdt_tmp)); \
Signature · 1 line
2.41.0
[PULL 09/56] target/arm/tcg: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
target/arm/tcg/translate-m-nocp.c: In function ‘gen_M_fp_sysreg_read’:
target/arm/tcg/translate-m-nocp.c:509:18: warning: declaration of ‘tmp’ shadows a previous local [-Wshadow=compatible-local]
509 | TCGv_i32 tmp = load_cpu_field(v7m.fpdscr[M_REG_NS]);
| ^~~
target/arm/tcg/translate-m-nocp.c:433:14: note: shadowed declaration is here
433 | TCGv_i32 tmp;
| ^~~
--- target/arm/tcg/mve_helper.c: In function ‘helper_mve_vqshlsb’:
target/arm/tcg/mve_helper.c:1259:19: warning: declaration of ‘r’ shadows a previous local [-Wshadow=compatible-local]
1259 | typeof(N) r = FN(N, (int8_t)(M), sizeof(N) * 8, ROUND, &su32); \
| ^
target/arm/tcg/mve_helper.c:1267:5: note: in expansion of macro ‘WRAP_QRSHL_HELPER’
1267 | WRAP_QRSHL_HELPER(do_sqrshl_bhs, N, M, false, satp)
| ^~~~~~~~~~~~~~~~~
target/arm/tcg/mve_helper.c:927:22: note: in expansion of macro ‘DO_SQSHL_OP’
927 | TYPE r = FN(n[H##ESIZE(e)], m[H##ESIZE(e)], &sat); \
| ^~
target/arm/tcg/mve_helper.c:945:5: note: in expansion of macro ‘DO_2OP_SAT’
945 | DO_2OP_SAT(OP##b, 1, int8_t, FN) \
| ^~~~~~~~~~
target/arm/tcg/mve_helper.c:1277:1: note: in expansion of macro ‘DO_2OP_SAT_S’
1277 | DO_2OP_SAT_S(vqshls, DO_SQSHL_OP)
| ^~~~~~~~~~~~
--- target/arm/tcg/mve_helper.c: In function ‘do_sqrshl48_d’:
target/arm/tcg/mve_helper.c:2463:17: warning: declaration of ‘extval’ shadows a previous local [-Wshadow=compatible-local]
2463 | int64_t extval = sextract64(src << shift, 0, 48);
| ^~~~~~
target/arm/tcg/mve_helper.c:2443:18: note: shadowed declaration is here
2443 | int64_t val, extval;
| ^~~~~~
--- target/arm/tcg/mve_helper.c: In function ‘do_uqrshl48_d’:
target/arm/tcg/mve_helper.c:2495:18: warning: declaration of ‘extval’ shadows a previous local [-Wshadow=compatible-local]
2495 | uint64_t extval = extract64(src << shift, 0, 48);
| ^~~~~~
target/arm/tcg/mve_helper.c:2479:19: note: shadowed declaration is here
2479 | uint64_t val, extval;
| ^~~~~~Message-ID: <[email protected]>
--- target/arm/tcg/mve_helper.c | 16 ++++++++-------- target/arm/tcg/translate-m-nocp.c | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-)
target/arm/tcg/mve_helper.c +8 -8
@@ -925,8 +925,8 @@ DO_1OP_IMM(vorri, DO_ORRI)bool qc = false; \for (e =0 ; e <16 /ESIZE ; e++, mask >>=ESIZE ) { \bool sat = false; \ - TYPE r = FN(n[H##ESIZE(e)], m[H##ESIZE(e)], &sat); \ - mergemask(&d[H##ESIZE(e)], r, mask); \ + TYPE r_ = FN(n[H##ESIZE(e)], m[H##ESIZE(e)], &sat); \ + mergemask(&d[H##ESIZE(e)], r_, mask); \ qc |= sat & mask & 1; \ } \ if (qc) { \
@@ -1250,11 +1250,11 @@ DO_2OP_SAT(vqsubsw, 4, int32_t, DO_SQSUB_W)#define WRAP_QRSHL_HELPER (FN ,N ,M ,ROUND , satp) \ ({ \ uint32_t su32 = 0; \ - typeof(N) r = FN(N, (int8_t)(M), sizeof(N) * 8, ROUND, &su32); \ + typeof(N) qrshl_ret = FN(N, (int8_t)(M), sizeof(N) * 8, ROUND, &su32); \ if (su32) { \ *satp = true; \ } \ - r; \ + qrshl_ret; \ })#define DO_SQSHL_OP (N ,M , satp) \
@@ -1292,12 +1292,12 @@ DO_2OP_SAT_U(vqrshlu, DO_UQRSHL_OP) for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) { \ bool sat = false; \ if ((e & 1) == XCHG) { \ - TYPE r = FN(n[H##ESIZE(e)], \ + TYPE vqdmladh_ret = FN(n[H##ESIZE(e)], \ m[H##ESIZE(e - XCHG)], \ n[H##ESIZE(e + (1 - 2 * XCHG))], \ m[H##ESIZE(e + (1 - XCHG))], \ ROUND, &sat); \ - mergemask(&d[H##ESIZE(e)], r, mask); \ + mergemask(&d[H##ESIZE(e)], vqdmladh_ret, mask); \ qc |= sat & mask & 1; \ } \ } \
@@ -2454,7 +2454,7 @@ static inline int64_t do_sqrshl48_d(int64_t src, int64_t shift,return extval; } }else if (shift <48 ) { -int64_t extval =sextract64 (src << shift,0 ,48 ); + extval =sextract64 (src << shift,0 ,48 );if (!sat || src == (extval >> shift)) {return extval; }
@@ -2486,7 +2486,7 @@ static inline uint64_t do_uqrshl48_d(uint64_t src, int64_t shift,return extval; } }else if (shift <48 ) { -uint64_t extval =extract64 (src << shift,0 ,48 ); + extval =extract64 (src << shift,0 ,48 );if (!sat || src == (extval >> shift)) {return extval; }
target/arm/tcg/translate-m-nocp.c +1 -1
@@ -506,7 +506,7 @@ static bool gen_M_fp_sysreg_read(DisasContext *s, int regno,gen_branch_fpInactive (s,TCG_COND_EQ , lab_active);/* fpInactive case: reads as FPDSCR_NS */ -TCGv_i32 tmp =load_cpu_field (v7m.fpdscr[M_REG_NS ]); + tmp =load_cpu_field (v7m.fpdscr[M_REG_NS ]);storefn (s, opaque, tmp, true); lab_end =gen_new_label ();tcg_gen_br (lab_end);
Signature · 1 line
2.41.0
[PULL 17/56] hw/m68k: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
hw/m68k/virt.c:263:13: error: declaration shadows a local variable [-Werror,-Wshadow]
BOOTINFOSTR(param_ptr, BI_COMMAND_LINE,
^
hw/m68k/bootinfo.h:47:13: note: expanded from macro 'BOOTINFOSTR'
int i; \
^
hw/m68k/virt.c:130:9: note: previous declaration is here
int i;
^Message-ID: <[email protected]>
--- hw/m68k/bootinfo.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
hw/m68k/bootinfo.h +4 -6
@@ -44,15 +44,14 @@#define BOOTINFOSTR (base, id, string) \ do { \ - int i; \ stw_p(base, id); \ base += 2; \ stw_p(base, \ (sizeof(struct bi_record) + strlen(string) + \ 1 /* null termination */ + 3 /* padding */) & ~3); \ base +=2 ; \ -for (i =0 ; string[i]; i++) { \ -stb_p (base++, string[i]); \ +for (unsigned i_ =0 ; string[i_]; i_++) { \ +stb_p (base++, string[i_]); \ } \stb_p (base++,0 ); \ base =QEMU_ALIGN_PTR_UP (base,4 ); \
@@ -60,7 +59,6 @@#define BOOTINFODATA (base, id, data, len) \ do { \ - int i; \ stw_p(base, id); \ base += 2; \ stw_p(base, \
@@ -69,8 +67,8 @@ base +=2 ; \stw_p (base, len); \ base +=2 ; \ -for (i =0 ; i < len; ++i) { \ -stb_p (base++, data[i]); \ +for (unsigned i_ =0 ; i_ < len; ++i_) { \ +stb_p (base++, data[i_]); \ } \ base =QEMU_ALIGN_PTR_UP (base,4 ); \ }while (0 )
Signature · 1 line
2.41.0
[PULL 47/56] intel_iommu: Fix shadow local variables on "size"
In reply to Markus ArmbrusterFrom: Peter Xu <[email protected]>
This patch fixes the warning of shadowed local variable:
../hw/i386/intel_iommu.c: In function ‘vtd_address_space_unmap’:../hw/i386/intel_iommu.c:3773:18: warning: declaration of ‘size’ shadows a previous local [-Wshadow=compatible-local]
3773 | uint64_t size = mask + 1;
| ^~~~../hw/i386/intel_iommu.c:3747:12: note: shadowed declaration is here
3747 | hwaddr size, remain;
| ^~~~Message-ID: <[email protected]>
--- hw/i386/intel_iommu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
hw/i386/intel_iommu.c +4 -4
@@ -3744,7 +3744,7 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, PCIBus *bus,/* Unmap the whole range in the notifier's scope. */ static void vtd_address_space_unmap (VTDAddressSpace *as,IOMMUNotifier *n) { -hwaddr size, remain; +hwaddr total, remain;hwaddr start = n->start;hwaddr end = n->end;IntelIOMMUState *s = as->iommu_state;
@@ -3765,7 +3765,7 @@ static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n) }assert (start <= end); - size = remain = end - start +1 ; + total = remain = end - start +1 ;while (remain >=VTD_PAGE_SIZE ) {IOMMUTLBEvent event;
@@ -3793,10 +3793,10 @@ static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n)trace_vtd_as_unmap_whole (pci_bus_num (as->bus),VTD_PCI_SLOT (as->devfn),VTD_PCI_FUNC (as->devfn), - n->start, size); + n->start, total); map.iova = n->start; - map.size = size -1 ;/* Inclusive */ + map.size = total -1 ;/* Inclusive */ iova_tree_remove (as->iova_tree, map); }
Signature · 1 line
2.41.0
[PULL 02/56] migration: Clean up local variable shadowing
In reply to Markus ArmbrusterLocal variables shadowing other local variables or parameters make the code needlessly hard to understand. Tracked down with -Wshadow=local. Clean up: delete inner declarations when they are actually redundant, else rename variables.
Message-ID: <[email protected]>
--- migration/block.c | 4 ++-- migration/ram.c | 8 +++----- migration/rdma.c | 8 +++++--- migration/vmstate.c | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-)
migration/block.c +2 -2
@@ -440,8 +440,8 @@ static int init_blk_migration(QEMUFile *f)/* Can only insert new BDSes now because doing so while iterating block * devices may end up in a deadlock (iterating the new BDSes, too). */ for (i =0 ; i < num_bs; i++) { -BlkMigDevState *bmds = bmds_bs[i].bmds; -BlockDriverState *bs = bmds_bs[i].bs; + bmds = bmds_bs[i].bmds; + bs = bmds_bs[i].bs;if (bmds) { ret =blk_insert_bs (bmds->blk, bs, &local_err);
migration/ram.c +3 -5
@@ -3517,8 +3517,6 @@ int colo_init_ram_cache(void)* we use the same name 'ram_bitmap' as for migration. */ if (ram_bytes_total ()) { -RAMBlock *block; -RAMBLOCK_FOREACH_NOT_IGNORED (block) {unsigned long pages = block->max_length >>TARGET_PAGE_BITS ; block->bmap =bitmap_new (pages);
@@ -3998,12 +3996,12 @@ static int ram_load_precopy(QEMUFile *f) } }if (migrate_ignore_shared ()) { -hwaddr addr =qemu_get_be64 (f); +hwaddr addr2 =qemu_get_be64 (f);if (migrate_ram_is_ignored (block) && - block->mr->addr != addr) { + block->mr->addr != addr2) {error_report ("Mismatched GPAs for block %s " "%" PRId64"!= %" PRId64, - id, (uint64_t )addr, + id, (uint64_t )addr2, (uint64_t )block->mr->addr); ret = -EINVAL ; }
migration/rdma.c +5 -3
@@ -1902,9 +1902,11 @@ static int qemu_rdma_exchange_send(RDMAContext *rdma, RDMAControlHeader *head,* by waiting for a READY message. */ if (rdma->control_ready_expected) { -RDMAControlHeader resp; - ret =qemu_rdma_exchange_get_response (rdma, - &resp,RDMA_CONTROL_READY ,RDMA_WRID_READY ); +RDMAControlHeader resp_ignored; + + ret =qemu_rdma_exchange_get_response (rdma, &resp_ignored, +RDMA_CONTROL_READY , +RDMA_WRID_READY );if (ret <0 ) {return ret; }
migration/vmstate.c +1 -1
@@ -97,7 +97,7 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,return -EINVAL ; }if (vmsd->pre_load) { -int ret = vmsd->pre_load (opaque); + ret = vmsd->pre_load (opaque);if (ret) {return ret; }
Signature · 1 line
2.41.0
[PULL 15/56] hw/arm/virt: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
hw/arm/virt.c:821:22: error: declaration shadows a local variable [-Werror,-Wshadow]
qemu_irq irq = qdev_get_gpio_in(vms->gic,
^
hw/arm/virt.c:803:13: note: previous declaration is here
int irq;
^Message-ID: <[email protected]>
--- hw/arm/virt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/arm/virt.c +1 -2
@@ -801,7 +801,6 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem)for (i =0 ; i < smp_cpus; i++) {DeviceState *cpudev =DEVICE (qemu_get_cpu (i));int ppibase =NUM_IRQS + i *GIC_INTERNAL +GIC_NR_SGIS ; -int irq;/* Mapping from the output timer irq lines from the CPU to the * GIC PPI inputs we use for the virt board. */
@@ -812,7 +811,7 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem) [GTIMER_SEC] = ARCH_TIMER_S_EL1_IRQ, }; -for (irq =0 ; irq <ARRAY_SIZE (timer_irq); irq++) { +for (unsigned irq =0 ; irq <ARRAY_SIZE (timer_irq); irq++) {qdev_connect_gpio_out (cpudev, irq,qdev_get_gpio_in (vms->gic, ppibase + timer_irq[irq]));
Signature · 1 line
2.41.0
[PULL 28/56] hw/intc/openpic: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
hw/intc/openpic.c: In function ‘openpic_gbl_write’:
hw/intc/openpic.c:614:17: warning: declaration of ‘idx’ shadows a previous local [-Wshadow=compatible-local]
614 | int idx;
| ^~~
hw/intc/openpic.c:568:9: note: shadowed declaration is here
568 | int idx;
| ^~~Message-ID: <[email protected]>
--- hw/intc/openpic.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
hw/intc/openpic.c +2 -5
@@ -610,11 +610,8 @@ static void openpic_gbl_write(void *opaque, hwaddr addr, uint64_t val,case 0x10B0 :case 0x10C0 :case 0x10D0 : - { -int idx; - idx = (addr -0x10A0 ) >>4 ; -write_IRQreg_ivpr (opp, opp->irq_ipi0 + idx, val); - } + idx = (addr -0x10A0 ) >>4 ; +write_IRQreg_ivpr (opp, opp->irq_ipi0 + idx, val);break ;case 0x10E0 :/* SPVE */ opp->spve = val & opp->vector_mask;
Signature · 1 line
2.41.0
[PULL 05/56] block/vdi: Clean up local variable shadowing
In reply to Markus ArmbrusterLocal variables shadowing other local variables or parameters make the code needlessly hard to understand. Tracked down with -Wshadow=local. Clean up: delete inner declarations when they are actually redundant, else rename variables.
Message-ID: <[email protected]>
--- block/vdi.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
block/vdi.c +3 -4
@@ -634,7 +634,6 @@ vdi_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, bmap_entry =le32_to_cpu (s->bmap[block_index]);if (!VDI_IS_ALLOCATED (bmap_entry)) {/* Allocate new block and write to it. */ -uint64_t data_offset;qemu_co_rwlock_upgrade (&s->bmap_lock); bmap_entry =le32_to_cpu (s->bmap[block_index]);if (VDI_IS_ALLOCATED (bmap_entry)) {
@@ -700,7 +699,7 @@ nonallocating_write:/* One or more new blocks were allocated. */ VdiHeader *header;uint8_t *base; -uint64_t offset; +uint64_t bmap_offset;uint32_t n_sectors;g_free (block);
@@ -723,11 +722,11 @@ nonallocating_write: bmap_first /= (SECTOR_SIZE /sizeof (uint32_t )); bmap_last /= (SECTOR_SIZE /sizeof (uint32_t )); n_sectors = bmap_last - bmap_first +1 ; - offset = s->bmap_sector + bmap_first; + bmap_offset = s->bmap_sector + bmap_first; base = ((uint8_t *)&s->bmap[0 ]) + bmap_first *SECTOR_SIZE ;logout ("will write %u block map sectors starting from entry %u\n" , n_sectors, bmap_first); - ret =bdrv_co_pwrite (bs->file, offset *SECTOR_SIZE , + ret =bdrv_co_pwrite (bs->file, bmap_offset *SECTOR_SIZE , n_sectors *SECTOR_SIZE , base,0 ); }
Signature · 1 line
2.41.0
[PULL 18/56] hw/microblaze: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
hw/microblaze/petalogix_ml605_mmu.c: In function ‘petalogix_ml605_init’:
hw/microblaze/petalogix_ml605_mmu.c:186:24: warning: declaration of ‘dinfo’ shadows a previous local [-Wshadow=compatible-local]
186 | DriveInfo *dinfo = drive_get(IF_MTD, 0, i);
| ^~~~~
hw/microblaze/petalogix_ml605_mmu.c:78:16: note: shadowed declaration is here
78 | DriveInfo *dinfo;
| ^~~~~Message-ID: <[email protected]>
--- hw/microblaze/petalogix_ml605_mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/microblaze/petalogix_ml605_mmu.c +1 -1
@@ -183,7 +183,7 @@ petalogix_ml605_init(MachineState *machine) spi = (SSIBus *)qdev_get_child_bus (dev,"spi" );for (i =0 ; i <NUM_SPI_FLASHES ; i++) { -DriveInfo *dinfo =drive_get (IF_MTD ,0 , i); + dinfo =drive_get (IF_MTD ,0 , i);qemu_irq cs_line; dev =qdev_new ("n25q128" );
Signature · 1 line
2.41.0
[PULL 07/56] qobject atomics osdep: Make a few macros more hygienic
In reply to Markus ArmbrusterVariables declared in macros can shadow other variables. Much of the time, this is harmless, e.g.:
#define _FDT(exp) \
do { \
int ret = (exp); \
if (ret < 0) { \
error_report("error creating device tree: %s: %s", \
#exp, fdt_strerror(ret)); \
exit(1); \
} \
} while (0)Harmless shadowing in h_client_architecture_support():
target_ulong ret;
[...]
ret = do_client_architecture_support(cpu, spapr, vec, fdt_bufsize);
if (ret == H_SUCCESS) {
_FDT((fdt_pack(spapr->fdt_blob)));
[...]
}
return ret;However, we can get in trouble when the shadowed variable is used in a macro argument:
#define QOBJECT(obj) ({ \
typeof(obj) o = (obj); \
o ? container_of(&(o)->base, QObject, base) : NULL; \
})QOBJECT(o) expands into
({---> typeof(o) o = (o);
o ? container_of(&(o)->base, QObject, base) : NULL;
})
Unintended variable name capture at --->. We'd be saved by -Winit-self. But I could certainly construct more elaborate death traps that don't trigger it.
To reduce the risk of trapping ourselves, we use variable names in macros that no sane person would use elsewhere. Here's our actual definition of QOBJECT():
#define QOBJECT(obj) ({ \
typeof(obj) _obj = (obj); \
_obj ? container_of(&(_obj)->base, QObject, base) : NULL; \
})Works well enough until we nest macro calls. For instance, with
#define qobject_ref(obj) ({ \
typeof(obj) _obj = (obj); \
qobject_ref_impl(QOBJECT(_obj)); \
_obj; \
})the expression qobject_ref(obj) expands into
({
typeof(obj) _obj = (obj);
qobject_ref_impl(
({
---> typeof(_obj) _obj = (_obj);
_obj ? container_of(&(_obj)->base, QObject, base) : NULL;
}));
_obj;
})Unintended variable name capture at --->.
The only reliable way to prevent unintended variable name capture is -Wshadow.
One blocker for enabling it is shadowing hiding in function-like macros like
qdict_put(dict, "name", qobject_ref(...))
qdict_put() wraps its last argument in QOBJECT(), and the last argument here contains another QOBJECT().
Use dark preprocessor sorcery to make the macros that give us this problem use different variable names on every call.
Message-ID: <[email protected]>
--- include/qapi/qmp/qobject.h | 10 ++++++++-- include/qemu/atomic.h | 17 ++++++++++++----- include/qemu/compiler.h | 3 +++ include/qemu/osdep.h | 27 ++++++++++++++++++++------- 4 files changed, 43 insertions(+), 14 deletions(-)
include/qapi/qmp/qobject.h +8 -2
@@ -45,10 +45,16 @@ struct QObject {struct QObjectBase_ base; }; -#define QOBJECT (obj) ({ \ +/* +* Preprocessor sorcery ahead: use a different identifier for the +* local variable in each expansion, so we can nest macro calls +* without shadowing variables. +*/ +#define QOBJECT_INTERNAL (obj, _obj) ({ \ typeof(obj) _obj = (obj); \ - _obj ? container_of(&(_obj)->base, QObject, base) : NULL; \ + _obj ? container_of(&_obj->base, QObject, base) : NULL; \ }) +#define QOBJECT (obj) QOBJECT_INTERNAL((obj), MAKE_IDENTFIER(_obj))/* Required for qobject_to() */ #define QTYPE_CAST_TO_QNull QTYPE_QNULL
include/qemu/atomic.h +12 -5
@@ -157,13 +157,20 @@smp_read_barrier_depends ();#endif -#define qatomic_rcu_read (ptr) \ - ({ \ +/* +* Preprocessor sorcery ahead: use a different identifier for the +* local variable in each expansion, so we can nest macro calls +* without shadowing variables. +*/ +#define qatomic_rcu_read_internal (ptr, _val) \ + ({ \ qemu_build_assert(sizeof(*ptr) <= ATOMIC_REG_SIZE); \ - typeof_strip_qual(*ptr) _val; \ - qatomic_rcu_read__nocheck(ptr, &_val); \ - _val; \ + typeof_strip_qual(*ptr) _val; \ + qatomic_rcu_read__nocheck(ptr, &_val); \ + _val; \ }) +#define qatomic_rcu_read (ptr) \ + qatomic_rcu_read_internal((ptr), MAKE_IDENTFIER(_val))#define qatomic_rcu_set (ptr, i) do { \ qemu_build_assert(sizeof(*ptr) <= ATOMIC_REG_SIZE); \
include/qemu/compiler.h +3 -0
@@ -37,6 +37,9 @@#define tostring (s) #s#endif +/* Expands into an identifier stemN, where N is another number each time */ +#define MAKE_IDENTFIER (stem) glue(stem, __COUNTER__) +#ifndef likely#define likely (x) __builtin_expect(!!(x), 1)#define unlikely (x) __builtin_expect(!!(x), 0)
include/qemu/osdep.h +20 -7
@@ -383,19 +383,28 @@ void QEMU_ERROR("code path is reachable")* determined by the pre-processor instead of the compiler, you'll * have to open-code it. Sadly, Coverity is severely confused by the * constant variants, so we have to dumb things down there. +* +* Preprocessor sorcery ahead: use different identifiers for the local +* variables in each expansion, so we can nest macro calls without +* shadowing variables. */ -#undef MIN -#define MIN (a, b) \ +#define MIN_INTERNAL (a, b, _a, _b) \ ({ \ typeof(1 ? (a) : (b)) _a = (a), _b = (b); \ _a < _b ? _a : _b; \ }) -#undef MAX -#define MAX (a, b) \ +#undef MIN +#define MIN (a, b) \ + MIN_INTERNAL((a), (b), MAKE_IDENTFIER(_a), MAKE_IDENTFIER(_b)) + +#define MAX_INTERNAL (a, b, _a, _b) \ ({ \ typeof(1 ? (a) : (b)) _a = (a), _b = (b); \ _a > _b ? _a : _b; \ }) +#undef MAX +#define MAX (a, b) \ + MAX_INTERNAL((a), (b), MAKE_IDENTFIER(_a), MAKE_IDENTFIER(_b))#ifdef __COVERITY__# define MIN_CONST (a, b) ((a) < (b) ? (a) : (b))
@@ -416,14 +425,18 @@ void QEMU_ERROR("code path is reachable")/* * Minimum function that returns zero only if both values are zero. * Intended for use with unsigned values only. +* +* Preprocessor sorcery ahead: use different identifiers for the local +* variables in each expansion, so we can nest macro calls without +* shadowing variables. */ -#ifndef MIN_NON_ZERO -#define MIN_NON_ZERO (a, b) \ +#define MIN_NON_ZERO_INTERNAL (a, b, _a, _b) \ ({ \ typeof(1 ? (a) : (b)) _a = (a), _b = (b); \ _a == 0 ? _b : (_b == 0 || _b > _a) ? _a : _b; \ }) -#endif +#define MIN_NON_ZERO (a, b) \ + MIN_NON_ZERO_INTERNAL((a), (b), MAKE_IDENTFIER(_a), MAKE_IDENTFIER(_b))/* * Round number down to multiple. Safe when m is not a power of 2 (see
Signature · 1 line
2.41.0
[PULL 32/56] spapr: Clean up local variable shadowing in spapr_init_cpus()
In reply to Markus ArmbrusterFrom: Cédric Le Goater <[email protected]>
Remove extra 'i' variable to fix this warning :
../hw/ppc/spapr.c: In function ‘spapr_init_cpus’:
../hw/ppc/spapr.c:2668:13: warning: declaration of ‘i’ shadows a previous local [-Wshadow=compatible-local]
2668 | int i;
| ^
../hw/ppc/spapr.c:2645:9: note: shadowed declaration is here
2645 | int i;
| ^
Message-ID: <[email protected]>
--- hw/ppc/spapr.c | 2 -- 1 file changed, 2 deletions(-)
hw/ppc/spapr.c +0 -2
@@ -2665,8 +2665,6 @@ static void spapr_init_cpus(SpaprMachineState *spapr) }if (smc->pre_2_10_has_unused_icps) { -int i; -for (i =0 ; i <spapr_max_server_number (spapr); i++) {/* Dummy entries get deregistered when real ICPState objects * are registered during CPU core hotplug.
Signature · 1 line
2.41.0
[PULL 04/56] block/dirty-bitmap: Clean up local variable shadowing
In reply to Markus ArmbrusterLocal variables shadowing other local variables or parameters make the code needlessly hard to understand. Tracked down with -Wshadow=local. Clean up: rename both the pair of parameters and the pair of local variables. While there, move the local variables to function scope.
Message-ID: <[email protected]>
--- block/monitor/bitmap-qmp-cmds.c | 19 ++++++++++--------- block/qcow2-bitmap.c | 3 +-- 2 files changed, 11 insertions(+), 11 deletions(-)
block/monitor/bitmap-qmp-cmds.c +10 -9
@@ -258,37 +258,38 @@ void qmp_block_dirty_bitmap_disable(const char *node, const char *name,bdrv_disable_dirty_bitmap (bitmap); } -BdrvDirtyBitmap *block_dirty_bitmap_merge (const char *node,const char *target, +BdrvDirtyBitmap *block_dirty_bitmap_merge (const char *dst_node, +const char *dst_bitmap,BlockDirtyBitmapOrStrList *bms,HBitmap **backup,Error **errp) {BlockDriverState *bs;BdrvDirtyBitmap *dst, *src;BlockDirtyBitmapOrStrList *lst; +const char *src_node, *src_bitmap;HBitmap *local_backup =NULL ;GLOBAL_STATE_CODE (); - dst =block_dirty_bitmap_lookup (node, target, &bs, errp); + dst =block_dirty_bitmap_lookup (dst_node, dst_bitmap, &bs, errp);if (!dst) {return NULL ; }for (lst = bms; lst; lst = lst->next) {switch (lst->value->type) { -const char *name, *node;case QTYPE_QSTRING : - name = lst->value->u.local; - src =bdrv_find_dirty_bitmap (bs, name); + src_bitmap = lst->value->u.local; + src =bdrv_find_dirty_bitmap (bs, src_bitmap);if (!src) { -error_setg (errp,"Dirty bitmap '%s' not found" , name); +error_setg (errp,"Dirty bitmap '%s' not found" , src_bitmap); goto fail; }break ;case QTYPE_QDICT : - node = lst->value->u.external.node; - name = lst->value->u.external.name; - src =block_dirty_bitmap_lookup (node, name,NULL , errp); + src_node = lst->value->u.external.node; + src_bitmap = lst->value->u.external.name; + src =block_dirty_bitmap_lookup (src_node, src_bitmap,NULL , errp);if (!src) { goto fail; }
block/qcow2-bitmap.c +1 -2
@@ -1555,7 +1555,6 @@ bool qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, FOR_EACH_DIRTY_BITMAP(bs, bitmap) {const char *name =bdrv_dirty_bitmap_name (bitmap);uint32_t granularity =bdrv_dirty_bitmap_granularity (bitmap); -Qcow2Bitmap *bm;if (!bdrv_dirty_bitmap_get_persistence (bitmap) ||bdrv_dirty_bitmap_inconsistent (bitmap)) {
@@ -1625,7 +1624,7 @@ bool qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs,/* allocate clusters and store bitmaps */ QSIMPLEQ_FOREACH(bm, bm_list, entry) { -BdrvDirtyBitmap *bitmap = bm->dirty_bitmap; + bitmap = bm->dirty_bitmap;if (bitmap ==NULL ||bdrv_dirty_bitmap_readonly (bitmap)) {continue ;
Signature · 1 line
2.41.0
[PULL 22/56] util/vhost-user-server: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
util/vhost-user-server.c: In function ‘set_watch’:
util/vhost-user-server.c:274:20: warning: declaration of ‘vu_fd_watch’ shadows a previous local [-Wshadow=compatible-local]
274 | VuFdWatch *vu_fd_watch = g_new0(VuFdWatch, 1);
| ^~~~~~~~~~~
util/vhost-user-server.c:271:16: note: shadowed declaration is here
271 | VuFdWatch *vu_fd_watch = find_vu_fd_watch(server, fd);
| ^~~~~~~~~~~Message-ID: <[email protected]>
--- util/vhost-user-server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/vhost-user-server.c +1 -1
@@ -278,7 +278,7 @@ set_watch(VuDev *vu_dev, int fd, int vu_evt,VuFdWatch *vu_fd_watch =find_vu_fd_watch (server, fd);if (!vu_fd_watch) { -VuFdWatch *vu_fd_watch =g_new0 (VuFdWatch,1 ); + vu_fd_watch =g_new0 (VuFdWatch,1 );QTAILQ_INSERT_TAIL (&server->vu_fd_watches, vu_fd_watch, next);
Signature · 1 line
2.41.0
[PULL 21/56] crypto/cipher-gnutls.c: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
In file included from crypto/cipher.c:140:
crypto/cipher-gnutls.c.inc: In function ‘qcrypto_gnutls_cipher_encrypt’:
crypto/cipher-gnutls.c.inc:116:17: warning: declaration of ‘err’ shadows a previous local [-Wshadow=compatible-local]
116 | int err = gnutls_cipher_init(&handle, ctx->galg, &gkey, NULL);
| ^~~
crypto/cipher-gnutls.c.inc:94:9: note: shadowed declaration is here
94 | int err;
| ^~~
--- crypto/cipher-gnutls.c.inc: In function ‘qcrypto_gnutls_cipher_decrypt’:
crypto/cipher-gnutls.c.inc:177:17: warning: declaration of ‘err’ shadows a previous local [-Wshadow=compatible-local]
177 | int err = gnutls_cipher_init(&handle, ctx->galg, &gkey, NULL);
| ^~~
crypto/cipher-gnutls.c.inc:154:9: note: shadowed declaration is here
154 | int err;
| ^~~Message-ID: <[email protected]>
--- crypto/cipher-gnutls.c.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
crypto/cipher-gnutls.c.inc +2 -2
@@ -113,7 +113,7 @@ qcrypto_gnutls_cipher_encrypt(QCryptoCipher *cipher, while (len) { gnutls_cipher_hd_t handle; gnutls_datum_t gkey = { (unsigned char *)ctx->key, ctx->nkey }; - int err = gnutls_cipher_init(&handle, ctx->galg, &gkey, NULL); + err = gnutls_cipher_init(&handle, ctx->galg, &gkey, NULL); if (err != 0) { error_setg(errp, "Cannot initialize cipher: %s", gnutls_strerror(err));
@@ -174,7 +174,7 @@ qcrypto_gnutls_cipher_decrypt(QCryptoCipher *cipher, while (len) { gnutls_cipher_hd_t handle; gnutls_datum_t gkey = { (unsigned char *)ctx->key, ctx->nkey }; - int err = gnutls_cipher_init(&handle, ctx->galg, &gkey, NULL); + err = gnutls_cipher_init(&handle, ctx->galg, &gkey, NULL); if (err != 0) { error_setg(errp, "Cannot initialize cipher: %s", gnutls_strerror(err));
Signature · 1 line
2.41.0
[PULL 23/56] linux-user/strace: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
linux-user/strace.c: In function ‘print_sockaddr’:
linux-user/strace.c:370:17: warning: declaration of ‘i’ shadows a previous local [-Wshadow=compatible-local]
370 | int i;
| ^
linux-user/strace.c:361:9: note: shadowed declaration is here
361 | int i;
| ^Message-ID: <[email protected]>
--- linux-user/strace.c | 1 - 1 file changed, 1 deletion(-)
linux-user/strace.c +0 -1
@@ -367,7 +367,6 @@ print_sockaddr(abi_ulong addr, abi_long addrlen, int last)switch (sa_family) {case AF_UNIX : {struct target_sockaddr_un *un = (struct target_sockaddr_un *)sa; -int i;qemu_log ("{sun_family=AF_UNIX,sun_path=\"" ); for (i = 0; i < addrlen - offsetof(struct target_sockaddr_un, sun_path) &&
Signature · 1 line
2.41.0
[PULL 13/56] target/tricore: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
target/tricore/translate.c:5016:18: warning: declaration of ‘temp’ shadows a previous local [-Wshadow=compatible-local]
5016 | TCGv temp = tcg_constant_i32(const9);
| ^~~~
target/tricore/translate.c:4958:10: note: shadowed declaration is here
4958 | TCGv temp;
| ^~~~Message-ID: <[email protected]>
--- target/tricore/translate.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
target/tricore/translate.c +3 -3
@@ -4962,8 +4962,6 @@ static void decode_rc_logical_shift(DisasContext *ctx) const9 =MASK_OP_RC_CONST9 (ctx->opcode); op2 =MASK_OP_RC_OP2 (ctx->opcode); - temp =tcg_temp_new (); -switch (op2) {case OPC2_32_RC_AND :tcg_gen_andi_tl (cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
@@ -4972,10 +4970,12 @@ static void decode_rc_logical_shift(DisasContext *ctx)tcg_gen_andi_tl (cpu_gpr_d[r2], cpu_gpr_d[r1], ~const9);break ;case OPC2_32_RC_NAND : + temp =tcg_temp_new ();tcg_gen_movi_tl (temp, const9);tcg_gen_nand_tl (cpu_gpr_d[r2], cpu_gpr_d[r1], temp);break ;case OPC2_32_RC_NOR : + temp =tcg_temp_new ();tcg_gen_movi_tl (temp, const9);tcg_gen_nor_tl (cpu_gpr_d[r2], cpu_gpr_d[r1], temp);break ;
@@ -5013,7 +5013,7 @@ static void decode_rc_logical_shift(DisasContext *ctx)break ;case OPC2_32_RC_SHUFFLE :if (has_feature (ctx,TRICORE_FEATURE_162 )) { -TCGv temp =tcg_constant_i32 (const9); + temp =tcg_constant_i32 (const9);gen_helper_shuffle (cpu_gpr_d[r2], cpu_gpr_d[r1], temp); }else {generate_trap (ctx,TRAPC_INSN_ERR ,TIN2_IOPC );
Signature · 1 line
2.41.0
[PULL 38/56] hw/acpi: changes towards enabling -Wshadow=local
In reply to Markus ArmbrusterFrom: Ani Sinha <[email protected]>
Code changes in acpi that addresses all compiler complaints coming from enabling -Wshadow flags. Enabling -Wshadow catches cases of local variables shadowing other local variables or parameters. These makes the code confusing and/or adds bugs that are difficult to catch. See also
Subject: Help wanted for enabling -Wshadow=local
Message-Id: <[email protected]>
https://lore.kernel.org/qemu-devel/[email protected]The code is tested to build with and without the flag turned on.
Message-ID: <[email protected]>
--- hw/acpi/cpu_hotplug.c | 25 +++++++++++++------------ hw/i386/acpi-build.c | 24 ++++++++++++------------ hw/smbios/smbios.c | 37 +++++++++++++++++++------------------ 3 files changed, 44 insertions(+), 42 deletions(-)
hw/acpi/cpu_hotplug.c +13 -12
@@ -265,26 +265,27 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,/* build Processor object for each processor */ for (i =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; +int cpu_apic_id = apic_ids->cpus[i].arch_id; -assert (apic_id <ACPI_CPU_HOTPLUG_ID_LIMIT ); +assert (cpu_apic_id <ACPI_CPU_HOTPLUG_ID_LIMIT ); - dev =aml_processor (i,0 ,0 ,"CP%.02X" , apic_id); + dev =aml_processor (i,0 ,0 ,"CP%.02X" , cpu_apic_id); method =aml_method ("_MAT" ,0 ,AML_NOTSERIALIZED );aml_append (method, -aml_return (aml_call2 (CPU_MAT_METHOD ,aml_int (apic_id),aml_int (i)) +aml_return (aml_call2 (CPU_MAT_METHOD , +aml_int (cpu_apic_id),aml_int (i)) ));aml_append (dev, method); method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED );aml_append (method, -aml_return (aml_call1 (CPU_STATUS_METHOD ,aml_int (apic_id)))); +aml_return (aml_call1 (CPU_STATUS_METHOD ,aml_int (cpu_apic_id))));aml_append (dev, method); method =aml_method ("_EJ0" ,1 ,AML_NOTSERIALIZED );aml_append (method, -aml_return (aml_call2 (CPU_EJECT_METHOD ,aml_int (apic_id), +aml_return (aml_call2 (CPU_EJECT_METHOD ,aml_int (cpu_apic_id),aml_arg (0 ))) );aml_append (dev, method);
@@ -298,11 +299,11 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,/* Arg0 = APIC ID */ method =aml_method (AML_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED );for (i =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; +int cpu_apic_id = apic_ids->cpus[i].arch_id; - if_ctx =aml_if (aml_equal (aml_arg (0 ),aml_int (apic_id))); + if_ctx =aml_if (aml_equal (aml_arg (0 ),aml_int (cpu_apic_id)));aml_append (if_ctx, -aml_notify (aml_name ("CP%.02X" , apic_id),aml_arg (1 )) +aml_notify (aml_name ("CP%.02X" , cpu_apic_id),aml_arg (1 )) );aml_append (method, if_ctx); }
@@ -319,13 +320,13 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,aml_varpackage (x86ms->apic_id_limit);for (i =0 , apic_idx =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; +int cpu_apic_id = apic_ids->cpus[i].arch_id; -for (; apic_idx < apic_id; apic_idx++) { +for (; apic_idx < cpu_apic_id; apic_idx++) {aml_append (pkg,aml_int (0 )); }aml_append (pkg,aml_int (apic_ids->cpus[i].cpu ?1 :0 )); - apic_idx = apic_id +1 ; + apic_idx = cpu_apic_id +1 ; }aml_append (sb_scope,aml_name_decl (CPU_ON_BITMAP , pkg));aml_append (ctx, sb_scope);
hw/i386/acpi-build.c +12 -12
@@ -1585,12 +1585,12 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (dev,aml_name_decl ("_UID" ,aml_int (bus_num)));aml_append (dev,aml_name_decl ("_BBN" ,aml_int (bus_num)));if (pci_bus_is_cxl (bus)) { -struct Aml *pkg =aml_package (2 ); +struct Aml *aml_pkg =aml_package (2 );aml_append (dev,aml_name_decl ("_HID" ,aml_string ("ACPI0016" ))); -aml_append (pkg,aml_eisaid ("PNP0A08" )); -aml_append (pkg,aml_eisaid ("PNP0A03" )); -aml_append (dev,aml_name_decl ("_CID" , pkg)); +aml_append (aml_pkg,aml_eisaid ("PNP0A08" )); +aml_append (aml_pkg,aml_eisaid ("PNP0A03" )); +aml_append (dev,aml_name_decl ("_CID" , aml_pkg));build_cxl_osc_method (dev); }else if (pci_bus_is_express (bus)) {aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A08" )));
@@ -1783,14 +1783,14 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,Object *pci_host =acpi_get_i386_pci_host ();if (pci_host) { -PCIBus *bus =PCI_HOST_BRIDGE (pci_host)->bus; -Aml *scope =aml_scope ("PCI0" ); +PCIBus *pbus =PCI_HOST_BRIDGE (pci_host)->bus; +Aml *ascope =aml_scope ("PCI0" );/* Scan all PCI buses. Generate tables to support hotplug. */ -build_append_pci_bus_devices (scope, bus); -if (object_property_find (OBJECT (bus),ACPI_PCIHP_PROP_BSEL )) { -build_append_pcihp_slots (scope, bus); +build_append_pci_bus_devices (ascope, pbus); +if (object_property_find (OBJECT (pbus),ACPI_PCIHP_PROP_BSEL )) { +build_append_pcihp_slots (ascope, pbus); } -aml_append (sb_scope, scope); +aml_append (sb_scope, ascope); } }
@@ -1842,10 +1842,10 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,bool has_pcnt;Object *pci_host =acpi_get_i386_pci_host (); -PCIBus *bus =PCI_HOST_BRIDGE (pci_host)->bus; +PCIBus *b =PCI_HOST_BRIDGE (pci_host)->bus; scope =aml_scope ("\\_SB.PCI0" ); - has_pcnt =build_append_notfication_callback (scope, bus); + has_pcnt =build_append_notfication_callback (scope, b);if (has_pcnt) {aml_append (dsdt, scope); }
hw/smbios/smbios.c +19 -18
@@ -1423,13 +1423,14 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)if (!qemu_opts_validate (opts, qemu_smbios_type8_opts, errp)) {return ; } -struct type8_instance *t; - t = g_new0(struct type8_instance, 1); -save_opt (&t->internal_reference, opts,"internal_reference" ); -save_opt (&t->external_reference, opts,"external_reference" ); - t->connector_type =qemu_opt_get_number (opts,"connector_type" ,0 ); - t->port_type =qemu_opt_get_number (opts,"port_type" ,0 ); -QTAILQ_INSERT_TAIL (&type8, t, next); +struct type8_instance *t8_i; + t8_i = g_new0(struct type8_instance, 1); +save_opt (&t8_i->internal_reference, opts,"internal_reference" ); +save_opt (&t8_i->external_reference, opts,"external_reference" ); + t8_i->connector_type =qemu_opt_get_number (opts, +"connector_type" ,0 ); + t8_i->port_type =qemu_opt_get_number (opts,"port_type" ,0 ); +QTAILQ_INSERT_TAIL (&type8, t8_i, next);return ;case 11 :if (!qemu_opts_validate (opts, qemu_smbios_type11_opts, errp)) {
@@ -1452,27 +1453,27 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) type17.speed =qemu_opt_get_number (opts,"speed" ,0 );return ;case 41 : { -struct type41_instance *t; +struct type41_instance *t41_i;Error *local_err =NULL ;if (!qemu_opts_validate (opts, qemu_smbios_type41_opts, errp)) {return ; } - t = g_new0(struct type41_instance, 1); -save_opt (&t->designation, opts,"designation" ); - t->kind =qapi_enum_parse (&type41_kind_lookup, -qemu_opt_get (opts,"kind" ), -0 , &local_err) +1 ; - t->kind |=0x80 ;/* enabled */ + t41_i = g_new0(struct type41_instance, 1); +save_opt (&t41_i->designation, opts,"designation" ); + t41_i->kind =qapi_enum_parse (&type41_kind_lookup, +qemu_opt_get (opts,"kind" ), +0 , &local_err) +1 ; + t41_i->kind |=0x80 ;/* enabled */ if (local_err !=NULL ) {error_propagate (errp, local_err); -g_free (t); +g_free (t41_i);return ; } - t->instance =qemu_opt_get_number (opts,"instance" ,1 ); -save_opt (&t->pcidev, opts,"pcidev" ); + t41_i->instance =qemu_opt_get_number (opts,"instance" ,1 ); +save_opt (&t41_i->pcidev, opts,"pcidev" ); -QTAILQ_INSERT_TAIL (&type41, t, next); +QTAILQ_INSERT_TAIL (&type41, t41_i, next);return ; }default :
Signature · 1 line
2.41.0
Re: [PULL 38/56] hw/acpi: changes towards enabling -Wshadow=local
Quoted 22 lines · Markus Armbruster
From: Ani Sinha <[email protected]>
Code changes in acpi that addresses all compiler complaints coming from enabling -Wshadow flags. Enabling -Wshadow catches cases of local variables shadowing other local variables or parameters. These makes the code confusing and/or adds bugs that are difficult to catch. See also
Subject: Help wanted for enabling -Wshadow=local Message-Id: <[email protected]> https://lore.kernel.org/qemu-devel/[email protected]The code is tested to build with and without the flag turned on.
CC Markus Armbruster <[email protected]>CC Philippe Mathieu-Daude <[email protected]>Signed-off-by Ani Sinha <[email protected]>
Quoted 4 lines
Message-ID: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>[Commit message tweaked]Signed-off-by Markus Armbruster <[email protected]>
Thanks!
Are you not going to pick up "hw/i386: changes towards enabling -Wshadow=local” ?
Quoted 199 lines
---
hw/acpi/cpu_hotplug.c | 25 +++++++++++++------------ hw/i386/acpi-build.c | 24 ++++++++++++------------ hw/smbios/smbios.c | 37 +++++++++++++++++++------------------ 3 files changed, 44 insertions(+), 42 deletions(-)hw/acpi/cpu_hotplug.c +13
-12@@ -265,26 +265,27 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,/* build Processor object for each processor */ for (i =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; +int cpu_apic_id = apic_ids->cpus[i].arch_id; -assert (apic_id <ACPI_CPU_HOTPLUG_ID_LIMIT ); +assert (cpu_apic_id <ACPI_CPU_HOTPLUG_ID_LIMIT ); - dev =aml_processor (i,0 ,0 ,"CP%.02X" , apic_id); + dev =aml_processor (i,0 ,0 ,"CP%.02X" , cpu_apic_id); method =aml_method ("_MAT" ,0 ,AML_NOTSERIALIZED );aml_append (method, -aml_return (aml_call2 (CPU_MAT_METHOD ,aml_int (apic_id),aml_int (i)) +aml_return (aml_call2 (CPU_MAT_METHOD , +aml_int (cpu_apic_id),aml_int (i)) ));aml_append (dev, method); method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED );aml_append (method, -aml_return (aml_call1 (CPU_STATUS_METHOD ,aml_int (apic_id)))); +aml_return (aml_call1 (CPU_STATUS_METHOD ,aml_int (cpu_apic_id))));aml_append (dev, method); method =aml_method ("_EJ0" ,1 ,AML_NOTSERIALIZED );aml_append (method, -aml_return (aml_call2 (CPU_EJECT_METHOD ,aml_int (apic_id), +aml_return (aml_call2 (CPU_EJECT_METHOD ,aml_int (cpu_apic_id),aml_arg (0 ))) );aml_append (dev, method);@@ -298,11 +299,11 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,/* Arg0 = APIC ID */ method =aml_method (AML_NOTIFY_METHOD ,2 ,AML_NOTSERIALIZED );for (i =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; +int cpu_apic_id = apic_ids->cpus[i].arch_id; - if_ctx =aml_if (aml_equal (aml_arg (0 ),aml_int (apic_id))); + if_ctx =aml_if (aml_equal (aml_arg (0 ),aml_int (cpu_apic_id)));aml_append (if_ctx, -aml_notify (aml_name ("CP%.02X" , apic_id),aml_arg (1 )) +aml_notify (aml_name ("CP%.02X" , cpu_apic_id),aml_arg (1 )) );aml_append (method, if_ctx); }@@ -319,13 +320,13 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,aml_varpackage (x86ms->apic_id_limit);for (i =0 , apic_idx =0 ; i < apic_ids->len; i++) { -int apic_id = apic_ids->cpus[i].arch_id; +int cpu_apic_id = apic_ids->cpus[i].arch_id; -for (; apic_idx < apic_id; apic_idx++) { +for (; apic_idx < cpu_apic_id; apic_idx++) {aml_append (pkg,aml_int (0 )); }aml_append (pkg,aml_int (apic_ids->cpus[i].cpu ?1 :0 )); - apic_idx = apic_id +1 ; + apic_idx = cpu_apic_id +1 ; }aml_append (sb_scope,aml_name_decl (CPU_ON_BITMAP , pkg));aml_append (ctx, sb_scope);hw/i386/acpi-build.c +12
-12@@ -1585,12 +1585,12 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (dev,aml_name_decl ("_UID" ,aml_int (bus_num)));aml_append (dev,aml_name_decl ("_BBN" ,aml_int (bus_num)));if (pci_bus_is_cxl (bus)) { -struct Aml *pkg =aml_package (2 ); +struct Aml *aml_pkg =aml_package (2 );aml_append (dev,aml_name_decl ("_HID" ,aml_string ("ACPI0016" ))); -aml_append (pkg,aml_eisaid ("PNP0A08" )); -aml_append (pkg,aml_eisaid ("PNP0A03" )); -aml_append (dev,aml_name_decl ("_CID" , pkg)); +aml_append (aml_pkg,aml_eisaid ("PNP0A08" )); +aml_append (aml_pkg,aml_eisaid ("PNP0A03" )); +aml_append (dev,aml_name_decl ("_CID" , aml_pkg));build_cxl_osc_method (dev); }else if (pci_bus_is_express (bus)) {aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A08" )));@@ -1783,14 +1783,14 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,Object *pci_host =acpi_get_i386_pci_host ();if (pci_host) { -PCIBus *bus =PCI_HOST_BRIDGE (pci_host)->bus; -Aml *scope =aml_scope ("PCI0" ); +PCIBus *pbus =PCI_HOST_BRIDGE (pci_host)->bus; +Aml *ascope =aml_scope ("PCI0" );/* Scan all PCI buses. Generate tables to support hotplug. */ -build_append_pci_bus_devices (scope, bus); -if (object_property_find (OBJECT (bus),ACPI_PCIHP_PROP_BSEL )) { -build_append_pcihp_slots (scope, bus); +build_append_pci_bus_devices (ascope, pbus); +if (object_property_find (OBJECT (pbus),ACPI_PCIHP_PROP_BSEL )) { +build_append_pcihp_slots (ascope, pbus); } -aml_append (sb_scope, scope); +aml_append (sb_scope, ascope); } }@@ -1842,10 +1842,10 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,bool has_pcnt;Object *pci_host =acpi_get_i386_pci_host (); -PCIBus *bus =PCI_HOST_BRIDGE (pci_host)->bus; +PCIBus *b =PCI_HOST_BRIDGE (pci_host)->bus; scope =aml_scope ("\\_SB.PCI0" ); - has_pcnt =build_append_notfication_callback (scope, bus); + has_pcnt =build_append_notfication_callback (scope, b);if (has_pcnt) {aml_append (dsdt, scope); }hw/smbios/smbios.c +19
-18@@ -1423,13 +1423,14 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)if (!qemu_opts_validate (opts, qemu_smbios_type8_opts, errp)) {return ; } -struct type8_instance *t; - t = g_new0(struct type8_instance, 1); -save_opt (&t->internal_reference, opts,"internal_reference" ); -save_opt (&t->external_reference, opts,"external_reference" ); - t->connector_type =qemu_opt_get_number (opts,"connector_type" ,0 ); - t->port_type =qemu_opt_get_number (opts,"port_type" ,0 ); -QTAILQ_INSERT_TAIL (&type8, t, next); +struct type8_instance *t8_i; + t8_i = g_new0(struct type8_instance, 1); +save_opt (&t8_i->internal_reference, opts,"internal_reference" ); +save_opt (&t8_i->external_reference, opts,"external_reference" ); + t8_i->connector_type =qemu_opt_get_number (opts, +"connector_type" ,0 ); + t8_i->port_type =qemu_opt_get_number (opts,"port_type" ,0 ); +QTAILQ_INSERT_TAIL (&type8, t8_i, next);return ;case 11 :if (!qemu_opts_validate (opts, qemu_smbios_type11_opts, errp)) {@@ -1452,27 +1453,27 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) type17.speed =qemu_opt_get_number (opts,"speed" ,0 );return ;case 41 : { -struct type41_instance *t; +struct type41_instance *t41_i;Error *local_err =NULL ;if (!qemu_opts_validate (opts, qemu_smbios_type41_opts, errp)) {return ; } - t = g_new0(struct type41_instance, 1); -save_opt (&t->designation, opts,"designation" ); - t->kind =qapi_enum_parse (&type41_kind_lookup, -qemu_opt_get (opts,"kind" ), -0 , &local_err) +1 ; - t->kind |=0x80 ;/* enabled */ + t41_i = g_new0(struct type41_instance, 1); +save_opt (&t41_i->designation, opts,"designation" ); + t41_i->kind =qapi_enum_parse (&type41_kind_lookup, +qemu_opt_get (opts,"kind" ), +0 , &local_err) +1 ; + t41_i->kind |=0x80 ;/* enabled */ if (local_err !=NULL ) {error_propagate (errp, local_err); -g_free (t); +g_free (t41_i);return ; } - t->instance =qemu_opt_get_number (opts,"instance" ,1 ); -save_opt (&t->pcidev, opts,"pcidev" ); + t41_i->instance =qemu_opt_get_number (opts,"instance" ,1 ); +save_opt (&t41_i->pcidev, opts,"pcidev" ); -QTAILQ_INSERT_TAIL (&type41, t, next); +QTAILQ_INSERT_TAIL (&type41, t41_i, next);return ; }default :Signature · 1 line
2.41.0
Re: [PULL 38/56] hw/acpi: changes towards enabling -Wshadow=local
Quoted 25 lines · Ani Sinha
Quoted 20 lines · Markus Armbruster
From: Ani Sinha <[email protected]>
Code changes in acpi that addresses all compiler complaints coming from enabling -Wshadow flags. Enabling -Wshadow catches cases of local variables shadowing other local variables or parameters. These makes the code confusing and/or adds bugs that are difficult to catch. See also
Subject: Help wanted for enabling -Wshadow=local Message-Id: <[email protected]> https://lore.kernel.org/qemu-devel/[email protected]The code is tested to build with and without the flag turned on.
CC Markus Armbruster <[email protected]>CC Philippe Mathieu-Daude <[email protected]>Signed-off-by Ani Sinha <[email protected]>Quoted 4 lines
Message-ID: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>[Commit message tweaked]Signed-off-by Markus Armbruster <[email protected]>
Quoted 2 lines
Thanks!
Are you not going to pick up "hw/i386: changes towards enabling -Wshadow=local” ?
Your conversation with Michael looked unfinished to me, so I didn't include your patch in my pull request. I did add it to shadow-next.
Re: [PULL 38/56] hw/acpi: changes towards enabling -Wshadow=local
Quoted 27 lines · Markus Armbruster
Quoted 25 lines · Ani Sinha
Quoted 24 lines · Markus Armbruster
From: Ani Sinha <[email protected]>
Code changes in acpi that addresses all compiler complaints coming from enabling -Wshadow flags. Enabling -Wshadow catches cases of local variables shadowing other local variables or parameters. These makes the code confusing and/or adds bugs that are difficult to catch. See also
Subject: Help wanted for enabling -Wshadow=local Message-Id: <[email protected]> https://lore.kernel.org/qemu-devel/[email protected]The code is tested to build with and without the flag turned on.
CC Markus Armbruster <[email protected]>CC Philippe Mathieu-Daude <[email protected]>Signed-off-by Ani Sinha <[email protected]>Message-ID: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>[Commit message tweaked]Signed-off-by Markus Armbruster <[email protected]>
Quoted 5 lines
Quoted 2 lines
Thanks!
Are you not going to pick up "hw/i386: changes towards enabling -Wshadow=local” ?Your conversation with Michael looked unfinished to me, so I didn't include your patch in my pull request. I did add it to shadow-next.
Yes - I clarified what I meant. These patch just always changed the name of the inner scope variable but that is not always the best thing to do.
Signature · 1 line
MST
[PULL 43/56] aspeed/i2c: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Cédric Le Goater <[email protected]>
Remove superfluous local 'data' variable and use the one define at the top of the routine. This fixes :
../hw/i2c/aspeed_i2c.c: In function ‘aspeed_i2c_bus_recv’:
../hw/i2c/aspeed_i2c.c:315:17: warning: declaration of ‘data’ shadows a previous local [-Wshadow=compatible-local]
315 | uint8_t data;
| ^~~~
../hw/i2c/aspeed_i2c.c:288:13: note: shadowed declaration is here
288 | uint8_t data;
| ^~~~Message-ID: <[email protected]>
--- hw/i2c/aspeed_i2c.c | 1 - 1 file changed, 1 deletion(-)
hw/i2c/aspeed_i2c.c +0 -1
@@ -312,7 +312,6 @@ static void aspeed_i2c_bus_recv(AspeedI2CBus *bus)SHARED_ARRAY_FIELD_DP32 (bus->regs, reg_pool_ctrl,RX_COUNT , i &0xff );SHARED_ARRAY_FIELD_DP32 (bus->regs, reg_cmd,RX_BUFF_EN ,0 ); }else if (SHARED_ARRAY_FIELD_EX32 (bus->regs, reg_cmd,RX_DMA_EN )) { -uint8_t data;/* In new mode, clear how many bytes we RXed */ if (aspeed_i2c_is_new_mode (bus->controller)) {ARRAY_FIELD_DP32 (bus->regs,I2CM_DMA_LEN_STS ,RX_LEN ,0 );
Signature · 1 line
2.41.0
[PULL 45/56] aspeed/i3c: Rename variable shadowing a local
In reply to Markus ArmbrusterFrom: Cédric Le Goater <[email protected]>
to fix warning :
../hw/i3c/aspeed_i3c.c: In function ‘aspeed_i3c_realize’:
../hw/i3c/aspeed_i3c.c:1959:17: warning: declaration of ‘dev’ shadows a parameter [-Wshadow=local]
1959 | Object *dev = OBJECT(&s->devices[i]);
| ^~~
../hw/i3c/aspeed_i3c.c:1942:45: note: shadowed declaration is here
1942 | static void aspeed_i3c_realize(DeviceState *dev, Error **errp)
| ~~~~~~~~~~~~~^~~
Message-ID: <[email protected]>
--- hw/misc/aspeed_i3c.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/misc/aspeed_i3c.c +3 -3
@@ -296,13 +296,13 @@ static void aspeed_i3c_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (&s->iomem_container,0x0 , &s->iomem);for (i =0 ; i <ASPEED_I3C_NR_DEVICES ; ++i) { -Object *dev =OBJECT (&s->devices[i]); +Object *i3c_dev =OBJECT (&s->devices[i]); -if (!object_property_set_uint (dev,"device-id" , i, errp)) { +if (!object_property_set_uint (i3c_dev,"device-id" , i, errp)) {return ; } -if (!sysbus_realize (SYS_BUS_DEVICE (dev), errp)) { +if (!sysbus_realize (SYS_BUS_DEVICE (i3c_dev), errp)) {return ; }
Signature · 1 line
2.41.0
[PULL 26/56] softmmu/physmem: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
softmmu/physmem.c: In function ‘cpu_physical_memory_snapshot_and_clear_dirty’:
softmmu/physmem.c:916:27: warning: declaration of ‘offset’ shadows a parameter [-Wshadow=compatible-local]
916 | unsigned long offset = page % DIRTY_MEMORY_BLOCK_SIZE;
| ^~~~~~ softmmu/physmem.c:892:31: note: shadowed declaration is here
892 | (MemoryRegion *mr, hwaddr offset, hwaddr length, unsigned client)
| ~~~~~~~^~~~~~
Message-ID: <[email protected]>
--- softmmu/physmem.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
softmmu/physmem.c +5 -5
@@ -913,16 +913,16 @@ DirtyBitmapSnapshot *cpu_physical_memory_snapshot_and_clear_dirtywhile (page < end) {unsigned long idx = page /DIRTY_MEMORY_BLOCK_SIZE ; -unsigned long offset = page %DIRTY_MEMORY_BLOCK_SIZE ; +unsigned long ofs = page %DIRTY_MEMORY_BLOCK_SIZE ;unsigned long num =MIN (end - page, -DIRTY_MEMORY_BLOCK_SIZE - offset); +DIRTY_MEMORY_BLOCK_SIZE - ofs); -assert (QEMU_IS_ALIGNED (offset, (1 <<BITS_PER_LEVEL ))); +assert (QEMU_IS_ALIGNED (ofs, (1 <<BITS_PER_LEVEL )));assert (QEMU_IS_ALIGNED (num, (1 <<BITS_PER_LEVEL ))); - offset >>=BITS_PER_LEVEL ; + ofs >>=BITS_PER_LEVEL ;bitmap_copy_and_clear_atomic (snap->dirty + dest, - blocks->blocks[idx] + offset, + blocks->blocks[idx] + ofs, num); page += num; dest += num >>BITS_PER_LEVEL ;
Signature · 1 line
2.41.0
[PULL 06/56] block: Clean up local variable shadowing
In reply to Markus ArmbrusterLocal variables shadowing other local variables or parameters make the code needlessly hard to understand. Tracked down with -Wshadow=local. Clean up: delete inner declarations when they are actually redundant, else rename variables.
Message-ID: <[email protected]>
--- block.c | 9 +++++---- block/rbd.c | 2 +- block/stream.c | 1 - block/vvfat.c | 35 ++++++++++++++++++----------------- hw/block/xen-block.c | 6 +++--- 5 files changed, 27 insertions(+), 26 deletions(-)
block.c +5 -4
@@ -3072,18 +3072,19 @@ bdrv_attach_child_common(BlockDriverState *child_bs, &local_err);if (ret <0 && child_class->change_aio_ctx) { -Transaction *tran =tran_new (); +Transaction *aio_ctx_tran =tran_new ();GHashTable *visited =g_hash_table_new (NULL ,NULL );bool ret_child;g_hash_table_add (visited, new_child); ret_child = child_class->change_aio_ctx (new_child, child_ctx, - visited, tran,NULL ); + visited, aio_ctx_tran, +NULL );if (ret_child == true) {error_free (local_err); ret =0 ; } -tran_finalize (tran, ret_child == true ?0 :-1 ); +tran_finalize (aio_ctx_tran, ret_child == true ?0 :-1 );g_hash_table_destroy (visited); }
@@ -6208,12 +6209,12 @@ void bdrv_iterate_format(void (*it)(void *opaque, const char *name), QLIST_FOREACH(drv, &bdrv_drivers, list) {if (drv->format_name) {bool found = false; -int i = count;if (use_bdrv_whitelist && !bdrv_is_whitelisted (drv, read_only)) {continue ; } + i = count;while (formats && i && !found) { found = !strcmp (formats[--i], drv->format_name); }
block/rbd.c +1 -1
@@ -1290,7 +1290,7 @@ static int coroutine_fn qemu_rbd_start_co(BlockDriverState *bs,* operations that exceed the current size. */ if (offset + bytes > s->image_size) { -int r =qemu_rbd_resize (bs, offset + bytes); + r =qemu_rbd_resize (bs, offset + bytes);if (r <0 ) {return r; }
block/stream.c +0 -1
@@ -292,7 +292,6 @@ void stream_start(const char *job_id, BlockDriverState *bs,/* Make sure that the image is opened in read-write mode */ bs_read_only =bdrv_is_read_only (bs);if (bs_read_only) { -int ret;/* Hold the chain during reopen */ if (bdrv_freeze_backing_chain (bs, above_base, errp) <0 ) {return ;
block/vvfat.c +18 -17
@@ -777,7 +777,6 @@ static int read_directory(BDRVVVFATState* s, int mapping_index)while ((entry=readdir (dir))) {unsigned int length=strlen (dirname)+2 +strlen (entry->d_name);char * buffer; -direntry_t * direntry;struct stat st;int is_dot=!strcmp (entry->d_name,"." );int is_dotdot=!strcmp (entry->d_name,".." );
@@ -857,7 +856,7 @@ static int read_directory(BDRVVVFATState* s, int mapping_index)/* fill with zeroes up to the end of the cluster */ while (s->directory.next%(0x10 *s->sectors_per_cluster)) { -direntry_t * direntry=array_get_next (&(s->directory)); + direntry =array_get_next (&(s->directory));memset (direntry,0 ,sizeof (direntry_t)); }
@@ -1962,24 +1961,24 @@ get_cluster_count_for_direntry(BDRVVVFATState* s, direntry_t* direntry, const ch* This is horribly inefficient, but that is okay, since * it is rarely executed, if at all. */ -int64_t offset =cluster2sector (s, cluster_num); +int64_t offs =cluster2sector (s, cluster_num);vvfat_close_current_file (s);for (i =0 ; i < s->sectors_per_cluster; i++) {int res; res =bdrv_is_allocated (s->qcow->bs, - (offset + i) *BDRV_SECTOR_SIZE , + (offs + i) *BDRV_SECTOR_SIZE ,BDRV_SECTOR_SIZE ,NULL );if (res <0 ) {return -1 ; }if (!res) { - res =vvfat_read (s->bs, offset, s->cluster_buffer,1 ); + res =vvfat_read (s->bs, offs, s->cluster_buffer,1 );if (res) {return -1 ; } - res =bdrv_co_pwrite (s->qcow, offset *BDRV_SECTOR_SIZE , + res =bdrv_co_pwrite (s->qcow, offs *BDRV_SECTOR_SIZE ,BDRV_SECTOR_SIZE , s->cluster_buffer,0 );if (res <0 ) {
@@ -2467,8 +2466,9 @@ commit_direntries(BDRVVVFATState* s, int dir_index, int parent_mapping_index)for (c = first_cluster; !fat_eof (s, c); c =modified_fat_get (s, c)) {direntry_t *first_direntry; -void * direntry =array_get (&(s->directory), current_dir_index); -int ret =vvfat_read (s->bs,cluster2sector (s, c), direntry, + + direntry =array_get (&(s->directory), current_dir_index); + ret =vvfat_read (s->bs,cluster2sector (s, c), (uint8_t *)direntry, s->sectors_per_cluster);if (ret)return ret;
@@ -2690,12 +2690,12 @@ static int handle_renames_and_mkdirs(BDRVVVFATState* s)direntry_t * direntry =array_get (&(s->directory), mapping->info.dir.first_dir_index);uint32_t c = mapping->begin; -int i =0 ; +int j =0 ;/* recurse */ while (!fat_eof (s, c)) { do { - direntry_t* d = direntry + i; + direntry_t *d = direntry + j; if (is_file(d) || (is_directory(d) && !is_dot(d))) { int l;
@@ -2716,8 +2716,8 @@ static int handle_renames_and_mkdirs(BDRVVVFATState* s)schedule_rename (s, m->begin, new_path); } - i++; - }while ((i % (0x10 * s->sectors_per_cluster)) !=0 ); + j++; + }while (j % (0x10 * s->sectors_per_cluster) !=0 ); c =fat_get (s, c); } }
@@ -2804,16 +2804,16 @@ static int coroutine_fn GRAPH_RDLOCK handle_commits(BDRVVVFATState* s)int begin = commit->param.new_file.first_cluster;mapping_t * mapping =find_mapping_for_cluster (s, begin);direntry_t * entry; -int i; +int j;/* find direntry */ -for (i =0 ; i < s->directory.next; i++) { - entry =array_get (&(s->directory), i); +for (j =0 ; j < s->directory.next; j++) { + entry =array_get (&(s->directory), j);if (is_file (entry) &&begin_of_direntry (entry) == begin)break ; } -if (i >= s->directory.next) { +if (j >= s->directory.next) { fail =-6 ;continue ; }
@@ -2833,8 +2833,9 @@ static int coroutine_fn GRAPH_RDLOCK handle_commits(BDRVVVFATState* s) mapping->mode =MODE_NORMAL ; mapping->info.file.offset =0 ; -if (commit_one_file (s, i,0 )) +if (commit_one_file (s, j,0 )) { fail =-7 ; + }break ; }
hw/block/xen-block.c +3 -3
@@ -369,7 +369,7 @@ static void xen_block_get_vdev(Object *obj, Visitor *v, const char *name,case XEN_BLOCK_VDEV_TYPE_XVD :case XEN_BLOCK_VDEV_TYPE_HD :case XEN_BLOCK_VDEV_TYPE_SD : { -char *name =disk_to_vbd_name (vdev->disk); +char *vbd_name =disk_to_vbd_name (vdev->disk); str = g_strdup_printf("%s%s%lu", (vdev->type == XEN_BLOCK_VDEV_TYPE_XVD) ?
@@ -377,8 +377,8 @@ static void xen_block_get_vdev(Object *obj, Visitor *v, const char *name, (vdev->type ==XEN_BLOCK_VDEV_TYPE_HD ) ?"hd" :"sd" , - name, vdev->partition); -g_free (name); + vbd_name, vdev->partition); +g_free (vbd_name);break ; }default :
Signature · 1 line
2.41.0
[PULL 27/56] hw/core/machine: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
hw/core/machine.c: In function ‘machine_initfn’:
hw/core/machine.c:1081:17: warning: declaration of ‘obj’ shadows a parameter [-Wshadow=compatible-local]
1081 | Object *obj = OBJECT(ms);
| ^~~
hw/core/machine.c:1065:36: note: shadowed declaration is here
1065 | static void machine_initfn(Object *obj)
| ~~~~~~~~^~~
Message-ID: <[email protected]>
--- hw/core/machine.c | 2 -- 1 file changed, 2 deletions(-)
hw/core/machine.c +0 -2
@@ -1082,8 +1082,6 @@ static void machine_initfn(Object *obj) ms->maxram_size = mc->default_ram_size;if (mc->nvdimm_supported) { -Object *obj =OBJECT (ms); - ms->nvdimms_state =g_new0 (NVDIMMState,1 );object_property_add_bool (obj,"nvdimm" , machine_get_nvdimm, machine_set_nvdimm);
Signature · 1 line
2.41.0
[PULL 33/56] spapr: Clean up local variable shadowing in spapr_get_fw_dev_path()
In reply to Markus ArmbrusterFrom: Cédric Le Goater <[email protected]>
Rename PCIDevice variable to avoid this warning :
../hw/ppc/spapr.c: In function ‘spapr_get_fw_dev_path’:
../hw/ppc/spapr.c:3217:20: warning: declaration of ‘pcidev’ shadows a previous local [-Wshadow=compatible-local]
3217 | PCIDevice *pcidev = CAST(PCIDevice, dev, TYPE_PCI_DEVICE);
| ^~~~~~
../hw/ppc/spapr.c:3147:16: note: shadowed declaration is here
3147 | PCIDevice *pcidev = CAST(PCIDevice, dev, TYPE_PCI_DEVICE);
| ^~~~~~Message-ID: <[email protected]>
--- hw/ppc/spapr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/ppc/spapr.c +2 -2
@@ -3214,8 +3214,8 @@ static char *spapr_get_fw_dev_path(FWPathProvider *p, BusState *bus,if (g_str_equal ("pci-bridge" ,qdev_fw_name (dev))) {/* SLOF uses "pci" instead of "pci-bridge" for PCI bridges */ -PCIDevice *pcidev =CAST (PCIDevice, dev,TYPE_PCI_DEVICE ); -return g_strdup_printf ("pci@%x" ,PCI_SLOT (pcidev->devfn)); +PCIDevice *pdev =CAST (PCIDevice, dev,TYPE_PCI_DEVICE ); +return g_strdup_printf ("pci@%x" ,PCI_SLOT (pdev->devfn)); }if (pcidev) {
Signature · 1 line
2.41.0
[PULL 36/56] spapr/drc: Clean up local variable shadowing in prop_get_fdt()
In reply to Markus ArmbrusterFrom: Cédric Le Goater <[email protected]>
Rename 'name' variable to avoid this warning :
../hw/ppc/spapr_drc.c: In function ‘prop_get_fdt’:
../hw/ppc/spapr_drc.c:344:21: warning: declaration of ‘name’ shadows a parameter [-Wshadow=compatible-local]
344 | const char *name = NULL;
| ^~~~ ../hw/ppc/spapr_drc.c:325:63: note: shadowed declaration is here
325 | static void prop_get_fdt(Object *obj, Visitor *v, const char *name,
| ~~~~~~~~~~~~^~~~
Message-ID: <[email protected]>
--- hw/ppc/spapr_drc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
hw/ppc/spapr_drc.c +5 -5
@@ -341,7 +341,7 @@ static void prop_get_fdt(Object *obj, Visitor *v, const char *name, fdt_depth =0 ; do { - const char *name = NULL; + const char *dt_name = NULL; const struct fdt_property *prop = NULL; int prop_len = 0, name_len = 0; uint32_t tag;
@@ -351,8 +351,8 @@ static void prop_get_fdt(Object *obj, Visitor *v, const char *name,switch (tag) {case FDT_BEGIN_NODE : fdt_depth++; - name =fdt_get_name (fdt, fdt_offset, &name_len); -if (!visit_start_struct (v, name,NULL ,0 , errp)) { + dt_name =fdt_get_name (fdt, fdt_offset, &name_len); +if (!visit_start_struct (v, dt_name,NULL ,0 , errp)) {return ; }break ;
@@ -369,8 +369,8 @@ static void prop_get_fdt(Object *obj, Visitor *v, const char *name,case FDT_PROP : {int i; prop =fdt_get_property_by_offset (fdt, fdt_offset, &prop_len); - name =fdt_string (fdt,fdt32_to_cpu (prop->nameoff)); -if (!visit_start_list (v, name,NULL ,0 , errp)) { + dt_name =fdt_string (fdt,fdt32_to_cpu (prop->nameoff)); +if (!visit_start_list (v, dt_name,NULL ,0 , errp)) {return ; }for (i =0 ; i < prop_len; i++) {
Signature · 1 line
2.41.0
[PULL 41/56] hw/arm/smmuv3.c: Avoid shadowing variable
In reply to Markus ArmbrusterFrom: Peter Maydell <[email protected]>
Avoid shadowing a variable in smmuv3_notify_iova():
../../hw/arm/smmuv3.c: In function ‘smmuv3_notify_iova’:../../hw/arm/smmuv3.c:1043:23: warning: declaration of ‘event’ shadows a previous local [-Wshadow=local]
1043 | SMMUEventInfo event = {.inval_ste_allowed = true};
| ^~~~~../../hw/arm/smmuv3.c:1038:19: note: shadowed declaration is here
1038 | IOMMUTLBEvent event;
| ^~~~~
Message-ID: <[email protected]>
--- hw/arm/smmuv3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/arm/smmuv3.c +2 -2
@@ -1040,8 +1040,8 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr,SMMUv3State *s = sdev->smmu;if (!tg) { -SMMUEventInfo event = {.inval_ste_allowed = true}; -SMMUTransCfg *cfg =smmuv3_get_config (sdev, &event); +SMMUEventInfo eventinfo = {.inval_ste_allowed = true}; +SMMUTransCfg *cfg =smmuv3_get_config (sdev, &eventinfo);SMMUTransTableInfo *tt;if (!cfg) {
Signature · 1 line
2.41.0
[PULL 14/56] hw/arm/armv7m: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
hw/arm/armv7m.c: In function ‘armv7m_realize’:
hw/arm/armv7m.c:520:27: warning: declaration of ‘sbd’ shadows a previous local [-Wshadow=compatible-local]
520 | SysBusDevice *sbd = SYS_BUS_DEVICE(&s->bitband[i]);
| ^~~
hw/arm/armv7m.c:278:19: note: shadowed declaration is here
278 | SysBusDevice *sbd;
| ^~~
--- hw/arm/armsse.c: In function ‘armsse_realize’:
hw/arm/armsse.c:1471:27: warning: declaration of ‘mr’ shadows a previous local [-Wshadow=compatible-local]
1471 | MemoryRegion *mr;
| ^~
hw/arm/armsse.c:917:19: note: shadowed declaration is here
917 | MemoryRegion *mr;
| ^~
--- hw/arm/armsse.c:1608:22: warning: declaration of ‘dev_splitter’ shadows a previous local [-Wshadow=compatible-local]
1608 | DeviceState *dev_splitter = DEVICE(splitter);
| ^~~~~~~~~~~~
hw/arm/armsse.c:923:18: note: shadowed declaration is here
923 | DeviceState *dev_splitter;
| ^~~~~~~~~~~~Message-ID: <[email protected]>
--- hw/arm/armsse.c | 16 ++++++---------- hw/arm/armv7m.c | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-)
hw/arm/armsse.c +6 -10
@@ -1468,7 +1468,6 @@ static void armsse_realize(DeviceState *dev, Error **errp)if (info->has_cachectrl) {for (i =0 ; i < info->num_cpus; i++) {char *name =g_strdup_printf ("cachectrl%d" , i); -MemoryRegion *mr;qdev_prop_set_string (DEVICE (&s->cachectrl[i]),"name" , name);g_free (name);
@@ -1484,7 +1483,6 @@ static void armsse_realize(DeviceState *dev, Error **errp)if (info->has_cpusecctrl) {for (i =0 ; i < info->num_cpus; i++) {char *name =g_strdup_printf ("CPUSECCTRL%d" , i); -MemoryRegion *mr;qdev_prop_set_string (DEVICE (&s->cpusecctrl[i]),"name" , name);g_free (name);
@@ -1499,7 +1497,6 @@ static void armsse_realize(DeviceState *dev, Error **errp) }if (info->has_cpuid) {for (i =0 ; i < info->num_cpus; i++) { -MemoryRegion *mr;qdev_prop_set_uint32 (DEVICE (&s->cpuid[i]),"CPUID" , i);if (!sysbus_realize (SYS_BUS_DEVICE (&s->cpuid[i]), errp)) {
@@ -1512,7 +1509,6 @@ static void armsse_realize(DeviceState *dev, Error **errp) }if (info->has_cpu_pwrctrl) {for (i =0 ; i < info->num_cpus; i++) { -MemoryRegion *mr;if (!sysbus_realize (SYS_BUS_DEVICE (&s->cpu_pwrctrl[i]), errp)) {return ;
@@ -1605,7 +1601,7 @@ static void armsse_realize(DeviceState *dev, Error **errp)/* Wire up the splitters for the MPC IRQs */ for (i =0 ; i <IOTS_NUM_EXP_MPC + info->sram_banks; i++) {SplitIRQ *splitter = &s->mpc_irq_splitter[i]; -DeviceState *dev_splitter =DEVICE (splitter); +DeviceState *devs =DEVICE (splitter);if (!object_property_set_int (OBJECT (splitter),"num-lines" ,2 , errp)) {
@@ -1617,22 +1613,22 @@ static void armsse_realize(DeviceState *dev, Error **errp)if (i <IOTS_NUM_EXP_MPC ) {/* Splitter input is from GPIO input line */ - s->mpcexp_status_in[i] =qdev_get_gpio_in (dev_splitter,0 ); -qdev_connect_gpio_out (dev_splitter,0 , + s->mpcexp_status_in[i] =qdev_get_gpio_in (devs,0 ); +qdev_connect_gpio_out (devs,0 ,qdev_get_gpio_in_named (dev_secctl,"mpcexp_status" , i)); }else {/* Splitter input is from our own MPC */ qdev_connect_gpio_out_named (DEVICE (&s->mpc[i -IOTS_NUM_EXP_MPC ]),"irq" ,0 , -qdev_get_gpio_in (dev_splitter,0 )); -qdev_connect_gpio_out (dev_splitter,0 , +qdev_get_gpio_in (devs,0 )); +qdev_connect_gpio_out (devs,0 ,qdev_get_gpio_in_named (dev_secctl,"mpc_status" , i -IOTS_NUM_EXP_MPC )); } -qdev_connect_gpio_out (dev_splitter,1 , +qdev_connect_gpio_out (devs,1 ,qdev_get_gpio_in (DEVICE (&s->mpc_irq_orgate), i)); }/* Create GPIO inputs which will pass the line state for our
hw/arm/armv7m.c +1 -1
@@ -517,7 +517,7 @@ static void armv7m_realize(DeviceState *dev, Error **errp)for (i =0 ; i <ARRAY_SIZE (s->bitband); i++) {if (s->enable_bitband) {Object *obj =OBJECT (&s->bitband[i]); -SysBusDevice *sbd =SYS_BUS_DEVICE (&s->bitband[i]); + sbd =SYS_BUS_DEVICE (&s->bitband[i]);if (!object_property_set_int (obj,"base" , bitband_input_addr[i], errp)) {
Signature · 1 line
2.41.0
[PULL 44/56] aspeed: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Cédric Le Goater <[email protected]>
Remove superfluous local 'irq' variables and use the one define at the top of the routine. This fixes warnings in aspeed_soc_ast2600_realize() such as :
../hw/arm/aspeed_ast2600.c: In function ‘aspeed_soc_ast2600_realize’:
../hw/arm/aspeed_ast2600.c:420:18: warning: declaration of ‘irq’ shadows a previous local [-Wshadow=compatible-local]
420 | qemu_irq irq = aspeed_soc_get_irq(s, ASPEED_DEV_TIMER1 + i);
| ^~~
../hw/arm/aspeed_ast2600.c:312:14: note: shadowed declaration is here
312 | qemu_irq irq;
| ^~~Message-ID: <[email protected]>
--- hw/arm/aspeed_ast2600.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
hw/arm/aspeed_ast2600.c +5 -5
@@ -388,7 +388,7 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)aspeed_mmio_map (s,SYS_BUS_DEVICE (&s->timerctrl),0 , sc->memmap[ASPEED_DEV_TIMER1 ]);for (i =0 ; i <ASPEED_TIMER_NR_TIMERS ; i++) { -qemu_irq irq =aspeed_soc_get_irq (s,ASPEED_DEV_TIMER1 + i); + irq =aspeed_soc_get_irq (s,ASPEED_DEV_TIMER1 + i);sysbus_connect_irq (SYS_BUS_DEVICE (&s->timerctrl), i, irq); }
@@ -413,8 +413,8 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp) }aspeed_mmio_map (s,SYS_BUS_DEVICE (&s->i2c),0 , sc->memmap[ASPEED_DEV_I2C ]);for (i =0 ; i <ASPEED_I2C_GET_CLASS (&s->i2c)->num_busses; i++) { -qemu_irq irq =qdev_get_gpio_in (DEVICE (&s->a7mpcore), - sc->irqmap[ASPEED_DEV_I2C ] + i); + irq =qdev_get_gpio_in (DEVICE (&s->a7mpcore), + sc->irqmap[ASPEED_DEV_I2C ] + i);/* The AST2600 I2C controller has one IRQ per bus. */ sysbus_connect_irq (SYS_BUS_DEVICE (&s->i2c.busses[i]),0 , irq); }
@@ -611,8 +611,8 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp) }aspeed_mmio_map (s,SYS_BUS_DEVICE (&s->i3c),0 , sc->memmap[ASPEED_DEV_I3C ]);for (i =0 ; i <ASPEED_I3C_NR_DEVICES ; i++) { -qemu_irq irq =qdev_get_gpio_in (DEVICE (&s->a7mpcore), - sc->irqmap[ASPEED_DEV_I3C ] + i); + irq =qdev_get_gpio_in (DEVICE (&s->a7mpcore), + sc->irqmap[ASPEED_DEV_I3C ] + i);/* The AST2600 I3C controller has one IRQ per bus. */ sysbus_connect_irq (SYS_BUS_DEVICE (&s->i3c.devices[i]),0 , irq); }
Signature · 1 line
2.41.0
[PULL 30/56] pnv/psi: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Cédric Le Goater <[email protected]>
to fix :
../hw/ppc/pnv_psi.c: In function ‘pnv_psi_p9_mmio_write’:
../hw/ppc/pnv_psi.c:741:24: warning: declaration of ‘addr’ shadows a parameter [-Wshadow=compatible-local]
741 | hwaddr addr = val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K);
| ^~~~ ../hw/ppc/pnv_psi.c:702:56: note: shadowed declaration is here
702 | static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr,
| ~~~~~~~^~~~
Message-ID: <[email protected]>
--- hw/ppc/pnv_psi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/ppc/pnv_psi.c +3 -2
@@ -738,8 +738,9 @@ static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr, } }else {if (!(psi->regs[reg] &PSIHB9_ESB_CI_VALID )) { -hwaddr addr = val & ~(PSIHB9_ESB_CI_VALID |PSIHB10_ESB_CI_64K ); -memory_region_add_subregion (sysmem, addr, +hwaddr esb_addr = + val & ~(PSIHB9_ESB_CI_VALID |PSIHB10_ESB_CI_64K ); +memory_region_add_subregion (sysmem, esb_addr, &psi9->source.esb_mmio); } }
Signature · 1 line
2.41.0
[PULL 29/56] hw/ppc: Clean up local variable shadowing in _FDT helper routine
In reply to Markus ArmbrusterFrom: Cédric Le Goater <[email protected]>
this fixes numerous warnings of this type :
In file included from ../hw/ppc/spapr_pci.c:43:
../hw/ppc/spapr_pci.c: In function ‘spapr_dt_phb’:
../include/hw/ppc/fdt.h:18:13: warning: declaration of ‘ret’ shadows a previous local [-Wshadow=compatible-local]
18 | int ret = (exp); \
| ^~~
../hw/ppc/spapr_pci.c:2355:5: note: in expansion of macro ‘_FDT’
2355 | _FDT(bus_off = fdt_add_subnode(fdt, 0, phb->dtbusname));
| ^~~~ ../hw/ppc/spapr_pci.c:2311:24: note: shadowed declaration is here
2311 | int bus_off, i, j, ret;
| ^~~
Message-ID: <[email protected]>
--- include/hw/ppc/fdt.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
include/hw/ppc/fdt.h +4 -4
@@ -15,10 +15,10 @@#define _FDT (exp) \ do { \ - int ret = (exp); \ - if (ret < 0) { \ - error_report("error creating device tree: %s: %s", \ - #exp, fdt_strerror(ret)); \ + int _ret = (exp); \ + if (_ret < 0) { \ + error_report("error creating device tree: %s: %s", \ + #exp, fdt_strerror(_ret)); \ exit(1); \ } \ } while (0)
Signature · 1 line
2.41.0
[PULL 34/56] spapr/drc: Clean up local variable shadowing in rtas_ibm_configure_connector()
In reply to Markus ArmbrusterFrom: Cédric Le Goater <[email protected]>
Remove extra 'drc_index' variable to avoid this warning :
../hw/ppc/spapr_drc.c: In function ‘rtas_ibm_configure_connector’:
../hw/ppc/spapr_drc.c:1240:26: warning: declaration of ‘drc_index’ shadows a previous local [-Wshadow=compatible-local]
1240 | uint32_t drc_index = spapr_drc_index(drc);
| ^~~~~~~~~
../hw/ppc/spapr_drc.c:1155:14: note: shadowed declaration is here
1155 | uint32_t drc_index;
| ^~~~~~~~~Message-ID: <[email protected]>
--- hw/ppc/spapr_drc.c | 2 -- 1 file changed, 2 deletions(-)
hw/ppc/spapr_drc.c +0 -2
@@ -1237,8 +1237,6 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu,case FDT_END_NODE : drc->ccs_depth--;if (drc->ccs_depth ==0 ) { -uint32_t drc_index =spapr_drc_index (drc); -/* done sending the device tree, move to configured state */ trace_spapr_drc_set_configured (drc_index); drc->state = drck->ready_state;
Signature · 1 line
2.41.0
[PULL 35/56] spapr/pci: Clean up local variable shadowing in spapr_phb_realize()
In reply to Markus ArmbrusterFrom: Cédric Le Goater <[email protected]>
Rename SysBusDevice variable to avoid this warning :
../hw/ppc/spapr_pci.c: In function ‘spapr_phb_realize’:
../hw/ppc/spapr_pci.c:1872:24: warning: declaration of ‘s’ shadows a previous local [-Wshadow=local]
1872 | SpaprPhbState *s;
| ^
../hw/ppc/spapr_pci.c:1829:19: note: shadowed declaration is here
1829 | SysBusDevice *s = SYS_BUS_DEVICE(dev);
| ^
Message-ID: <[email protected]>
--- hw/ppc/spapr_pci.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/ppc/spapr_pci.c +3 -3
@@ -1826,9 +1826,9 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp) (SpaprMachineState *)object_dynamic_cast (qdev_get_machine (),TYPE_SPAPR_MACHINE );SpaprMachineClass *smc = spapr ?SPAPR_MACHINE_GET_CLASS (spapr) :NULL ; -SysBusDevice *s =SYS_BUS_DEVICE (dev); -SpaprPhbState *sphb =SPAPR_PCI_HOST_BRIDGE (s); -PCIHostState *phb =PCI_HOST_BRIDGE (s); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +SpaprPhbState *sphb =SPAPR_PCI_HOST_BRIDGE (sbd); +PCIHostState *phb =PCI_HOST_BRIDGE (sbd);MachineState *ms =MACHINE (spapr);char *namebuf;int i;
Signature · 1 line
2.41.0
[PULL 16/56] hw/arm/allwinner: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
hw/arm/allwinner-r40.c:412:14: error: declaration shadows a local variable [-Werror,-Wshadow]
for (int i = 0; i < AW_R40_NUM_MMCS; i++) {
^
hw/arm/allwinner-r40.c:299:14: note: previous declaration is here
unsigned i;
^Message-ID: <[email protected]>
--- hw/arm/allwinner-r40.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
hw/arm/allwinner-r40.c +3 -4
@@ -296,10 +296,9 @@ static void allwinner_r40_realize(DeviceState *dev, Error **errp) {const char *r40_nic_models[] = {"gmac" ,"emac" ,NULL };AwR40State *s =AW_R40 (dev); -unsigned i;/* CPUs */ -for (i =0 ; i <AW_R40_NUM_CPUS ; i++) { +for (unsigned i =0 ; i <AW_R40_NUM_CPUS ; i++) {/* * Disable secondary CPUs. Guest EL3 firmware will start
@@ -335,7 +334,7 @@ static void allwinner_r40_realize(DeviceState *dev, Error **errp)* maintenance interrupt signal to the appropriate GIC PPI inputs, * and the GIC's IRQ/FIQ/VIRQ/VFIQ interrupt outputs to the CPU's inputs. */ -for (i =0 ; i <AW_R40_NUM_CPUS ; i++) { +for (unsigned i =0 ; i <AW_R40_NUM_CPUS ; i++) {DeviceState *cpudev =DEVICE (&s->cpus[i]);int ppibase =AW_R40_GIC_NUM_SPI + i *GIC_INTERNAL +GIC_NR_SGIS ;int irq;
@@ -494,7 +493,7 @@ static void allwinner_r40_realize(DeviceState *dev, Error **errp) qdev_get_gpio_in(DEVICE(&s->gic), AW_R40_GIC_SPI_EMAC));/* Unimplemented devices */ -for (i =0 ; i <ARRAY_SIZE (r40_unimplemented); i++) { +for (unsigned i =0 ; i <ARRAY_SIZE (r40_unimplemented); i++) {create_unimplemented_device (r40_unimplemented[i].device_name, r40_unimplemented[i].base, r40_unimplemented[i].size);
Signature · 1 line
2.41.0
[PULL 20/56] net/eth: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
net/eth.c:435:20: error: declaration shadows a local variable [-Werror,-Wshadow]
size_t input_size = iov_size(pkt, pkt_frags);
^
net/eth.c:413:16: note: previous declaration is here
size_t input_size = iov_size(pkt, pkt_frags);
^Message-ID: <[email protected]>
--- net/eth.c | 2 -- 1 file changed, 2 deletions(-)
net/eth.c +0 -2
@@ -432,8 +432,6 @@ _eth_get_rss_ex_src_addr(const struct iovec *pkt, int pkt_frags, }if (opthdr.type ==IP6_OPT_HOME ) { -size_t input_size =iov_size (pkt, pkt_frags); -if (input_size < opt_offset +sizeof (opthdr)) {return false; }
Signature · 1 line
2.41.0
[PULL 11/56] target/mips: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Fix:
target/mips/tcg/nanomips_translate.c.inc:4410:33: error: declaration shadows a local variable [-Werror,-Wshadow]
int32_t imm = extract32(ctx->opcode, 1, 13) |
^
target/mips/tcg/nanomips_translate.c.inc:3577:9: note: previous declaration is here
int imm;
^
target/mips/tcg/translate.c:15578:19: error: declaration shadows a local variable [-Werror,-Wshadow]
for (unsigned i = 1; i < 32; i++) {
^
target/mips/tcg/translate.c:15567:9: note: previous declaration is here
int i;
^
target/mips/tcg/msa_helper.c:7478:13: error: declaration shadows a local variable [-Werror,-Wshadow]
MSA_FLOAT_MAXOP(pwx->w[0], min, pws->w[0], pws->w[0], 32);
^
target/mips/tcg/msa_helper.c:7434:23: note: expanded from macro 'MSA_FLOAT_MAXOP'
float_status *status = &env->active_tc.msa_fp_status;
^Message-ID: <[email protected]>
--- target/mips/tcg/msa_helper.c | 8 ++++---- target/mips/tcg/translate.c | 8 +++----- target/mips/tcg/nanomips_translate.c.inc | 6 +++--- 3 files changed, 10 insertions(+), 12 deletions(-)
target/mips/tcg/msa_helper.c +4 -4
@@ -7432,15 +7432,15 @@ void helper_msa_ftq_df(CPUMIPSState *env, uint32_t df, uint32_t wd,#define MSA_FLOAT_MAXOP (DEST ,OP ,ARG1 ,ARG2 ,BITS ) \ do { \ - float_status *status = &env->active_tc.msa_fp_status; \ + float_status *status_ = &env->active_tc.msa_fp_status; \ int c; \ \ - set_float_exception_flags(0, status); \ - DEST = float ## BITS ## _ ## OP(ARG1, ARG2, status); \ + set_float_exception_flags(0, status_); \ + DEST = float ## BITS ## _ ## OP(ARG1, ARG2, status_); \ c = update_msacsr(env, 0, 0); \ \ if (get_enabled_exceptions(env, c)) { \ - DEST = ((FLOAT_SNAN ## BITS(status) >> 6) << 6) | c; \ + DEST = ((FLOAT_SNAN ## BITS(status_) >> 6) << 6) | c; \ } \ } while (0)
target/mips/tcg/translate.c +3 -5
@@ -15564,10 +15564,8 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns,void mips_tcg_init (void ) { -int i; - cpu_gpr[0 ] =NULL ; -for (i =1 ; i <32 ; i++) +for (unsigned i =1 ; i <32 ; i++) cpu_gpr[i] =tcg_global_mem_new (cpu_env, offsetof(CPUMIPSState , active_tc.gpr[i]),
@@ -15584,7 +15582,7 @@ void mips_tcg_init(void) rname); }#endif /* !TARGET_MIPS64 */ -for (i =0 ; i <32 ; i++) { +for (unsigned i =0 ; i <32 ; i++) { int off = offsetof(CPUMIPSState, active_fpu.fpr[i].wr.d[0]); fpu_f64[i] =tcg_global_mem_new_i64 (cpu_env, off, fregnames[i]);
@@ -15592,7 +15590,7 @@ void mips_tcg_init(void)msa_translate_init (); cpu_PC =tcg_global_mem_new (cpu_env, offsetof(CPUMIPSState, active_tc.PC), "PC"); -for (i =0 ; i <MIPS_DSP_ACC ; i++) { +for (unsigned i =0 ; i <MIPS_DSP_ACC ; i++) { cpu_HI[i] =tcg_global_mem_new (cpu_env, offsetof(CPUMIPSState, active_tc.HI[i]), regnames_HI[i]);
target/mips/tcg/nanomips_translate.c.inc +3 -3
@@ -4407,8 +4407,8 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) case NM_BPOSGE32C: check_dsp_r3(ctx); { - int32_t imm = extract32(ctx->opcode, 1, 13) | - extract32(ctx->opcode, 0, 1) << 13; + imm = extract32(ctx->opcode, 1, 13) + | extract32(ctx->opcode, 0, 1) << 13; gen_compute_branch_nm(ctx, OPC_BPOSGE32, 4, -1, -2, imm << 1);
@@ -4635,7 +4635,7 @@ static int decode_isa_nanomips(CPUMIPSState *env, DisasContext *ctx) break; case NM_LI16: { - int imm = extract32(ctx->opcode, 0, 7); + imm = extract32(ctx->opcode, 0, 7); imm = (imm == 0x7f ? -1 : imm); if (rt != 0) { tcg_gen_movi_tl(cpu_gpr[rt], imm);
Signature · 1 line
2.41.0
[PULL 46/56] aspeed/timer: Clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Cédric Le Goater <[email protected]>
commit 8137355e850f ("aspeed/timer: Fix behaviour running Linux") introduced a MAX() expression to calculate the next timer deadline :
return calculate_time(t, MAX(MAX(t->match[0], t->match[1]), 0));
The second MAX() is not necessary since the compared values are an unsigned and 0. Simply remove it and fix warning :
../hw/timer/aspeed_timer.c: In function ‘calculate_next’:
../include/qemu/osdep.h:396:31: warning: declaration of ‘_a’ shadows a previous local [-Wshadow=compatible-local]
396 | typeof(1 ? (a) : (b)) _a = (a), _b = (b); \
| ^~
../hw/timer/aspeed_timer.c:170:12: note: in expansion of macro ‘MAX’
170 | next = MAX(MAX(calculate_match(t, 0), calculate_match(t, 1)), 0);
| ^~~
../hw/timer/aspeed_timer.c:170:16: note: in expansion of macro ‘MAX’
170 | next = MAX(MAX(calculate_match(t, 0), calculate_match(t, 1)), 0);
| ^~~
/home/legoater/work/qemu/qemu-aspeed.git/include/qemu/osdep.h:396:31: note: shadowed declaration is here
396 | typeof(1 ? (a) : (b)) _a = (a), _b = (b); \
| ^~
../hw/timer/aspeed_timer.c:170:12: note: in expansion of macro ‘MAX’
170 | next = MAX(MAX(calculate_match(t, 0), calculate_match(t, 1)), 0);
| ^~~Message-ID: <[email protected]>
--- hw/timer/aspeed_timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/timer/aspeed_timer.c +1 -1
@@ -167,7 +167,7 @@ static uint64_t calculate_next(struct AspeedTimer *t)qemu_set_irq (t->irq, t->level); } - next =MAX (MAX (calculate_match (t,0 ),calculate_match (t,1 )),0 ); + next =MAX (calculate_match (t,0 ),calculate_match (t,1 )); t->start =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );return calculate_time (t, next);
Signature · 1 line
2.41.0
[PULL 56/56] disas/m68k: clean up local variable shadowing
In reply to Markus ArmbrusterFrom: Laurent Vivier <[email protected]>
Fix following warnings
.../disas/m68k.c: In function ‘print_insn_arg’:.../disas/m68k.c:1635:13: warning: declaration of ‘val’ shadows a previous local [-Wshadow=compatible-local]
1635 | int val = fetch_arg (buffer, place, 5, info);
| ^~~.../disas/m68k.c:1093:7: note: shadowed declaration is here
1093 | int val = 0;
| ^~~Message-ID: <[email protected]>
--- disas/m68k.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
disas/m68k.c +4 -4
@@ -1632,10 +1632,10 @@ print_insn_arg (const char *d,case '2' :case '3' : { -int val =fetch_arg (buffer, place,5 , info); +int reg =fetch_arg (buffer, place,5 , info);const char *name =0 ; -switch (val) +switch (reg) {case 2 : name ="%tt0" ;break ;case 3 : name ="%tt1" ;break ;
@@ -1655,12 +1655,12 @@ print_insn_arg (const char *d,int break_reg = ((buffer[3 ] >>2 ) &7 ); (*info->fprintf_func) - (info->stream, val ==0x1c ?"%%bad%d" :"%%bac%d" , + (info->stream, reg ==0x1c ?"%%bad%d" :"%%bac%d" , break_reg); }break ;default : - (*info->fprintf_func) (info->stream,"<mmu register %d>" , val); + (*info->fprintf_func) (info->stream,"<mmu register %d>" , reg); }if (name) (*info->fprintf_func) (info->stream,"%s" , name);
Signature · 1 line
2.41.0
[PULL 53/56] target/riscv: vector_helper: Fixup local variables shadowing
In reply to Markus ArmbrusterFrom: Alistair Francis <[email protected]>
Local variables shadowing other local variables or parameters make the code needlessly hard to understand. Bugs love to hide in such code.
Evidence: "[PATCH v3 1/7] migration/rdma: Fix save_page method to fail on polling error".
This patch removes the local variable shadowing. Tested by adding:
--extra-cflags='-Wshadow=local -Wno-error=shadow=local -Wno-error=shadow=compatible-local'
To configure
Message-ID: <[email protected]>
--- target/riscv/vector_helper.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
target/riscv/vector_helper.c +4 -3
@@ -516,7 +516,7 @@ ProbeSuccess: k++;continue ; } -target_ulong addr = base + ((i * nf + k) << log2_esz); + addr = base + ((i * nf + k) << log2_esz);ldst_elem (env,adjust_addr (env, addr), i + k * max_elems, vd, ra); k++; }
@@ -4791,9 +4791,10 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, void *vs2, \uint32_t total_elems =vext_get_total_elems (env, desc, esz); \uint32_t vta =vext_vta (desc); \uint32_t vma =vext_vma (desc); \ -target_ulong i_max, i; \ +target_ulong i_max, i_min, i; \ \ - i_max =MAX (MIN (s1 < vlmax ? vlmax - s1 :0 , vl), env->vstart); \ + i_min =MIN (s1 < vlmax ? vlmax - s1 :0 , vl); \ + i_max =MAX (i_min, env->vstart); \for (i = env->vstart; i < i_max; ++i) { \if (!vm && !vext_elem_mask (v0, i)) { \/* set masked-off elements to 1s */ \
Signature · 1 line
2.41.0
[PULL 50/56] qemu-nbd: changes towards enabling -Wshadow=local
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
Address all compiler complaints from -Wshadow in qemu-nbd. Several instances of 'int ret' became shadows when commit 4fbec260 added 'ret' at a higher scope in main. More interesting was the 'void *ret' capturing the result of a pthread; where we were conceptually doing '(void*)(intptr_t)EXIT_FAILURE != NULL' which just feels wrong (even though it happens to compile correctly), so it was worth a better cleanup.
Message-ID: <[email protected]>
--- qemu-nbd.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
qemu-nbd.c +4 -5
@@ -939,7 +939,6 @@ int main(int argc, char **argv)g_autoptr (GError) err =NULL ;int stderr_fd[2 ];pid_t pid; -int ret;if (!g_unix_open_pipe (stderr_fd,FD_CLOEXEC , &err)) { error_report("Error setting up communication pipe: %s",
@@ -1172,7 +1171,6 @@ int main(int argc, char **argv)if (opts.device) {#if HAVE_NBD_DEVICE -int ret; ret =pthread_create (&client_thread,NULL , nbd_client_thread, &opts);if (ret !=0 ) {error_report ("Failed to create client thread: %s" ,strerror (ret));
@@ -1219,9 +1217,10 @@ int main(int argc, char **argv)qemu_opts_del (sn_opts);if (opts.device) { -void *ret; -pthread_join (client_thread, &ret); -exit (ret !=NULL ); +void *result; +pthread_join (client_thread, &result); + ret = (intptr_t )result; +exit (ret); }else {exit (EXIT_SUCCESS ); }
Signature · 1 line
2.41.0
[PULL 55/56] hw/nvme: Clean up local variable shadowing in nvme_ns_init()
In reply to Markus ArmbrusterFrom: Klaus Jensen <[email protected]>
Fix local variable shadowing in nvme_ns_init().
Message-ID: <[email protected]>
--- hw/nvme/ns.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/nvme/ns.c +2 -2
@@ -107,7 +107,7 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp) ns->pif = ns->params.pif; -static const NvmeLBAF lbaf[16 ] = { +static const NvmeLBAF defaults[16 ] = { [0 ] = { .ds =9 }, [1 ] = { .ds =9 , .ms =8 }, [2 ] = { .ds =9 , .ms =16 },
@@ -120,7 +120,7 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp) ns->nlbaf =8 ; -memcpy (&id_ns->lbaf, &lbaf,sizeof (lbaf)); +memcpy (&id_ns->lbaf, &defaults,sizeof (defaults));for (i =0 ; i < ns->nlbaf; i++) {NvmeLBAF *lbaf = &id_ns->lbaf[i];
Signature · 1 line
2.41.0
[PULL 40/56] hw/misc/arm_sysctl.c: Avoid shadowing local variable
In reply to Markus ArmbrusterFrom: Peter Maydell <[email protected]>
Avoid shadowing a local variable in arm_sysctl_write():
../../hw/misc/arm_sysctl.c: In function ‘arm_sysctl_write’:../../hw/misc/arm_sysctl.c:537:26: warning: declaration of ‘val’ shadows a parameter [-Wshadow=local]
537 | uint32_t val;
| ^~~../../hw/misc/arm_sysctl.c:388:39: note: shadowed declaration is here
388 | uint64_t val, unsigned size)
| ~~~~~~~~~^~~Message-ID: <[email protected]>
--- hw/misc/arm_sysctl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/misc/arm_sysctl.c +3 -3
@@ -534,12 +534,12 @@ static void arm_sysctl_write(void *opaque, hwaddr offset, s->sys_cfgstat |=2 ;/* error */ } }else { -uint32_t val; +uint32_t data;if (!vexpress_cfgctrl_read (s, dcc, function, site, position, - device, &val)) { + device, &data)) { s->sys_cfgstat |=2 ;/* error */ }else { - s->sys_cfgdata = val; + s->sys_cfgdata = data; } } }
Signature · 1 line
2.41.0
[PULL 51/56] hw/riscv: opentitan: Fixup local variables shadowing
In reply to Markus ArmbrusterFrom: Alistair Francis <[email protected]>
Local variables shadowing other local variables or parameters make the code needlessly hard to understand. Bugs love to hide in such code.
Evidence: "[PATCH v3 1/7] migration/rdma: Fix save_page method to fail on polling error".
This patch removes the local variable shadowing. Tested by adding:
--extra-cflags='-Wshadow=local -Wno-error=shadow=local -Wno-error=shadow=compatible-local'
To configure
Message-ID: <[email protected]>
--- hw/riscv/opentitan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/riscv/opentitan.c +1 -1
@@ -227,7 +227,7 @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp) IRQ_M_TIMER));/* SPI-Hosts */ -for (int i =0 ; i <OPENTITAN_NUM_SPI_HOSTS ; ++i) { +for (i =0 ; i <OPENTITAN_NUM_SPI_HOSTS ; ++i) { dev =DEVICE (&(s->spi_host[i]));if (!sysbus_realize (SYS_BUS_DEVICE (&s->spi_host[i]), errp)) {return ;
Signature · 1 line
2.41.0
[PULL 54/56] softmmu/device_tree: Fixup local variables shadowing
In reply to Markus ArmbrusterFrom: Alistair Francis <[email protected]>
Local variables shadowing other local variables or parameters make the code needlessly hard to understand. Bugs love to hide in such code.
Evidence: "[PATCH v3 1/7] migration/rdma: Fix save_page method to fail on polling error".
This patch removes the local variable shadowing. Tested by adding:
--extra-cflags='-Wshadow=local -Wno-error=shadow=local -Wno-error=shadow=compatible-local'
To configure
Message-ID: <[email protected]>
--- softmmu/device_tree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
softmmu/device_tree.c +3 -3
@@ -418,9 +418,9 @@ int qemu_fdt_setprop_string_array(void *fdt, const char *node_path, } p = str =g_malloc0 (total_len);for (i =0 ; i < len; i++) { -int len =strlen (array[i]) +1 ; -pstrcpy (p, len, array[i]); - p += len; +int offset =strlen (array[i]) +1 ; +pstrcpy (p, offset, array[i]); + p += offset; } ret =qemu_fdt_setprop (fdt, node_path, prop, str, total_len);
Signature · 1 line
2.41.0
[PULL 52/56] target/riscv: cpu: Fixup local variables shadowing
In reply to Markus ArmbrusterFrom: Alistair Francis <[email protected]>
Local variables shadowing other local variables or parameters make the code needlessly hard to understand. Bugs love to hide in such code.
Evidence: "[PATCH v3 1/7] migration/rdma: Fix save_page method to fail on polling error".
This patch removes the local variable shadowing. Tested by adding:
--extra-cflags='-Wshadow=local -Wno-error=shadow=local -Wno-error=shadow=compatible-local'
To configure
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/riscv/cpu.c +2 -2
@@ -704,7 +704,7 @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags) CSR_MPMMASK, }; -for (int i =0 ; i <ARRAY_SIZE (dump_csrs); ++i) { +for (i =0 ; i <ARRAY_SIZE (dump_csrs); ++i) {int csrno = dump_csrs[i];target_ulong val =0 ;RISCVException res =riscv_csrrw_debug (env, csrno, &val,0 ,0 );
@@ -747,7 +747,7 @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)CSR_VTYPE , CSR_VLENB, }; -for (int i =0 ; i <ARRAY_SIZE (dump_rvv_csrs); ++i) { +for (i =0 ; i <ARRAY_SIZE (dump_rvv_csrs); ++i) {int csrno = dump_rvv_csrs[i];target_ulong val =0 ;RISCVException res =riscv_csrrw_debug (env, csrno, &val,0 ,0 );
Signature · 1 line
2.41.0
[PULL 48/56] crypto: remove shadowed 'ret' variable
In reply to Markus ArmbrusterFrom: Daniel P. Berrangé <[email protected]>
Both instances of 'ret' are used to store a gnutls API return code.
Message-ID: <[email protected]>
--- crypto/tls-cipher-suites.c | 1 - 1 file changed, 1 deletion(-)
crypto/tls-cipher-suites.c +0 -1
@@ -52,7 +52,6 @@ GByteArray *qcrypto_tls_cipher_suites_get_data(QCryptoTLSCipherSuites *obj, byte_array =g_byte_array_new ();for (i =0 ;; i++) { -int ret;unsigned idx;const char *name;IANA_TLS_CIPHER cipher;
Signature · 1 line
2.41.0
[PULL 42/56] hw/arm/smmuv3-internal.h: Don't use locals in statement macros
In reply to Markus ArmbrusterFrom: Peter Maydell <[email protected]>
The STE_CTXPTR() and STE_S2TTB() macros both extract two halves of an address from fields in the STE and combine them into a single value to return. The current code for this uses a GCC statement expression. There are two problems with this:
(1) The type chosen for the variable in the statement expr is 'unsigned long', which might not be 64 bits
(2) the name chosen for the variable causes -Wshadow warnings because it's the same as a variable in use at the callsite:
In file included from ../../hw/arm/smmuv3.c:34:../../hw/arm/smmuv3.c: In function ‘smmu_get_cd’:../../hw/arm/smmuv3-internal.h:538:23: warning: declaration of ‘addr’ shadows a previous local [-Wshadow=compatible-local]
538 | unsigned long addr; \
| ^~~~../../hw/arm/smmuv3.c:339:23: note: in expansion of macro ‘STE_CTXPTR’
339 | dma_addr_t addr = STE_CTXPTR(ste);
| ^~~~~~~~~~../../hw/arm/smmuv3.c:339:16: note: shadowed declaration is here
339 | dma_addr_t addr = STE_CTXPTR(ste);
| ^~~~
Sidestep both of these problems by just using a single expression rather than a statement expr.
For CMD_ADDR, we got the type of the variable right but still run into -Wshadow problems:
In file included from ../../hw/arm/smmuv3.c:34:../../hw/arm/smmuv3.c: In function ‘smmuv3_range_inval’:../../hw/arm/smmuv3-internal.h:334:22: warning: declaration of ‘addr’ shadows a previous local [-Wshadow=compatible-local]
334 | uint64_t addr = high << 32 | (low << 12); \
| ^~~~../../hw/arm/smmuv3.c:1104:28: note: in expansion of macro ‘CMD_ADDR’
1104 | dma_addr_t end, addr = CMD_ADDR(cmd);
| ^~~~~~~~../../hw/arm/smmuv3.c:1104:21: note: shadowed declaration is here
1104 | dma_addr_t end, addr = CMD_ADDR(cmd);
| ^~~~
so convert it too.
CD_TTB has neither problem, but it is the only other macro in the file that uses this pattern, so we convert it also for consistency's sake.
We use extract64() rather than extract32() to avoid having to explicitly cast the result to uint64_t.
Message-ID: <[email protected]>
--- hw/arm/smmuv3-internal.h | 41 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 28 deletions(-)
hw/arm/smmuv3-internal.h +13 -28
@@ -328,12 +328,9 @@ enum { /* Command completion notification */#define CMD_TTL (x) extract32((x)->word[2], 8 , 2)#define CMD_TG (x) extract32((x)->word[2], 10, 2)#define CMD_STE_RANGE (x) extract32((x)->word[2], 0 , 5) -#define CMD_ADDR (x) ({ \ - uint64_t high = (uint64_t)(x)->word[3]; \ - uint64_t low = extract32((x)->word[2], 12, 20); \ - uint64_t addr = high << 32 | (low << 12); \ - addr; \ - }) +#define CMD_ADDR (x) \ + (((uint64_t)((x)->word[3]) << 32) | \ + ((extract64((x)->word[2], 12, 20)) << 12))#define SMMU_FEATURE_2LVL_STE (1 << 0)
@@ -533,21 +530,13 @@ typedef struct CD {#define STE_S2S (x) extract32((x)->word[5], 25, 1)#define STE_S2R (x) extract32((x)->word[5], 26, 1) -#define STE_CTXPTR (x) \ - ({ \ - unsigned long addr; \ - addr = (uint64_t)extract32((x)->word[1], 0, 16) << 32; \ - addr |= (uint64_t)((x)->word[0] & 0xffffffc0); \ - addr; \ - }) +#define STE_CTXPTR (x) \ + ((extract64((x)->word[1], 0, 16) << 32) | \ + ((x)->word[0] & 0xffffffc0)) -#define STE_S2TTB (x) \ - ({ \ - unsigned long addr; \ - addr = (uint64_t)extract32((x)->word[7], 0, 16) << 32; \ - addr |= (uint64_t)((x)->word[6] & 0xfffffff0); \ - addr; \ - }) +#define STE_S2TTB (x) \ + ((extract64((x)->word[7], 0, 16) << 32) | \ + ((x)->word[6] & 0xfffffff0))static inline int oas2bits (int oas_field) {
@@ -585,14 +574,10 @@ static inline int pa_range(STE *ste)#define CD_VALID (x) extract32((x)->word[0], 31, 1)#define CD_ASID (x) extract32((x)->word[1], 16, 16) -#define CD_TTB (x, sel) \ - ({ \ - uint64_t hi, lo; \ - hi = extract32((x)->word[(sel) * 2 + 3], 0, 19); \ - hi <<= 32; \ - lo = (x)->word[(sel) * 2 + 2] & ~0xfULL; \ - hi | lo; \ - }) +#define CD_TTB (x, sel) \ + ((extract64((x)->word[(sel) * 2 + 3], 0, 19) << 32) | \ + ((x)->word[(sel) * 2 + 2] & ~0xfULL)) +#define CD_HAD (x, sel) extract32((x)->word[(sel) * 2 + 2], 1, 1)#define CD_TSZ (x, sel) extract32((x)->word[0], (16 * (sel)) + 0, 6)
Signature · 1 line
2.41.0
Stefan Hajnoczi
AppliedApplied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/8.2 for any user-visible changes.