Skip to contentSkip to conversation

hw/i386/acpi-build: Fix maybe-uninitialized error when ACPI hotplug off

PATCH In review Philippe Mathieu-Daudé 3 participants 5 messages Nov 7, 2020 – Nov 12, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hw/i386/acpi-build: Fix maybe-uninitialized error when ACPI hotplug off

GCC 9.3.0 thinks that 'method' can be left uninitialized. This code is already in the "if (bsel || pcihp_bridge_en)" block statement, but it isn't smart enough to figure it out.

Restrict the code to be used only in the "if (bsel || pcihp_bridge_en)" block statement to fix (on Ubuntu):

../hw/i386/acpi-build.c: In function 'build_append_pci_bus_devices':
../hw/i386/acpi-build.c:496:9: error: 'method' may be used uninitialized in this function [-Werror=maybe-uninitialized]

    496 |         aml_append(parent_scope, method);
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

Fixes df4008c9c59 ("piix4: don't reserve hw resources when hotplug is off globally")
---
 hw/i386/acpi-build.c | 45 +++++++++++++++++++++-----------------------
 1 file changed, 21 insertions(+), 24 deletions(-)
hw/i386/acpi-build.c +21 -24
index 4f66642d887..1f5c2112452 100644
@@ -465,34 +465,31 @@ static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus,
      */
     if (bsel || pcihp_bridge_en) {
         method = aml_method("PCNT", 0, AML_NOTSERIALIZED);
-    }
-    /* If bus supports hotplug select it and notify about local events */
-    if (bsel) {
-        uint64_t bsel_val = qnum_get_uint(qobject_to(QNum, bsel));
 
-        aml_append(method, aml_store(aml_int(bsel_val), aml_name("BNUM")));
-        aml_append(method,
-            aml_call2("DVNT", aml_name("PCIU"), aml_int(1) /* Device Check */)
-        );
-        aml_append(method,
-            aml_call2("DVNT", aml_name("PCID"), aml_int(3)/* Eject Request */)
-        );
-    }
+        /* If bus supports hotplug select it and notify about local events */
+        if (bsel) {
+            uint64_t bsel_val = qnum_get_uint(qobject_to(QNum, bsel));
 
-    /* Notify about child bus events in any case */
-    if (pcihp_bridge_en) {
-        QLIST_FOREACH(sec, &bus->child, sibling) {
-            int32_t devfn = sec->parent_dev->devfn;
-
-            if (pci_bus_is_root(sec) || pci_bus_is_express(sec)) {
-                continue;
-            }
-
-            aml_append(method, aml_name("^S%.02X.PCNT", devfn));
+            aml_append(method, aml_store(aml_int(bsel_val), aml_name("BNUM")));
+            aml_append(method, aml_call2("DVNT", aml_name("PCIU"),
+                                         aml_int(1))); /* Device Check */
+            aml_append(method, aml_call2("DVNT", aml_name("PCID"),
+                                         aml_int(3))); /* Eject Request */
+        }
+
+        /* Notify about child bus events in any case */
+        if (pcihp_bridge_en) {
+            QLIST_FOREACH(sec, &bus->child, sibling) {
+                int32_t devfn = sec->parent_dev->devfn;
+
+                if (pci_bus_is_root(sec) || pci_bus_is_express(sec)) {
+                    continue;
+                }
+
+                aml_append(method, aml_name("^S%.02X.PCNT", devfn));
+            }
         }
-    }
 
-    if (bsel || pcihp_bridge_en) {
         aml_append(parent_scope, method);
     }
     qobject_unref(bsel);
Signature · 1 line
2.26.2
Acked-by on v2 1/1
#1 lore raw
Quoted 8 lines · Philippe Mathieu-Daudé

GCC 9.3.0 thinks that 'method' can be left uninitialized. This code is already in the "if (bsel || pcihp_bridge_en)" block statement, but it isn't smart enough to figure it out.

Restrict the code to be used only in the "if (bsel || pcihp_bridge_en)" block statement to fix (on Ubuntu):

Quoted 6 lines

../hw/i386/acpi-build.c: In function 'build_append_pci_bus_devices':
../hw/i386/acpi-build.c:496:9: error: 'method' may be used uninitialized in this function [-Werror=maybe-uninitialized]

    496 |         aml_append(parent_scope, method);
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

OK I looked at the patch closely and it makes sense. Can you please run a "make check" to make sure we have not broken anything?

Quoted 2 lines
Fixes df4008c9c59 ("piix4: don't reserve hw resources when hotplug is off globally")
Quoted 68 lines
---
 hw/i386/acpi-build.c | 45 +++++++++++++++++++++-----------------------
 1 file changed, 21 insertions(+), 24 deletions(-)
hw/i386/acpi-build.c +21 -25
index 4f66642d887..1f5c2112452 100644
@@ -465,34 +465,31 @@ static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus,
      */
     if (bsel || pcihp_bridge_en) {
         method = aml_method("PCNT", 0, AML_NOTSERIALIZED);
-    }
-    /* If bus supports hotplug select it and notify about local events */
-    if (bsel) {
-        uint64_t bsel_val = qnum_get_uint(qobject_to(QNum, bsel));
 
-        aml_append(method, aml_store(aml_int(bsel_val), aml_name("BNUM")));
-        aml_append(method,
-            aml_call2("DVNT", aml_name("PCIU"), aml_int(1) /* Device Check */)
-        );
-        aml_append(method,
-            aml_call2("DVNT", aml_name("PCID"), aml_int(3)/* Eject Request */)
-        );
-    }
+        /* If bus supports hotplug select it and notify about local events */
+        if (bsel) {
+            uint64_t bsel_val = qnum_get_uint(qobject_to(QNum, bsel));
 
-    /* Notify about child bus events in any case */
-    if (pcihp_bridge_en) {
-        QLIST_FOREACH(sec, &bus->child, sibling) {
-            int32_t devfn = sec->parent_dev->devfn;
-
-            if (pci_bus_is_root(sec) || pci_bus_is_express(sec)) {
-                continue;
-            }
-
-            aml_append(method, aml_name("^S%.02X.PCNT", devfn));
+            aml_append(method, aml_store(aml_int(bsel_val), aml_name("BNUM")));
+            aml_append(method, aml_call2("DVNT", aml_name("PCIU"),
+                                         aml_int(1))); /* Device Check */
+            aml_append(method, aml_call2("DVNT", aml_name("PCID"),
+                                         aml_int(3))); /* Eject Request */
+        }
+
+        /* Notify about child bus events in any case */
+        if (pcihp_bridge_en) {
+            QLIST_FOREACH(sec, &bus->child, sibling) {
+                int32_t devfn = sec->parent_dev->devfn;
+
+                if (pci_bus_is_root(sec) || pci_bus_is_express(sec)) {
+                    continue;
+                }
+
+                aml_append(method, aml_name("^S%.02X.PCNT", devfn));
+            }
         }
-    }
 
-    if (bsel || pcihp_bridge_en) {
         aml_append(parent_scope, method);
     }
     qobject_unref(bsel);
--

2.26.2

#2 lore raw
Quoted 16 lines · Ani Sinha
Quoted 8 lines · Philippe Mathieu-Daudé

GCC 9.3.0 thinks that 'method' can be left uninitialized. This code is already in the "if (bsel || pcihp_bridge_en)" block statement, but it isn't smart enough to figure it out.

Restrict the code to be used only in the "if (bsel || pcihp_bridge_en)" block statement to fix (on Ubuntu):

Quoted 6 lines

../hw/i386/acpi-build.c: In function 'build_append_pci_bus_devices':
../hw/i386/acpi-build.c:496:9: error: 'method' may be used uninitialized in this function [-Werror=maybe-uninitialized]

    496 |         aml_append(parent_scope, method);
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

Quoted 2 lines

OK I looked at the patch closely and it makes sense. Can you please run a "make check" to make sure we have not broken anything?

Yes I did...

#3 lore raw
Quoted 19 lines · On Sun, Nov 8, 2020 at 22:40 Philippe Mathieu-Daudé <[email protected]> wrote:
Quoted 1 line · Ani Sinha

On Sun, Nov 8, 2020 at 1:10 AM Philippe Mathieu-Daudé <[email protected]>

Quoted 10 lines · wrote:
Quoted 10 lines

GCC 9.3.0 thinks that 'method' can be left uninitialized. This code is already in the "if (bsel || pcihp_bridge_en)" block statement, but it isn't smart enough to figure it out.

Restrict the code to be used only in the "if (bsel || pcihp_bridge_en)" block statement to fix (on Ubuntu):

../hw/i386/acpi-build.c: In function 'build_append_pci_bus_devices':
../hw/i386/acpi-build.c:496:9: error: 'method' may be used

uninitialized

Quoted 5 lines
Quoted 4 lines

in this function [-Werror=maybe-uninitialized]

    496 |         aml_append(parent_scope, method);
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

Quoted 4 lines
Quoted 2 lines

OK I looked at the patch closely and it makes sense. Can you please run a "make check" to make sure we have not broken anything?

Yes I did...

Has this been queued Michael?

Quoted 2 lines
#4 lore raw
Quoted 29 lines · Ani Sinha

On Sun, Nov 8, 2020 at 22:40 Philippe Mathieu-Daudé <[email protected]> wrote:

    On 11/8/20 4:58 AM, Ani Sinha wrote:
    > On Sun, Nov 8, 2020 at 1:10 AM Philippe Mathieu-Daudé <[email protected]>
    wrote:
    >>
    >> GCC 9.3.0 thinks that 'method' can be left uninitialized. This code
    >> is already in the "if (bsel || pcihp_bridge_en)" block statement,
    >> but it isn't smart enough to figure it out.
    >>
    >> Restrict the code to be used only in the "if (bsel || pcihp_bridge_en)"
    >> block statement to fix (on Ubuntu):
    >>
    >>   ../hw/i386/acpi-build.c: In function 'build_append_pci_bus_devices':
    >>   ../hw/i386/acpi-build.c:496:9: error: 'method' may be used
    uninitialized
    >>   in this function [-Werror=maybe-uninitialized]
    >>     496 |         aml_append(parent_scope, method);
    >>         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    >>   cc1: all warnings being treated as errors
    >
    > OK I looked at the patch closely and it makes sense. Can you please
    > run a "make check" to make sure we have not broken anything?

    Yes I did...
Quoted 1 line

Has this been queued Michael?

tagged, thanks!

Quoted 4 lines