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 Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> Message-Id: <20260415215539.92629-2-philmd@linaro.org>
Philippe Mathieu-Daudé committed
Apr 15, 2026 at 23:09 UTC
f168046842c3cbcc3d02ff81e339de95ac714396
8 files changed
+12
-12
block/blkio.c
+1
-1
@@ -124,7 +124,7 @@ blkio_do_alloc_bounce_buffer(BDRVBlkioState *s, BlkioBounceBuf *bounce,
124
int64_t bytes)
125
{
126
void *addr = s->bounce_pool.addr;
127
- BlkioBounceBuf *cur = NULL;
127
+ BlkioBounceBuf *cur;
128
BlkioBounceBuf *prev = NULL;
129
ptrdiff_t space;
130
block/gluster.c
+2
-2
@@ -251,7 +251,7 @@ static void glfs_set_preopened(const char *volume, glfs_t *fs)
251
252
static glfs_t *glfs_find_preopened(const char *volume)
253
{
254
- ListElement *entry = NULL;
254
+ ListElement *entry;
255
256
QLIST_FOREACH(entry, &glfs_list, list) {
257
if (strcmp(entry->saved.volume, volume) == 0) {
@@ -265,7 +265,7 @@ static glfs_t *glfs_find_preopened(const char *volume)
265
266
static void glfs_clear_preopened(glfs_t *fs)
267
{
268
- ListElement *entry = NULL;
268
+ ListElement *entry;
269
ListElement *next;
270
271
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,
146
{
147
int ecam_id = VIRT_ECAM_ID(vms->highmem_ecam);
148
bool cxl_present = false;
149
- PCIBus *bus = vms->bus;
149
+ PCIBus *bus;
150
bool acpi_pcihp = false;
151
152
if (vms->acpi_dev) {
hw/i386/xen/xen-hvm.c
+2
-2
@@ -184,7 +184,7 @@ static void xen_ram_init(PCMachineState *pcms,
184
static XenPhysmap *get_physmapping(hwaddr start_addr, ram_addr_t size,
185
int page_mask)
186
{
187
- XenPhysmap *physmap = NULL;
187
+ XenPhysmap *physmap;
188
189
start_addr &= page_mask;
190
@@ -200,7 +200,7 @@ static hwaddr xen_phys_offset_to_gaddr(hwaddr phys_offset, ram_addr_t size,
200
int page_mask)
201
{
202
hwaddr addr = phys_offset & page_mask;
203
- XenPhysmap *physmap = NULL;
203
+ XenPhysmap *physmap;
204
205
QLIST_FOREACH(physmap, &xen_physmap, list) {
206
if (range_covers_byte(physmap->phys_offset, physmap->size, addr)) {
hw/riscv/riscv-iommu.c
+1
-1
@@ -1678,7 +1678,7 @@ static void riscv_iommu_ats(RISCVIOMMUState *s,
1678
IOMMUAccessFlags perm,
1679
void (*trace_fn)(const char *id))
1680
{
1681
- RISCVIOMMUSpace *as = NULL;
1681
+ RISCVIOMMUSpace *as;
1682
IOMMUNotifier *n;
1683
IOMMUTLBEvent event;
1684
uint32_t pid;
hw/vfio/cpr-legacy.c
+1
-1
@@ -212,7 +212,7 @@ void vfio_legacy_cpr_unregister_container(VFIOLegacyContainer *container)
212
void vfio_cpr_giommu_remap(VFIOContainer *bcontainer,
213
MemoryRegionSection *section)
214
{
215
- VFIOGuestIOMMU *giommu = NULL;
215
+ VFIOGuestIOMMU *giommu;
216
hwaddr as_offset = section->offset_within_address_space;
217
hwaddr iommu_offset = as_offset - section->offset_within_region;
218
hw/vfio/listener.c
+2
-2
@@ -333,7 +333,7 @@ static void vfio_ram_discard_unregister_listener(VFIOContainer *bcontainer,
333
MemoryRegionSection *section)
334
{
335
RamDiscardManager *rdm = memory_region_get_ram_discard_manager(section->mr);
336
- VFIORamDiscardListener *vrdl = NULL;
336
+ VFIORamDiscardListener *vrdl;
337
338
QLIST_FOREACH(vrdl, &bcontainer->vrdl_list, next) {
339
if (vrdl->mr == section->mr &&
@@ -463,7 +463,7 @@ static void vfio_device_error_append(VFIODevice *vbasedev, Error **errp)
463
VFIORamDiscardListener *vfio_find_ram_discard_listener(
464
VFIOContainer *bcontainer, MemoryRegionSection *section)
465
{
466
- VFIORamDiscardListener *vrdl = NULL;
466
+ VFIORamDiscardListener *vrdl;
467
468
QLIST_FOREACH(vrdl, &bcontainer->vrdl_list, next) {
469
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)
62
/* find emulate register group entry */
63
XenPTRegGroup *xen_pt_find_reg_grp(XenPCIPassthroughState *s, uint32_t address)
64
{
65
- XenPTRegGroup *entry = NULL;
65
+ XenPTRegGroup *entry;
66
67
/* find register group entry */
68
QLIST_FOREACH(entry, &s->reg_grps, entries) {
@@ -80,7 +80,7 @@ XenPTRegGroup *xen_pt_find_reg_grp(XenPCIPassthroughState *s, uint32_t address)
80
/* find emulate register entry */
81
XenPTReg *xen_pt_find_reg(XenPTRegGroup *reg_grp, uint32_t address)
82
{
83
- XenPTReg *reg_entry = NULL;
83
+ XenPTReg *reg_entry;
84
XenPTRegInfo *reg = NULL;
85
uint32_t real_offset = 0;
86