All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Ani Sinha <ani@anisinha.ca>
Cc: Eduardo Habkost <ehabkost@redhat.com>,
	jusual@redhat.com,
	Richard Henderson <richard.henderson@linaro.org>,
	qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	Igor Mammedov <imammedo@redhat.com>
Subject: Re: [PATCH v3] hw/acpi: add an assertion check for non-null return from acpi_get_i386_pci_host
Date: Wed, 28 Jul 2021 09:03:41 -0400	[thread overview]
Message-ID: <20210728085437-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20210726165743.232073-1-ani@anisinha.ca>

On Mon, Jul 26, 2021 at 10:27:43PM +0530, Ani Sinha wrote:
> All existing code using acpi_get_i386_pci_host() checks for a non-null
> return value from this function call. Instead of returning early when the value
> returned is NULL, assert instead. Since there are only two possible host buses
> for i386 - q35 and i440fx, a null value return from the function does not make
> sense in most cases and is likely an error situation.

add "on i386"?

> Fixes: c0e427d6eb5fef ("hw/acpi/ich9: Enable ACPI PCI hot-plug")

This that seems inappropriate, this is not a bugfix.

> 
> Signed-off-by: Ani Sinha <ani@anisinha.ca>


Frankly I don't see this as a useful cleanup.
assert is generally a last resort thing.

> ---
>  hw/acpi/pcihp.c      |  8 ++++++++
>  hw/i386/acpi-build.c | 15 ++++++---------
>  2 files changed, 14 insertions(+), 9 deletions(-)
> 
> changelog:
> v1: initial patch
> v2: removed comment addition - that can be sent as a separate patch.
> v3: added assertion for null host values for all cases except one.
> 
> diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
> index f4d706e47d..054ee8cbc5 100644
> --- a/hw/acpi/pcihp.c
> +++ b/hw/acpi/pcihp.c
> @@ -116,6 +116,12 @@ static void acpi_set_pci_info(void)
>      bsel_is_set = true;
>  
>      if (!host) {
> +        /*
> +         * This function can be eventually called from
> +         * qemu_devices_reset() -> acpi_pcihp_reset() even
> +         * for architectures other than i386. Hence, we need

why call out i386 here? well because currently host
is only non-null for q35 and i440fx which are both i386.
all the above is not a given and we won't remember to update
the comment if we change it. Generally graceful failure
is the default or should be.



> +         * to ignore null values for host here.
> +         */
>          return;
>      }
>  
> @@ -136,6 +142,8 @@ static void acpi_pcihp_disable_root_bus(void)
>          return;
>      }
>  
> +    assert(host);
> +
>      bus = PCI_HOST_BRIDGE(host)->bus;
>      if (bus) {
>          /* setting the hotplug handler to NULL makes the bus non-hotpluggable */
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index 17836149fe..83fb1d55c0 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -321,9 +321,7 @@ static void acpi_get_pci_holes(Range *hole, Range *hole64)
>  
>      pci_host = acpi_get_i386_pci_host();
>  
> -    if (!pci_host) {
> -        return;
> -    }
> +    assert(pci_host);
>  
>      range_set_bounds1(hole,
>                        object_property_get_uint(pci_host,
> @@ -1769,9 +1767,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
>  
>          pci_host = acpi_get_i386_pci_host();
>  
> -        if (pci_host) {
> -            bus = PCI_HOST_BRIDGE(pci_host)->bus;
> -        }
> +        assert(pci_host);
> +
> +        bus = PCI_HOST_BRIDGE(pci_host)->bus;
>  
>          if (bus) {
>              Aml *scope = aml_scope("PCI0");
> @@ -2389,9 +2387,8 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
>      QObject *o;
>  
>      pci_host = acpi_get_i386_pci_host();
> -    if (!pci_host) {
> -        return false;
> -    }
> +
> +    assert(pci_host);
>  
>      o = object_property_get_qobject(pci_host, PCIE_HOST_MCFG_BASE, NULL);
>      if (!o) {
> -- 
> 2.25.1



  reply	other threads:[~2021-07-28 13:05 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-26 16:57 [PATCH v3] hw/acpi: add an assertion check for non-null return from acpi_get_i386_pci_host Ani Sinha
2021-07-28 13:03 ` Michael S. Tsirkin [this message]
2021-07-28 14:12   ` Ani Sinha
2021-07-29  4:38   ` Ani Sinha
2021-07-29  6:10     ` Ani Sinha
2021-08-03 11:34       ` Ani Sinha
2021-08-05  9:15 ` Igor Mammedov
2021-08-05 12:09   ` Ani Sinha
2021-08-05 12:59     ` Ani Sinha
2021-08-05 14:12       ` Ani Sinha
2021-08-05 22:13         ` Michael S. Tsirkin
2021-08-06 10:33           ` Igor Mammedov
2021-08-06 10:37         ` Igor Mammedov
2021-08-06 10:52           ` Ani Sinha
2021-08-06 14:01             ` Philippe Mathieu-Daudé
2021-08-06 16:38               ` Philippe Mathieu-Daudé
2021-08-09 16:21                 ` Ani Sinha
2021-08-11 15:00               ` Ani Sinha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210728085437-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=ani@anisinha.ca \
    --cc=ehabkost@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=jusual@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.