Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1AEA2C433EF for ; Fri, 20 May 2022 04:56:40 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3743C83E3C; Fri, 20 May 2022 06:56:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1653022598; bh=NKddsmS1vuXOSj6AQJJRTqLGpt7oCP2y26JbzbKIv1w=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Sv03rBx7d04f3tXWzG/hVbqC5LYRHr4KNkvZJVrlaH3aTzuYd37dvx2PkK+LaQOU5 MUmKPZgLXY/vAzhQRv0vXB79KIGODSrbW47Ul1Soq8Y9LSKd7maIEhcVM9eE3xysmh Gd0aR7zsQOHYmNlG8mUQyvin1goelstS3FniHkrxOivqjoCXOesunv0+ZP5orQd+/P ZnbVFII2eZ1ohhEjIDbSukU5H0oNI8TccTnjl+wAbBNRzOhV2uFV6AgweWdTMeDdTd 5clbb+pVr1D9Qyyu3m2q6wZXMDPGc9ow4akZde8U4wcSwDeRredQmU6tk3AZAP/M9h CdgJ9wt6ZoTWA== Received: by phobos.denx.de (Postfix, from userid 109) id F341A83E81; Fri, 20 May 2022 06:56:36 +0200 (CEST) Received: from mout-u-107.mailbox.org (mout-u-107.mailbox.org [IPv6:2001:67c:2050:101:465::107]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3B05383DEB for ; Fri, 20 May 2022 06:56:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sr@denx.de Received: from smtp102.mailbox.org (unknown [91.198.250.119]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-107.mailbox.org (Postfix) with ESMTPS id 4L4Dw01TLvz9sPp; Fri, 20 May 2022 06:56:32 +0200 (CEST) Message-ID: Date: Fri, 20 May 2022 06:56:30 +0200 MIME-Version: 1.0 Subject: Re: [PATCH] pci: Handle failed calloc in decode_regions() Content-Language: en-US To: =?UTF-8?Q?Pierre-Cl=c3=a9ment_Tosi?= , u-boot@lists.denx.de Cc: Bin Meng , Simon Glass References: <20220519164830.3934669-1-ptosi@google.com> From: Stefan Roese In-Reply-To: <20220519164830.3934669-1-ptosi@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4L4Dw01TLvz9sPp X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean On 19.05.22 18:48, Pierre-Clément Tosi wrote: > Add a check for calloc() failing to allocate the requested memory. > > Make decode_regions() return an error code. > > Cc: Bin Meng > Cc: Simon Glass > Cc: Stefan Roese > Signed-off-by: Pierre-Clément Tosi Reviewed-by: Stefan Roese Thanks, Stefan > --- > drivers/pci/pci-uclass.c | 15 ++++++++++----- > 1 file changed, 10 insertions(+), 5 deletions(-) > > diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c > index 970ee1adf1..2c85e78a13 100644 > --- a/drivers/pci/pci-uclass.c > +++ b/drivers/pci/pci-uclass.c > @@ -954,7 +954,7 @@ int pci_bind_bus_devices(struct udevice *bus) > return 0; > } > > -static void decode_regions(struct pci_controller *hose, ofnode parent_node, > +static int decode_regions(struct pci_controller *hose, ofnode parent_node, > ofnode node) > { > int pci_addr_cells, addr_cells, size_cells; > @@ -968,7 +968,7 @@ static void decode_regions(struct pci_controller *hose, ofnode parent_node, > prop = ofnode_get_property(node, "ranges", &len); > if (!prop) { > debug("%s: Cannot decode regions\n", __func__); > - return; > + return -EINVAL; > } > > pci_addr_cells = ofnode_read_simple_addr_cells(node); > @@ -986,6 +986,8 @@ static void decode_regions(struct pci_controller *hose, ofnode parent_node, > max_regions = len / cells_per_record + CONFIG_NR_DRAM_BANKS; > hose->regions = (struct pci_region *) > calloc(1, max_regions * sizeof(struct pci_region)); > + if (!hose->regions) > + return -ENOMEM; > > for (i = 0; i < max_regions; i++, len -= cells_per_record) { > u64 pci_addr, addr, size; > @@ -1053,7 +1055,7 @@ static void decode_regions(struct pci_controller *hose, ofnode parent_node, > /* Add a region for our local memory */ > bd = gd->bd; > if (!bd) > - return; > + return 0; > > for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) { > if (bd->bi_dram[i].size) { > @@ -1068,7 +1070,7 @@ static void decode_regions(struct pci_controller *hose, ofnode parent_node, > } > } > > - return; > + return 0; > } > > static int pci_uclass_pre_probe(struct udevice *bus) > @@ -1097,7 +1099,10 @@ static int pci_uclass_pre_probe(struct udevice *bus) > /* For bridges, use the top-level PCI controller */ > if (!device_is_on_pci_bus(bus)) { > hose->ctlr = bus; > - decode_regions(hose, dev_ofnode(bus->parent), dev_ofnode(bus)); > + ret = decode_regions(hose, dev_ofnode(bus->parent), > + dev_ofnode(bus)); > + if (ret) > + return ret; > } else { > struct pci_controller *parent_hose; > Viele Grüße, Stefan Roese -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de