hw/i386: changes towards enabling -Wshadow=local for x86 machines
PATCH v3 1/1 hw/i386: changes towards enabling -Wshadow=local for x86 machines
Code changes 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]
--- hw/i386/acpi-microvm.c | 4 ++-- hw/i386/pc.c | 1 - hw/i386/x86.c | 2 -- 3 files changed, 2 insertions(+), 5 deletions(-)
changelog:
v3: split the patches. Peter's changes are now in a seperate patch.
Addressed mst's suggestions. Removed message-ID
from commit log and added the reference to previous discussion thread
explicitly.
v2: kept Peter's changes from https://lore.kernel.org/r/[email protected]
and removed mine.
hw/i386/acpi-microvm.c +2 -2
@@ -55,8 +55,8 @@ static void acpi_dsdt_add_virtio(Aml *scope, bus =sysbus_get_default (); QTAILQ_FOREACH(kid, &bus->children, sibling) { -DeviceState *dev = kid->child; -Object *obj =object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MMIO ); +Object *obj =object_dynamic_cast (OBJECT (kid->child), +TYPE_VIRTIO_MMIO );if (obj) {VirtIOMMIOProxy *mmio =VIRTIO_MMIO (obj);
hw/i386/pc.c +0 -1
@@ -1116,7 +1116,6 @@ void pc_memory_init(PCMachineState *pcms,if (machine->device_memory) {uint64_t *val =g_malloc (sizeof (*val)); -PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);uint64_t res_mem_end = machine->device_memory->base;if (!pcmc->broken_reserved_end) {
hw/i386/x86.c +0 -2
@@ -365,8 +365,6 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, cpu_slot =x86_find_cpu_slot (MACHINE (x86ms), cpu->apic_id, &idx);if (!cpu_slot) { -MachineState *ms =MACHINE (x86ms); -x86_topo_ids_from_apicid (cpu->apic_id, &topo_info, &topo_ids);error_setg (errp, "Invalid CPU [socket: %u, die: %u, core: %u, thread: %u] with"
Signature · 1 line
2.42.0
Quoted 11 lines · Ani Sinha
Code changes 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]
Quoted 7 lines
CC Markus Armbruster <[email protected]>CC Philippe Mathieu-Daude <[email protected]>Signed-off-by Ani Sinha <[email protected]>Reviewed-by Daniel P. Berrangé <[email protected]>Reviewed-by Peter Xu <[email protected]>
Quoted 56 lines
--- hw/i386/acpi-microvm.c | 4 ++-- hw/i386/pc.c | 1 - hw/i386/x86.c | 2 -- 3 files changed, 2 insertions(+), 5 deletions(-)changelog:
v3: split the patches. Peter's changes are now in a seperate patch.
Addressed mst's suggestions. Removed message-ID
from commit log and added the reference to previous discussion thread
explicitly.
v2: kept Peter's changes from https://lore.kernel.org/r/[email protected]
and removed mine.hw/i386/acpi-microvm.c +2
-2@@ -55,8 +55,8 @@ static void acpi_dsdt_add_virtio(Aml *scope, bus =sysbus_get_default (); QTAILQ_FOREACH(kid, &bus->children, sibling) { -DeviceState *dev = kid->child; -Object *obj =object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MMIO ); +Object *obj =object_dynamic_cast (OBJECT (kid->child), +TYPE_VIRTIO_MMIO );if (obj) {VirtIOMMIOProxy *mmio =VIRTIO_MMIO (obj);hw/i386/pc.c +0
-1@@ -1116,7 +1116,6 @@ void pc_memory_init(PCMachineState *pcms,if (machine->device_memory) {uint64_t *val =g_malloc (sizeof (*val)); -PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);uint64_t res_mem_end = machine->device_memory->base;if (!pcmc->broken_reserved_end) {hw/i386/x86.c +0
-2@@ -365,8 +365,6 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, cpu_slot =x86_find_cpu_slot (MACHINE (x86ms), cpu->apic_id, &idx);if (!cpu_slot) { -MachineState *ms =MACHINE (x86ms); -x86_topo_ids_from_apicid (cpu->apic_id, &topo_info, &topo_ids);error_setg (errp, "Invalid CPU [socket: %u, die: %u, core: %u, thread: %u] with"Signature · 1 line
2.42.0
Markus Armbruster
AppliedQuoted 11 lines · Ani Sinha
Code changes 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]
Quoted 7 lines
CC Markus Armbruster <[email protected]>CC Philippe Mathieu-Daude <[email protected]>Signed-off-by Ani Sinha <[email protected]>Reviewed-by Daniel P. Berrangé <[email protected]>Reviewed-by Peter Xu <[email protected]>
Queued. Thanks!