On Wed, 6 Jan 2021 16:24:01 +0100 BALATON Zoltan via <qemu-...@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 <bala...@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);