Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79F08C433E0 for ; Thu, 7 Jan 2021 09:46:45 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DC1C22333D for ; Thu, 7 Jan 2021 09:46:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC1C22333D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=eik.bme.hu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:42458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxRsR-0003pC-Qb for qemu-devel@archiver.kernel.org; Thu, 07 Jan 2021 04:46:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59532) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxRrN-0003Na-OT; Thu, 07 Jan 2021 04:45:37 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]:17756) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxRrI-0005zC-DC; Thu, 07 Jan 2021 04:45:36 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 881DB7470F5; Thu, 7 Jan 2021 10:45:26 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 40FF97470F4; Thu, 7 Jan 2021 10:45:26 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zero.eik.bme.hu (Postfix) with ESMTP id 3EFDA74645B; Thu, 7 Jan 2021 10:45:26 +0100 (CET) Date: Thu, 7 Jan 2021 10:45:26 +0100 (CET) From: BALATON Zoltan To: Greg Kurz Subject: Re: [PATCH 3/3] sam460ex: Use type cast macro instead of simple cast In-Reply-To: <20210107090815.12cc73fd@bahia.lan> Message-ID: <201f883b-c4f2-88f1-24fa-b1759d2c849d@eik.bme.hu> References: <8bc87f574759a3e9e9e8707b1e0947c1ee21fa8c.1609946641.git.balaton@eik.bme.hu> <20210107090815.12cc73fd@bahia.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Received-SPF: pass client-ip=2001:738:2001:2001::2001; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , David Gibson , BALATON Zoltan via , qemu-devel@nongnu.org, f4bug@amsat.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Thu, 7 Jan 2021, Greg Kurz wrote: > On Wed, 6 Jan 2021 16:24:01 +0100 > BALATON Zoltan via 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. This wasn't my experience when I've got an error in code and got a NULL pointer here (on pegasos2 board but same situation). At least with qom-debug enabled (which I think is on by default unless explicitly disabled in configure) this will abort if the object is not the right type. >> shouldn't fail here. >> >> Signed-off-by: BALATON Zoltan >> --- >> 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(). I think it can only fail if the ppc440-pcix-host type is changed to not have a pci.0 child any more which is a programming error that's very unlikely to happen but if needed an assert could be added but I don't think that's really necessary. The error_report was definitely not needed as it's not a user error in any case. Regards, BALATON Zoltan >> memory_region_init_alias(isa, NULL, "isa_mmio", get_system_io(), >> 0, 0x10000); >> memory_region_add_subregion(get_system_memory(), 0xc08000000, isa); > >