[PULL 05/17] hw/i386/acpi-build: Fix maybe-uninitialized error when ACPI hotplug off

Michael S. Tsirkin posted 17 patches 5 years, 2 months ago
[PULL 05/17] hw/i386/acpi-build: Fix maybe-uninitialized error when ACPI hotplug off
Posted by Michael S. Tsirkin 5 years, 2 months ago
From: Philippe Mathieu-Daudé <philmd@redhat.com>

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")
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20201107194045.438027-1-philmd@redhat.com>
Acked-by: Ani Sinha <ani@anisinha.ca>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/acpi-build.c | 45 +++++++++++++++++++++-----------------------
 1 file changed, 21 insertions(+), 24 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 4f66642d88..1f5c211245 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -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);
-- 
MST


Re: [PULL 05/17] hw/i386/acpi-build: Fix maybe-uninitialized error when ACPI hotplug off
Posted by Ani Sinha 5 years, 2 months ago
On Mon, Nov 16, 2020 at 03:57 Michael S. Tsirkin <mst@redhat.com> wrote:

> From: Philippe Mathieu-Daudé <philmd@redhat.com>
>
> 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")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Message-Id: <20201107194045.438027-1-philmd@redhat.com>
> Acked-by: Ani Sinha <ani@anisinha.ca>
> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>


Is there any reason why my ack was removed from the patch that was
ultimately merged?

https://git.qemu.org/?p=qemu.git;a=commit;h=811c74fb657db0559274a710e50ef0096a1915a3




> ---
>  hw/i386/acpi-build.c | 45 +++++++++++++++++++++-----------------------
>  1 file changed, 21 insertions(+), 24 deletions(-)
>
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index 4f66642d88..1f5c211245 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -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);
> --
> MST
>
>
Re: [PULL 05/17] hw/i386/acpi-build: Fix maybe-uninitialized error when ACPI hotplug off
Posted by Philippe Mathieu-Daudé 5 years, 2 months ago
On 11/16/20 6:44 PM, Ani Sinha wrote:
> 
> 
> On Mon, Nov 16, 2020 at 03:57 Michael S. Tsirkin <mst@redhat.com
> <mailto:mst@redhat.com>> wrote:
> 
>     From: Philippe Mathieu-Daudé <philmd@redhat.com
>     <mailto:philmd@redhat.com>>
> 
>     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")
>     Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com
>     <mailto:philmd@redhat.com>>
>     Message-Id: <20201107194045.438027-1-philmd@redhat.com
>     <mailto:20201107194045.438027-1-philmd@redhat.com>>
>     Acked-by: Ani Sinha <ani@anisinha.ca <mailto:ani@anisinha.ca>>
>     Reviewed-by: Michael S. Tsirkin <mst@redhat.com <mailto:mst@redhat.com>>
>     Signed-off-by: Michael S. Tsirkin <mst@redhat.com
>     <mailto:mst@redhat.com>>
> 
> 
> Is there any reason why my ack was removed from the patch that was
> ultimately merged?

The patch merged is not the patch Michael queued. So your Ack has not
been removed, simply Alex queued an older version previous to your Ack.
https://www.mail-archive.com/qemu-devel@nongnu.org/msg760119.html

> 
> https://git.qemu.org/?p=qemu.git;a=commit;h=811c74fb657db0559274a710e50ef0096a1915a3
> <https://git.qemu.org/?p=qemu.git;a=commit;h=811c74fb657db0559274a710e50ef0096a1915a3>


Re: [PULL 05/17] hw/i386/acpi-build: Fix maybe-uninitialized error when ACPI hotplug off
Posted by Ani Sinha 5 years, 2 months ago
On Mon, Nov 16, 2020 at 23:32 Philippe Mathieu-Daudé <philmd@redhat.com>
wrote:

> On 11/16/20 6:44 PM, Ani Sinha wrote:
> >
> >
> > On Mon, Nov 16, 2020 at 03:57 Michael S. Tsirkin <mst@redhat.com
> > <mailto:mst@redhat.com>> wrote:
> >
> >     From: Philippe Mathieu-Daudé <philmd@redhat.com
> >     <mailto:philmd@redhat.com>>
> >
> >     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")
> >     Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com
> >     <mailto:philmd@redhat.com>>
> >     Message-Id: <20201107194045.438027-1-philmd@redhat.com
> >     <mailto:20201107194045.438027-1-philmd@redhat.com>>
> >     Acked-by: Ani Sinha <ani@anisinha.ca <mailto:ani@anisinha.ca>>
> >     Reviewed-by: Michael S. Tsirkin <mst@redhat.com <mailto:
> mst@redhat.com>>
> >     Signed-off-by: Michael S. Tsirkin <mst@redhat.com
> >     <mailto:mst@redhat.com>>
> >
> >
> > Is there any reason why my ack was removed from the patch that was
> > ultimately merged?
>
> The patch merged is not the patch Michael queued. So your Ack has not
> been removed, simply Alex queued an older version previous to your Ack.
> https://www.mail-archive.com/qemu-devel@nongnu.org/msg760119.htm
> <https://www.mail-archive.com/qemu-devel@nongnu.org/msg760119.html>


Ugh! So is there any material difference between those two patches? I took
a quick look and it seemed the same patch.

<https://www.mail-archive.com/qemu-devel@nongnu.org/msg760119.html>

<https://www.mail-archive.com/qemu-devel@nongnu.org/msg760119.html>
>
> >
> >
> https://git.qemu.org/?p=qemu.git;a=commit;h=811c74fb657db0559274a710e50ef0096a1915a3
> > <
> https://git.qemu.org/?p=qemu.git;a=commit;h=811c74fb657db0559274a710e50ef0096a1915a3
> >
>
>