Commit f168046842 for qemu.org
commit f168046842c3cbcc3d02ff81e339de95ac714396
Author: Philippe Mathieu-Daudé <philmd@linaro.org>
Date: Wed Apr 15 23:09:57 2026 +0200
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>
diff --git a/block/blkio.c b/block/blkio.c
index 20f138a38c..fb8bec27d7 100644
--- a/block/blkio.c
+++ b/block/blkio.c
@@ -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;
diff --git a/block/gluster.c b/block/gluster.c
index 4fb25b2c6d..279f650241 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -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) {
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 6817a72e2e..3f285ff6c7 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -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) {
diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c
index 67d3e836eb..d3ce082e07 100644
--- a/hw/i386/xen/xen-hvm.c
+++ b/hw/i386/xen/xen-hvm.c
@@ -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)) {
diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c
index 7ba3240552..5fac1ec344 100644
--- a/hw/riscv/riscv-iommu.c
+++ b/hw/riscv/riscv-iommu.c
@@ -1678,7 +1678,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;
diff --git a/hw/vfio/cpr-legacy.c b/hw/vfio/cpr-legacy.c
index 033a546c30..c431d89973 100644
--- a/hw/vfio/cpr-legacy.c
+++ b/hw/vfio/cpr-legacy.c
@@ -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;
diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c
index 31c3113f8f..0b72a2cf5e 100644
--- a/hw/vfio/listener.c
+++ b/hw/vfio/listener.c
@@ -333,7 +333,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 &&
@@ -463,7 +463,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 &&
diff --git a/hw/xen/xen_pt_config_init.c b/hw/xen/xen_pt_config_init.c
index 3edaeab1e3..bbc82a2bcf 100644
--- a/hw/xen/xen_pt_config_init.c
+++ b/hw/xen/xen_pt_config_init.c
@@ -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;