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 DE438C433F5 for ; Thu, 19 May 2022 16:49:04 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5105A839DF; Thu, 19 May 2022 18:49:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="YuznpNUd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3225F83D9B; Thu, 19 May 2022 18:48:59 +0200 (CEST) Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 300F6839DF for ; Thu, 19 May 2022 18:48:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=393SGYgUKBhYBFAE42AA270.yA8G-xAAF74EFE.z09J.z0@flex--ptosi.bounces.google.com Received: by mail-wm1-x349.google.com with SMTP id v124-20020a1cac82000000b003948b870a8dso4758867wme.2 for ; Thu, 19 May 2022 09:48:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=/w9LJz6CjR2bldtK3p9D0pCi1EBlBoU/wErKzeOBKFo=; b=YuznpNUdgP53LRV/4JgmHy9IL7PaDQsHOOMo/CESBYwabygQeMONBwDwA8n9NeeJQ5 uA4q0toMF7PCHHSIiwZfyQroorVv0AXX9oZgmXj41F7CF5F0m/W8phKXtbYnK29/h3HJ OOYTN1yJc4Gha2vMHdruwDSYvChfdDYabSvT7XuAKvpfeSwesA2PpVbVp8gjT3wJV91E hi8C1+dDf00V4uj+4x5i5tDea5aW2IhOFD1BfeDwI7Vdu8RynqepGemXgafbA4hkM3/Y h51Ga60GpbI9KRY8Q+rwhj99tBqCF1ibJugAE1ecDN4sB+1M0aIPJDHNhW6PhpxrMja8 u5PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=/w9LJz6CjR2bldtK3p9D0pCi1EBlBoU/wErKzeOBKFo=; b=y7jgDmaPVuJwnL57CiOfDuBUl/BKueHUqcSwBU+L4ICdHfLnsZhMN+Um+sQPRikefy OPX+ohsYuGD6HhwKQuCNgXD3v9hEwLnmAwpNm6DBOWYuQxw5O0KbndweRQMcLqXY4LgO +ZlRxylio8DttQSSHpGWdO0PA8aGArNYa7eRJ3cwxm9I/IdZ6CpcdvkeVIgMrrZiZ4pC e0RMIHIRHN68pKU9eKf5sGiz+1u7kYjmYtKu1q2qGBmd2LXOFyxJfoSS1kXQ+S2JDtr1 CSRzxSY+45pEUpBw45hJOd/yKYxh3Qwq0zpGzfdk26QeV0k/1ni72tsNZpV5tqfdCaat HinQ== X-Gm-Message-State: AOAM531vKapOTg7On4LW0+KpwjOIX/oKjDL4HLAYFJ33szBuDeuLkzBk +x204iJe4E1KpAy+ywD9b1NeVwV0blmETjkpcCmtvCMiQvrsb+dZ85tBi848IcUtFsVgTE9QOOe Mb1R9rHMBi2T7vQlZvjVmuxKhY1YsjjQC0stqYx5IVD3LQ4vzQKFp7ASH X-Google-Smtp-Source: ABdhPJylg2lVg1Ytr+pvMJmbe9eY9/taLIQAUkRNw0y2sm3BU93T1iJXdfl5l6qu5rmX2vYuVK6+gDE5QA== X-Received: from ptosi1.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:afb]) (user=ptosi job=sendgmr) by 2002:a05:600c:3482:b0:397:165:3ac3 with SMTP id a2-20020a05600c348200b0039701653ac3mr4583855wmq.149.1652978935600; Thu, 19 May 2022 09:48:55 -0700 (PDT) Date: Thu, 19 May 2022 17:48:30 +0100 Message-Id: <20220519164830.3934669-1-ptosi@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.1.124.g0e6072fb45-goog Subject: [PATCH] pci: Handle failed calloc in decode_regions() From: "=?UTF-8?q?Pierre-Cl=C3=A9ment=20Tosi?=" To: u-boot@lists.denx.de Cc: "=?UTF-8?q?Pierre-Cl=C3=A9ment=20Tosi?=" , Bin Meng , Simon Glass , Stefan Roese Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 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=C3=A9ment Tosi --- 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; } =20 -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 =3D ofnode_get_property(node, "ranges", &len); if (!prop) { debug("%s: Cannot decode regions\n", __func__); - return; + return -EINVAL; } =20 pci_addr_cells =3D ofnode_read_simple_addr_cells(node); @@ -986,6 +986,8 @@ static void decode_regions(struct pci_controller *hose,= ofnode parent_node, max_regions =3D len / cells_per_record + CONFIG_NR_DRAM_BANKS; hose->regions =3D (struct pci_region *) calloc(1, max_regions * sizeof(struct pci_region)); + if (!hose->regions) + return -ENOMEM; =20 for (i =3D 0; i < max_regions; i++, len -=3D cells_per_record) { u64 pci_addr, addr, size; @@ -1053,7 +1055,7 @@ static void decode_regions(struct pci_controller *hos= e, ofnode parent_node, /* Add a region for our local memory */ bd =3D gd->bd; if (!bd) - return; + return 0; =20 for (i =3D 0; i < CONFIG_NR_DRAM_BANKS; ++i) { if (bd->bi_dram[i].size) { @@ -1068,7 +1070,7 @@ static void decode_regions(struct pci_controller *hos= e, ofnode parent_node, } } =20 - return; + return 0; } =20 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 =3D bus; - decode_regions(hose, dev_ofnode(bus->parent), dev_ofnode(bus)); + ret =3D decode_regions(hose, dev_ofnode(bus->parent), + dev_ofnode(bus)); + if (ret) + return ret; } else { struct pci_controller *parent_hose; =20 --=20 2.36.1.124.g0e6072fb45-goog