[PATCH v2] hw/i386/pc_piix.c: remove unnecessary if() from pc_init1()

Mark Cave-Ayland posted 1 patch 3 weeks, 6 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20250901140422.1136949-1-mark.caveayland@nutanix.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Eduardo Habkost <eduardo@habkost.net>, "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
There is a newer version of this series
hw/i386/pc_piix.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
[PATCH v2] hw/i386/pc_piix.c: remove unnecessary if() from pc_init1()
Posted by Mark Cave-Ayland 3 weeks, 6 days ago
Now that the isapc logic has been split out of pc_piix.c, the PCI Host Bridge
(phb) object is now always set in pc_init1().

Since phb is now guaranteed not to be NULL, Coverity reports that the if()
statement surrounding ioapic_init_gsi() is now unnecessary and can be removed
(CID 1620557), along with the phb NULL initialiser.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
Fixes: 99d0630a45 ("hw/i386/pc_piix.c: assume pcmc->pci_enabled is always true in pc_init1()")
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/i386/pc_piix.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

v2:
- Add R-B tags from Peter and Phil
- Remove phb NULL initialiser


diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 7e78b6daa6..caf8bab68e 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -106,7 +106,7 @@ static void pc_init1(MachineState *machine, const char *pci_type)
     X86MachineState *x86ms = X86_MACHINE(machine);
     MemoryRegion *system_memory = get_system_memory();
     MemoryRegion *system_io = get_system_io();
-    Object *phb = NULL;
+    Object *phb;
     ISABus *isa_bus;
     Object *piix4_pm = NULL;
     qemu_irq smi_irq;
@@ -284,9 +284,7 @@ static void pc_init1(MachineState *machine, const char *pci_type)
         pc_i8259_create(isa_bus, gsi_state->i8259_irq);
     }
 
-    if (phb) {
-        ioapic_init_gsi(gsi_state, phb);
-    }
+    ioapic_init_gsi(gsi_state, phb);
 
     if (tcg_enabled()) {
         x86_register_ferr_irq(x86ms->gsi[13]);
-- 
2.43.0


Re: [PATCH v2] hw/i386/pc_piix.c: remove unnecessary if() from pc_init1()
Posted by Markus Armbruster 3 weeks, 5 days ago
Mark Cave-Ayland <mark.caveayland@nutanix.com> writes:

> Now that the isapc logic has been split out of pc_piix.c, the PCI Host Bridge
> (phb) object is now always set in pc_init1().
>
> Since phb is now guaranteed not to be NULL, Coverity reports that the if()
> statement surrounding ioapic_init_gsi() is now unnecessary and can be removed
> (CID 1620557), along with the phb NULL initialiser.

We commonly use the more formal tag

  Coverity: CID 1620557

>
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> Fixes: 99d0630a45 ("hw/i386/pc_piix.c: assume pcmc->pci_enabled is always true in pc_init1()")
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Re: [PATCH v2] hw/i386/pc_piix.c: remove unnecessary if() from pc_init1()
Posted by Mark Cave-Ayland 3 weeks, 5 days ago
On 01/09/2025 16:22, Markus Armbruster wrote:

> Mark Cave-Ayland <mark.caveayland@nutanix.com> writes:
> 
>> Now that the isapc logic has been split out of pc_piix.c, the PCI Host Bridge
>> (phb) object is now always set in pc_init1().
>>
>> Since phb is now guaranteed not to be NULL, Coverity reports that the if()
>> statement surrounding ioapic_init_gsi() is now unnecessary and can be removed
>> (CID 1620557), along with the phb NULL initialiser.
> 
> We commonly use the more formal tag
> 
>    Coverity: CID 1620557
> 
>>
>> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
>> Fixes: 99d0630a45 ("hw/i386/pc_piix.c: assume pcmc->pci_enabled is always true in pc_init1()")
>> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
>> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Thanks Markus, I've just posted a v3 with this added.


ATB,

Mark.