qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kurz <groug@kaod.org>
To: BALATON Zoltan via <qemu-ppc@nongnu.org>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	f4bug@amsat.org, qemu-devel@nongnu.org,
	David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [PATCH 3/3] sam460ex: Use type cast macro instead of simple cast
Date: Thu, 7 Jan 2021 09:08:15 +0100	[thread overview]
Message-ID: <20210107090815.12cc73fd@bahia.lan> (raw)
In-Reply-To: <8bc87f574759a3e9e9e8707b1e0947c1ee21fa8c.1609946641.git.balaton@eik.bme.hu>

On Wed, 6 Jan 2021 16:24:01 +0100
BALATON Zoltan via <qemu-ppc@nongnu.org> wrote:

> Use the PCI_BUS type cast macro to convert result of
> qdev_get_child_bus(). Also remove the check for NULL afterwards which
> should not be needed because sysbus_create_simple() uses error_abort

It seems to me that sysbus_create_simple() doesn't return NULL because
it ends up calling object_new_with_type(). This allocates the object
with either g_malloc() or qemu_memalign(), both of which abort on
failure.

> and PCI_BUS macro also checks its argument by default so this

AFAICT, PCI_BUS() and all other instance type checking macros are
happy with a NULL argument. They simply return NULL in this case.

> shouldn't fail here.
> 
> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
> ---
>  hw/ppc/sam460ex.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c
> index 14e6583eb0..cc67e9c39b 100644
> --- a/hw/ppc/sam460ex.c
> +++ b/hw/ppc/sam460ex.c
> @@ -384,11 +384,8 @@ static void sam460ex_init(MachineState *machine)
>      ppc460ex_pcie_init(env);
>      /* All PCI irqs are connected to the same UIC pin (cf. UBoot source) */
>      dev = sysbus_create_simple("ppc440-pcix-host", 0xc0ec00000, uic[1][0]);
> -    pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci.0");
> -    if (!pci_bus) {
> -        error_report("couldn't create PCI controller!");
> -        exit(1);
> -    }
> +    pci_bus = PCI_BUS(qdev_get_child_bus(dev, "pci.0"));
> +

But PCI_BUS() is being passed qdev_get_child_bus(dev, "pci.0"), not
dev... so the real question here is whether this can return NULL
or not. And if this happens, is this a (1) user or (2) programming
error ?

If (1) then the "if (!pci_bus) { }" should be kept. If (2) then
it should be converted to an assert().

>      memory_region_init_alias(isa, NULL, "isa_mmio", get_system_io(),
>                               0, 0x10000);
>      memory_region_add_subregion(get_system_memory(), 0xc08000000, isa);



  reply	other threads:[~2021-01-07  8:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-06 15:24 [PATCH 0/3] Fix up sam460ex fixes BALATON Zoltan via
2021-01-06 15:24 ` [PATCH 1/3] Revert "sam460ex: Remove FDT_PPC dependency from KConfig" BALATON Zoltan via
2021-01-06 15:24 ` [PATCH 3/3] sam460ex: Use type cast macro instead of simple cast BALATON Zoltan via
2021-01-07  8:08   ` Greg Kurz [this message]
2021-01-07  9:45     ` BALATON Zoltan
2021-01-07 11:13       ` Greg Kurz
2021-01-07 19:37         ` BALATON Zoltan
2021-01-06 15:24 ` [PATCH 2/3] Revert "ppc4xx: Move common dependency on serial to common option" BALATON Zoltan via

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=20210107090815.12cc73fd@bahia.lan \
    --to=groug@kaod.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=f4bug@amsat.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).