cocci: Do not initialize variable used by *FOREACH*() macro
Subsystems (3)
cover cocci: Do not initialize variable used by *FOREACH*() macro
Most of our *FOREACH*() macros take a pointer argument, then assign it upon entry before iterating. Thus there is no need to initialize the variable used as argument. But sometimes we do, which is confusing (for example &first_cpu). This series uses a Coccinelle script to clean these unnecessary usages. (and 2 bonus cleanup patches at the end).
Philippe Mathieu-Daudé (8):
cocci: Do not initialize variable used by QLIST_FOREACH macro
cocci: Do not initialize variable used by QSLIST_FOREACH macro
cocci: Do not initialize variable used by QSIMPLEQ_FOREACH macro
cocci: Do not initialize variable used by QTAILQ_FOREACH macro
cocci: Do not initialize variable used by RAMBLOCK_FOREACH* macro
cocci: Do not initialize variable used by CPU_FOREACH macro target/mips: Reduce CPUState scope when used with CPU_FOREACH() target/riscv: Iterate vCPUs using CPU_FOREACH() macro
target/mips/internal.h | 11 ++++++----- block/blkdebug.c | 2 +- block/blkio.c | 2 +- block/gluster.c | 4 ++-- ebpf/ebpf.c | 2 +- hw/arm/virt-acpi-build.c | 2 +- hw/i386/xen/xen-hvm.c | 4 ++-- hw/misc/mips_cpc.c | 4 ++-- hw/ppc/spapr.c | 2 +- hw/ppc/spapr_events.c | 4 ++-- hw/riscv/boot.c | 9 +++++---- hw/riscv/riscv-iommu.c | 2 +- hw/vfio/cpr-legacy.c | 2 +- hw/vfio/listener.c | 4 ++-- hw/xen/xen_pt_config_init.c | 4 ++-- migration/block-dirty-bitmap.c | 2 +- migration/dirtyrate.c | 4 ++-- net/colo-compare.c | 4 ++-- net/net.c | 2 +- target/mips/tcg/system/cp0_helper.c | 28 ++++++++++++++++------------ target/mips/tcg/system/tlb_helper.c | 7 +++---- target/s390x/kvm/stsi-topology.c | 2 +- 22 files changed, 56 insertions(+), 51 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/8 cocci: Do not initialize variable used by QLIST_FOREACH macro
The QLIST_FOREACH() macro, defined in "qemu/queue.h", always assigns its iterator variable when entering the loop. Remove the pointless and possibly misleading assignment.
Mechanical patch using the following coccinelle spatch:
@@
type T;
identifier e;
iterator FOREACH_MACRO =~ ".*_FOREACH.*";
statement S;
@@
- T *e = ...;
+ T *e;
... when != e
FOREACH_MACRO(e, ...) S--- block/blkio.c | 2 +- block/gluster.c | 4 ++-- hw/arm/virt-acpi-build.c | 2 +- hw/i386/xen/xen-hvm.c | 4 ++-- hw/riscv/riscv-iommu.c | 2 +- hw/vfio/cpr-legacy.c | 2 +- hw/vfio/listener.c | 4 ++-- hw/xen/xen_pt_config_init.c | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-)
block/blkio.c +1 -1
@@ -124,7 +124,7 @@ blkio_do_alloc_bounce_buffer(BDRVBlkioState *s, BlkioBounceBuf *bounce, int64_t bytes) {void *addr = s->bounce_pool.addr; -BlkioBounceBuf *cur =NULL ; +BlkioBounceBuf *cur;BlkioBounceBuf *prev =NULL ;ptrdiff_t space;
block/gluster.c +2 -2
@@ -251,7 +251,7 @@ static void glfs_set_preopened(const char *volume, glfs_t *fs)static glfs_t *glfs_find_preopened (const char *volume) { -ListElement *entry =NULL ; +ListElement *entry; QLIST_FOREACH(entry, &glfs_list, list) {if (strcmp (entry->saved.volume, volume) ==0 ) {
@@ -265,7 +265,7 @@ static glfs_t *glfs_find_preopened(const char *volume)static void glfs_clear_preopened (glfs_t *fs) { -ListElement *entry =NULL ; +ListElement *entry;ListElement *next;if (fs ==NULL ) {
hw/arm/virt-acpi-build.c +1 -1
@@ -146,7 +146,7 @@ static void acpi_dsdt_add_pci(Aml *scope, const MemMapEntry *memmap, {int ecam_id =VIRT_ECAM_ID (vms->highmem_ecam);bool cxl_present = false; -PCIBus *bus = vms->bus; +PCIBus *bus;bool acpi_pcihp = false;if (vms->acpi_dev) {
hw/i386/xen/xen-hvm.c +2 -2
@@ -184,7 +184,7 @@ static void xen_ram_init(PCMachineState *pcms,static XenPhysmap *get_physmapping (hwaddr start_addr,ram_addr_t size,int page_mask) { -XenPhysmap *physmap =NULL ; +XenPhysmap *physmap; start_addr &= page_mask;
@@ -200,7 +200,7 @@ static hwaddr xen_phys_offset_to_gaddr(hwaddr phys_offset, ram_addr_t size, int page_mask) {hwaddr addr = phys_offset & page_mask; -XenPhysmap *physmap =NULL ; +XenPhysmap *physmap; QLIST_FOREACH(physmap, &xen_physmap, list) {if (range_covers_byte (physmap->phys_offset, physmap->size, addr)) {
hw/riscv/riscv-iommu.c +1 -1
@@ -1681,7 +1681,7 @@ static void riscv_iommu_ats(RISCVIOMMUState *s,IOMMUAccessFlags perm, void (*trace_fn)(const char *id)) { - RISCVIOMMUSpace *as = NULL; + RISCVIOMMUSpace *as;IOMMUNotifier *n;IOMMUTLBEvent event;uint32_t pid;
hw/vfio/cpr-legacy.c +1 -1
@@ -212,7 +212,7 @@ void vfio_legacy_cpr_unregister_container(VFIOLegacyContainer *container)void vfio_cpr_giommu_remap (VFIOContainer *bcontainer,MemoryRegionSection *section) { -VFIOGuestIOMMU *giommu =NULL ; +VFIOGuestIOMMU *giommu;hwaddr as_offset = section->offset_within_address_space;hwaddr iommu_offset = as_offset - section->offset_within_region;
hw/vfio/listener.c +2 -2
@@ -337,7 +337,7 @@ static void vfio_ram_discard_unregister_listener(VFIOContainer *bcontainer, MemoryRegionSection *section) {RamDiscardManager *rdm =memory_region_get_ram_discard_manager (section->mr); -VFIORamDiscardListener *vrdl =NULL ; +VFIORamDiscardListener *vrdl; QLIST_FOREACH(vrdl, &bcontainer->vrdl_list, next) { if (vrdl->mr == section->mr &&
@@ -467,7 +467,7 @@ static void vfio_device_error_append(VFIODevice *vbasedev, Error **errp)VFIORamDiscardListener *vfio_find_ram_discard_listener (VFIOContainer *bcontainer,MemoryRegionSection *section) { -VFIORamDiscardListener *vrdl =NULL ; +VFIORamDiscardListener *vrdl; QLIST_FOREACH(vrdl, &bcontainer->vrdl_list, next) { if (vrdl->mr == section->mr &&
hw/xen/xen_pt_config_init.c +2 -2
@@ -62,7 +62,7 @@ static int xen_pt_hide_dev_cap(const XenHostPCIDevice *d, uint8_t grp_id)/* find emulate register group entry */ XenPTRegGroup *xen_pt_find_reg_grp (XenPCIPassthroughState *s,uint32_t address) { -XenPTRegGroup *entry =NULL ; +XenPTRegGroup *entry;/* find register group entry */ QLIST_FOREACH(entry, &s->reg_grps, entries) {
@@ -80,7 +80,7 @@ XenPTRegGroup *xen_pt_find_reg_grp(XenPCIPassthroughState *s, uint32_t address)/* find emulate register entry */ XenPTReg *xen_pt_find_reg (XenPTRegGroup *reg_grp,uint32_t address) { -XenPTReg *reg_entry =NULL ; +XenPTReg *reg_entry;XenPTRegInfo *reg =NULL ;uint32_t real_offset =0 ;
Signature · 1 line
2.53.0
PATCH 2/8 cocci: Do not initialize variable used by QSLIST_FOREACH macro
In reply to Philippe Mathieu-DaudéThe QSLIST_FOREACH() macro, defined in "qemu/queue.h", always assigns its iterator variable when entering the loop. Remove the pointless and possibly misleading assignment.
Mechanical patch using the following coccinelle spatch:
@@
type T;
identifier e;
iterator FOREACH_MACRO =~ ".*_FOREACH.*";
statement S;
@@
- T *e = ...;
+ T *e;
... when != e
FOREACH_MACRO(e, ...) S--- ebpf/ebpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ebpf/ebpf.c +1 -1
@@ -40,7 +40,7 @@ void ebpf_register_binary_data(int id, const void *data, size_t datalen)const void *ebpf_find_binary_by_id (int id,size_t *sz,Error **errp) { -struct ElfBinaryDataEntry *it =NULL ; +struct ElfBinaryDataEntry *it; QSLIST_FOREACH(it, &ebpf_elf_obj_list, node) {if (id == it->id) { *sz = it->datalen;
Signature · 1 line
2.53.0
PATCH 3/8 cocci: Do not initialize variable used by QSIMPLEQ_FOREACH macro
In reply to Philippe Mathieu-DaudéThe QSIMPLEQ_FOREACH() macro, defined in "qemu/queue.h", always assigns its iterator variable when entering the loop. Remove the pointless and possibly misleading assignment.
Mechanical patch using the following coccinelle spatch:
@@
type T;
identifier e;
iterator FOREACH_MACRO =~ ".*_FOREACH.*";
statement S;
@@
- T *e = ...;
+ T *e;
... when != e
FOREACH_MACRO(e, ...) S--- block/blkdebug.c | 2 +- migration/block-dirty-bitmap.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
block/blkdebug.c +1 -1
@@ -591,7 +591,7 @@ static int coroutine_fn rule_check(BlockDriverState *bs, uint64_t offset, uint64_t bytes, BlkdebugIOType iotype) {BDRVBlkdebugState *s = bs->opaque; -BlkdebugRule *rule =NULL ; +BlkdebugRule *rule;int error;bool immediately;
migration/block-dirty-bitmap.c +1 -1
@@ -1216,7 +1216,7 @@ fail:static int dirty_bitmap_save_setup (QEMUFile *f,void *opaque,Error **errp) {DBMSaveState *s = &((DBMState *)opaque)->save; -SaveBitmapState *dbms =NULL ; +SaveBitmapState *dbms;if (init_dirty_bitmap_migration (s, errp) <0 ) {return -1 ;
Signature · 1 line
2.53.0
PATCH 4/8 cocci: Do not initialize variable used by QTAILQ_FOREACH macro
In reply to Philippe Mathieu-DaudéThe QTAILQ_FOREACH() macro, defined in "qemu/queue.h", always assigns its iterator variable when entering the loop. Remove the pointless and possibly misleading assignment.
Mechanical patch using the following coccinelle spatch:
@@
type T;
identifier e;
iterator FOREACH_MACRO =~ ".*_FOREACH.*";
statement S;
@@
- T *e = ...;
+ T *e;
... when != e
FOREACH_MACRO(e, ...) S--- hw/ppc/spapr.c | 2 +- hw/ppc/spapr_events.c | 4 ++-- net/colo-compare.c | 4 ++-- net/net.c | 2 +- target/s390x/kvm/stsi-topology.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-)
hw/ppc/spapr.c +1 -1
@@ -3685,7 +3685,7 @@ struct SpaprDimmState {static SpaprDimmState *spapr_pending_dimm_unplugs_find (SpaprMachineState *s,PCDIMMDevice *dimm) { -SpaprDimmState *dimm_state =NULL ; +SpaprDimmState *dimm_state; QTAILQ_FOREACH(dimm_state, &s->pending_dimm_unplugs, next) {if (dimm_state->dimm == dimm) {
hw/ppc/spapr_events.c +2 -2
@@ -460,7 +460,7 @@ static void rtas_event_log_queue(SpaprMachineState *spapr,static SpaprEventLogEntry *rtas_event_log_dequeue (SpaprMachineState *spapr,uint32_t event_mask) { -SpaprEventLogEntry *entry =NULL ; +SpaprEventLogEntry *entry; QTAILQ_FOREACH(entry, &spapr->pending_events, next) { const SpaprEventSource *source =
@@ -482,7 +482,7 @@ static SpaprEventLogEntry *rtas_event_log_dequeue(SpaprMachineState *spapr,static bool rtas_event_log_contains (SpaprMachineState *spapr,uint32_t event_mask) { -SpaprEventLogEntry *entry =NULL ; +SpaprEventLogEntry *entry; QTAILQ_FOREACH(entry, &spapr->pending_events, next) { const SpaprEventSource *source =
net/colo-compare.c +2 -2
@@ -1396,7 +1396,7 @@ static void colo_compare_init(Object *obj)void colo_compare_cleanup (void ) { -CompareState *tmp =NULL ; +CompareState *tmp;CompareState *n =NULL ; QTAILQ_FOREACH_SAFE(tmp, &net_compares, next, n) {
@@ -1407,7 +1407,7 @@ void colo_compare_cleanup(void)static void colo_compare_finalize (Object *obj) {CompareState *s =COLO_COMPARE (obj); -CompareState *tmp =NULL ; +CompareState *tmp;qemu_mutex_lock (&colo_compare_mutex); QTAILQ_FOREACH(tmp, &net_compares, next) {
net/net.c +1 -1
@@ -653,7 +653,7 @@ static ssize_t filter_receive_iov(NetClientState *nc, NetPacketSent *sent_cb) {ssize_t ret =0 ; -NetFilterState *nf =NULL ; +NetFilterState *nf;if (direction ==NET_FILTER_DIRECTION_TX ) { QTAILQ_FOREACH(nf, &nc->filters, next) {
target/s390x/kvm/stsi-topology.c +1 -1
@@ -285,7 +285,7 @@ static void s390_topology_fill_list_sorted(S390TopologyList *topology_list)*/ static void s390_topology_empty_list (S390TopologyList *topology_list) { -S390TopologyEntry *entry =NULL ; +S390TopologyEntry *entry;S390TopologyEntry *tmp =NULL ; QTAILQ_FOREACH_SAFE(entry, topology_list, next, tmp) {
Signature · 1 line
2.53.0
PATCH 5/8 cocci: Do not initialize variable used by RAMBLOCK_FOREACH* macro
In reply to Philippe Mathieu-DaudéThe RAMBLOCK_FOREACH_MIGRATABLE() macro, defined in migration/ram.h, ends up calling QLIST_FOREACH_RCU() which always assigns its iterator variable when entering the loop. Remove the pointless and possibly misleading assignment.
Mechanical patch using the following coccinelle spatch:
@@
type T;
identifier e;
iterator FOREACH_MACRO =~ ".*_FOREACH.*";
statement S;
@@
- T *e = ...;
+ T *e;
... when != e
FOREACH_MACRO(e, ...) S--- migration/dirtyrate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
migration/dirtyrate.c +2 -2
@@ -485,7 +485,7 @@ static bool record_ramblock_hash_info(struct RamblockDirtyInfo **block_dinfo, {struct RamblockDirtyInfo *info =NULL ;struct RamblockDirtyInfo *dinfo =NULL ; -RAMBlock *block =NULL ; +RAMBlock *block;int total_count =0 ;int index =0 ;bool ret = false;
@@ -568,7 +568,7 @@ static bool compare_page_hash_info(struct RamblockDirtyInfo *info, int block_count) {struct RamblockDirtyInfo *block_dinfo =NULL ; -RAMBlock *block =NULL ; +RAMBlock *block;RAMBLOCK_FOREACH_MIGRATABLE (block) {if (skip_sample_ramblock (block)) {
Signature · 1 line
2.53.0
PATCH 6/8 cocci: Do not initialize variable used by CPU_FOREACH macro
In reply to Philippe Mathieu-DaudéThe CPU_FOREACH() macro, defined in "hw/core/cpu.h", ends up calling QTAILQ_FOREACH_RCU() which always assigns its iterator variable when entering the loop. Remove the pointless and possibly misleading assignment.
Mechanical patch using the following coccinelle spatch:
@@
type T;
identifier e;
iterator FOREACH_MACRO =~ ".*_FOREACH.*"; statement S;
@@
- T *e = ...;
+ T *e;
... when != e
FOREACH_MACRO(e, ...) S--- target/mips/internal.h | 2 +- hw/misc/mips_cpc.c | 4 ++-- target/mips/tcg/system/cp0_helper.c | 8 ++++---- target/mips/tcg/system/tlb_helper.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-)
target/mips/internal.h +1 -1
@@ -279,7 +279,7 @@ static inline int mips_vpe_active(CPUMIPSState *env)static inline int mips_vp_active (CPUMIPSState *env) { -CPUState *other_cs = first_cpu; +CPUState *other_cs;/* Check if the VP disabled other VPs (which means the VP is enabled) */ if ((env->CP0_VPControl >> CP0VPCtl_DIS) &1 ) {
hw/misc/mips_cpc.c +2 -2
@@ -44,7 +44,7 @@ static void mips_cpu_reset_async_work(CPUState *cs, run_on_cpu_data data)static void cpc_run_vp (MIPSCPCState *cpc,uint64_t vp_run) { -CPUState *cs = first_cpu; +CPUState *cs;CPU_FOREACH (cs) {uint64_t i =1ULL << cs->cpu_index;
@@ -62,7 +62,7 @@ static void cpc_run_vp(MIPSCPCState *cpc, uint64_t vp_run)static void cpc_stop_vp (MIPSCPCState *cpc,uint64_t vp_stop) { -CPUState *cs = first_cpu; +CPUState *cs;CPU_FOREACH (cs) {uint64_t i =1ULL << cs->cpu_index;
target/mips/tcg/system/cp0_helper.c +4 -4
@@ -1559,7 +1559,7 @@ target_ulong helper_emt(void)target_ulong helper_dvpe (CPUMIPSState *env) { -CPUState *other_cs = first_cpu; +CPUState *other_cs;target_ulong prev = env->mvp->CP0_MVPControl;if (env->CP0_VPEConf0 & (1 <<CP0VPEC0_MVP )) {
@@ -1577,7 +1577,7 @@ target_ulong helper_dvpe(CPUMIPSState *env)target_ulong helper_evpe (CPUMIPSState *env) { -CPUState *other_cs = first_cpu; +CPUState *other_cs;target_ulong prev = env->mvp->CP0_MVPControl;if (env->CP0_VPEConf0 & (1 <<CP0VPEC0_MVP )) {
@@ -1599,7 +1599,7 @@ target_ulong helper_evpe(CPUMIPSState *env)/* R6 Multi-threading */ target_ulong helper_dvp (CPUMIPSState *env) { -CPUState *other_cs = first_cpu; +CPUState *other_cs;target_ulong prev = env->CP0_VPControl;if (!((env->CP0_VPControl >> CP0VPCtl_DIS) &1 )) {
@@ -1617,7 +1617,7 @@ target_ulong helper_dvp(CPUMIPSState *env)target_ulong helper_evp (CPUMIPSState *env) { -CPUState *other_cs = first_cpu; +CPUState *other_cs;target_ulong prev = env->CP0_VPControl;if ((env->CP0_VPControl >> CP0VPCtl_DIS) &1 ) {
target/mips/tcg/system/tlb_helper.c +1 -1
@@ -346,7 +346,7 @@ void helper_ginvt(CPUMIPSState *env, target_ulong arg, uint32_t type)uint32_t invMsgVPN2 = arg & (TARGET_PAGE_MASK <<1 );uint8_t invMsgR =0 ;uint32_t invMsgMMid = env->CP0_MemoryMapID; -CPUState *other_cs = first_cpu; +CPUState *other_cs;#ifdef TARGET_MIPS64 invMsgR =extract64 (arg,62 ,2 );
Signature · 1 line
2.53.0
PATCH 7/8 target/mips: Reduce CPUState scope when used with CPU_FOREACH()
In reply to Philippe Mathieu-DaudéWhen possible, reduce CPUState variable scope.
Prefer cpu_env(cpu) over &cpu->env.
--- target/mips/internal.h | 11 ++++++----- target/mips/tcg/system/cp0_helper.c | 28 ++++++++++++++++------------ target/mips/tcg/system/tlb_helper.c | 7 +++---- 3 files changed, 25 insertions(+), 21 deletions(-)
target/mips/internal.h +6 -5
@@ -279,7 +279,7 @@ static inline int mips_vpe_active(CPUMIPSState *env)static inline int mips_vp_active (CPUMIPSState *env) { -CPUState *other_cs; +CPUState *cs;/* Check if the VP disabled other VPs (which means the VP is enabled) */ if ((env->CP0_VPControl >> CP0VPCtl_DIS) &1 ) {
@@ -287,10 +287,11 @@ static inline int mips_vp_active(CPUMIPSState *env) }/* Check if the virtual processor is disabled due to a DVP */ -CPU_FOREACH (other_cs) { -MIPSCPU *other_cpu =MIPS_CPU (other_cs); -if ((&other_cpu->env != env) && - ((other_cpu->env.CP0_VPControl >> CP0VPCtl_DIS) &1 )) { +CPU_FOREACH (cs) { +CPUMIPSState *other_env =cpu_env (cs); + +if ((other_env != env) && + ((other_env->CP0_VPControl >> CP0VPCtl_DIS) &1 )) {return 0 ; } }
target/mips/tcg/system/cp0_helper.c +16 -12
@@ -1559,12 +1559,13 @@ target_ulong helper_emt(void)target_ulong helper_dvpe (CPUMIPSState *env) { -CPUState *other_cs;target_ulong prev = env->mvp->CP0_MVPControl;if (env->CP0_VPEConf0 & (1 <<CP0VPEC0_MVP )) { -CPU_FOREACH (other_cs) { -MIPSCPU *other_cpu =MIPS_CPU (other_cs); +CPUState *cpu; + +CPU_FOREACH (cpu) { +MIPSCPU *other_cpu =MIPS_CPU (cpu);/* Turn off all VPEs except the one executing the dvpe. */ if (&other_cpu->env != env) { other_cpu->env.mvp->CP0_MVPControl &= ~(1 << CP0MVPCo_EVP);
@@ -1577,12 +1578,13 @@ target_ulong helper_dvpe(CPUMIPSState *env)target_ulong helper_evpe (CPUMIPSState *env) { -CPUState *other_cs;target_ulong prev = env->mvp->CP0_MVPControl;if (env->CP0_VPEConf0 & (1 <<CP0VPEC0_MVP )) { -CPU_FOREACH (other_cs) { -MIPSCPU *other_cpu =MIPS_CPU (other_cs); +CPUState *cpu; + +CPU_FOREACH (cpu) { +MIPSCPU *other_cpu =MIPS_CPU (cpu);if (&other_cpu->env != env /* If the VPE is WFI, don't disturb its sleep. */
@@ -1599,12 +1601,13 @@ target_ulong helper_evpe(CPUMIPSState *env)/* R6 Multi-threading */ target_ulong helper_dvp (CPUMIPSState *env) { -CPUState *other_cs;target_ulong prev = env->CP0_VPControl;if (!((env->CP0_VPControl >> CP0VPCtl_DIS) &1 )) { -CPU_FOREACH (other_cs) { -MIPSCPU *other_cpu =MIPS_CPU (other_cs); +CPUState *cpu; + +CPU_FOREACH (cpu) { +MIPSCPU *other_cpu =MIPS_CPU (cpu);/* Turn off all VPs except the one executing the dvp. */ if (&other_cpu->env != env) {mips_vpe_sleep (other_cpu);
@@ -1617,12 +1620,13 @@ target_ulong helper_dvp(CPUMIPSState *env)target_ulong helper_evp (CPUMIPSState *env) { -CPUState *other_cs;target_ulong prev = env->CP0_VPControl;if ((env->CP0_VPControl >> CP0VPCtl_DIS) &1 ) { -CPU_FOREACH (other_cs) { -MIPSCPU *other_cpu =MIPS_CPU (other_cs); +CPUState *cpu; + +CPU_FOREACH (cpu) { +MIPSCPU *other_cpu =MIPS_CPU (cpu);if ((&other_cpu->env != env) && !mips_vp_is_wfi (other_cpu)) {/* * If the VP is WFI, don't disturb its sleep.
target/mips/tcg/system/tlb_helper.c +3 -4
@@ -346,15 +346,14 @@ void helper_ginvt(CPUMIPSState *env, target_ulong arg, uint32_t type)uint32_t invMsgVPN2 = arg & (TARGET_PAGE_MASK <<1 );uint8_t invMsgR =0 ;uint32_t invMsgMMid = env->CP0_MemoryMapID; -CPUState *other_cs; +CPUState *cpu;#ifdef TARGET_MIPS64 invMsgR =extract64 (arg,62 ,2 );#endif -CPU_FOREACH (other_cs) { -MIPSCPU *other_cpu =MIPS_CPU (other_cs); -global_invalidate_tlb (&other_cpu->env, invMsgVPN2, invMsgR, invMsgMMid, +CPU_FOREACH (cpu) { +global_invalidate_tlb (cpu_env (cpu), invMsgVPN2, invMsgR, invMsgMMid, invAll, invVAMMid, invMMid, invVA); } }
Signature · 1 line
2.53.0
PATCH 8/8 target/riscv: Iterate vCPUs using CPU_FOREACH() macro
In reply to Philippe Mathieu-DaudéMost code iterates over vCPUs using the CPU_FOREACH() macro. Prefer cpu_env(cpu) over &cpu->env.
--- hw/riscv/boot.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
hw/riscv/boot.c +5 -4
@@ -490,10 +490,11 @@ void riscv_setup_direct_kernel(hwaddr kernel_addr, hwaddr fdt_addr) {CPUState *cs; -for (cs = first_cpu; cs; cs =CPU_NEXT (cs)) { -RISCVCPU *riscv_cpu =RISCV_CPU (cs); - riscv_cpu->env.kernel_addr = kernel_addr; - riscv_cpu->env.fdt_addr = fdt_addr; +CPU_FOREACH (cs) { +CPURISCVState *env =cpu_env (cs); + + env->kernel_addr = kernel_addr; + env->fdt_addr = fdt_addr; } }
Signature · 1 line
2.53.0
Quoted 33 lines · Philippe Mathieu-Daudé
Most of our *FOREACH*() macros take a pointer argument, then assign it upon entry before iterating. Thus there is no need to initialize the variable used as argument. But sometimes we do, which is confusing (for example
&first_cpu). This series uses a Coccinelle script to clean these unnecessary usages. (and 2 bonus cleanup patches at the end).Philippe Mathieu-Daudé (8):
cocci: Do not initialize variable used byQLIST_FOREACHmacro
cocci: Do not initialize variable used byQSLIST_FOREACHmacro
cocci: Do not initialize variable used byQSIMPLEQ_FOREACHmacro
cocci: Do not initialize variable used byQTAILQ_FOREACHmacro
cocci: Do not initialize variable used by RAMBLOCK_FOREACH* macro
cocci: Do not initialize variable used byCPU_FOREACHmacro target/mips: Reduce CPUState scope when used withCPU_FOREACH()target/riscv: Iterate vCPUs usingCPU_FOREACH()macrotarget/mips/internal.h | 11 ++++++----- block/blkdebug.c | 2 +- block/blkio.c | 2 +- block/gluster.c | 4 ++-- ebpf/ebpf.c | 2 +- hw/arm/virt-acpi-build.c | 2 +- hw/i386/xen/xen-hvm.c | 4 ++-- hw/misc/mips_cpc.c | 4 ++-- hw/ppc/spapr.c | 2 +- hw/ppc/spapr_events.c | 4 ++-- hw/riscv/boot.c | 9 +++++---- hw/riscv/riscv-iommu.c | 2 +- hw/vfio/cpr-legacy.c | 2 +- hw/vfio/listener.c | 4 ++-- hw/xen/xen_pt_config_init.c | 4 ++--
Quoted 9 lines
migration/block-dirty-bitmap.c | 2 +- migration/dirtyrate.c | 4 ++-- net/colo-compare.c | 4 ++-- net/net.c | 2 +- target/mips/tcg/system/cp0_helper.c | 28 ++++++++++++++++------------ target/mips/tcg/system/tlb_helper.c | 7 +++---- target/s390x/kvm/stsi-topology.c | 2 +- 22 files changed, 56 insertions(+), 51 deletions(-)
For the series:
Quoted 9 lines
Philippe Mathieu-Daudé (8):
cocci: Do not initialize variable used byQLIST_FOREACHmacro
cocci: Do not initialize variable used byQSLIST_FOREACHmacro
cocci: Do not initialize variable used byQSIMPLEQ_FOREACHmacro
cocci: Do not initialize variable used byQTAILQ_FOREACHmacro
cocci: Do not initialize variable used by RAMBLOCK_FOREACH* macro
cocci: Do not initialize variable used byCPU_FOREACHmacro target/mips: Reduce CPUState scope when used withCPU_FOREACH()target/riscv: Iterate vCPUs usingCPU_FOREACH()macro
Series queued, thanks.