From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx1.t-argos.ru (mx1.t-argos.ru [109.73.34.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1285757CAF; Fri, 3 May 2024 13:09:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.73.34.58 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714741753; cv=none; b=hNwaNfnRCXA3GqW/gikvXf4eAVeqXTUDP+Vpn8UB1kaDopdKjj/exmNLWDF43I2DBldF0b3R6qvYaEIbo9julIGHUzJpu7kbgV080hshd01S3hq0tNfhTLi/NlhXzrrjpxXIeA+FCQk+Cg+AdltMMcj4XRf7F+jLCZLgnk+dqBw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714741753; c=relaxed/simple; bh=DK58w0qoY8bz2V3cf6+WgUE3iZh/7ahs8g0KuQsm9dw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ptqCECPnT1K2wKWkNOzERnUiDGqkqzf4gJ2w5y+uE2lodE4i+x5lE6ibP7Yr63OdHNBoEL4/XyTKP7/s/X0VwW7LhI8k8pMRzC+WGk2ciLYzaDhVdn2EkJ3lqM0V+GzTUnPqhq9BELd4Zb53+4suI2mPKnUHRBjqCl/7siKZVjU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=t-argos.ru; spf=pass smtp.mailfrom=t-argos.ru; dkim=pass (2048-bit key) header.d=t-argos.ru header.i=@t-argos.ru header.b=sN7akbRC; arc=none smtp.client-ip=109.73.34.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=t-argos.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=t-argos.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=t-argos.ru header.i=@t-argos.ru header.b="sN7akbRC" Received: from mx1.t-argos.ru (localhost [127.0.0.1]) by mx1.t-argos.ru (Postfix) with ESMTP id 815B3100002; Fri, 3 May 2024 15:58:27 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=t-argos.ru; s=mail; t=1714741107; bh=eVo+sqixpVSIXoZvCWGWulhPdG3v/sDUTXHvwVOwTVo=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=sN7akbRCGwqsie3fdKFfpQ8OpA7SsWEz06TcjBE5EEL/iaa4EeoG+jCCS4QUMYcFx cK0RmrDUgYs1tFA3FeOdFujF0n4MW5ZesMWbqJhG3NOhu0bOA+p7RvwCQxd4TzejU8 YOaDkFJJVODMp0YGNv2Jh/jgfT2ZugOEwg6C3nHSP0HtW1YST1YYo8fL7fYh8TNDcK REgWV12MtN6Jx1G+3Qo29CSprtBcyTplTg+IbubNAf3rND0kza0SSKSHvEtSwz/N1i qQUyhTCHqYf5hSH7nvFY0PdXlKGhj4KVneK5laHuiO4MqSU/1Ian1R3HR89Ldm/p7z ZwR3SRgpBH08A== Received: from mx1.t-argos.ru.ru (ta-mail-02.ta.t-argos.ru [172.17.13.212]) by mx1.t-argos.ru (Postfix) with ESMTP; Fri, 3 May 2024 15:57:34 +0300 (MSK) Received: from localhost.localdomain (172.17.215.6) by ta-mail-02 (172.17.13.212) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Fri, 3 May 2024 15:57:13 +0300 From: Aleksandr Mishin To: Jonathan Chocron CC: Aleksandr Mishin , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Rob Herring , Bjorn Helgaas , , , , Bjorn Helgaas Subject: [PATCH v3] PCI: dwc: al: Check IORESOURCE_BUS existence during PCIe config preparation Date: Fri, 3 May 2024 15:57:05 +0300 Message-ID: <20240503125705.46055-1-amishin@t-argos.ru> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240328180126.23574-1-amishin@t-argos.ru> References: Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: ta-mail-02.ta.t-argos.ru (172.17.13.212) To ta-mail-02 (172.17.13.212) X-KSMG-Rule-ID: 1 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 185041 [May 03 2024] X-KSMG-AntiSpam-Version: 6.1.0.4 X-KSMG-AntiSpam-Envelope-From: amishin@t-argos.ru X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 19 0.3.19 07c7fa124d1a1dc9662cdc5aace418c06ae99d2b, {Tracking_from_domain_doesnt_match_to}, d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;t-argos.ru:7.1.1;127.0.0.199:7.1.2;mx1.t-argos.ru.ru:7.1.1, FromAlignment: s X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean, bases: 2024/05/03 12:24:00 X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2024/05/03 04:26:00 #25076703 X-KSMG-AntiVirus-Status: Clean, skipped If IORESOURCE_BUS is not provided in Device Tree it will be fabricated in of_pci_parse_bus_range(). So NULL pointer dereference will not occur. But other drivers do this check. So it can be added for code consistency. Found by Linux Verification Center (linuxtesting.org) with SVACE. Suggested-by: Bjorn Helgaas Signed-off-by: Aleksandr Mishin --- v1->v2: Add return code processing as suggested by Bjorn v2->v3: Return -ENODEV instead of -EINVAL drivers/pci/controller/dwc/pcie-al.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-al.c b/drivers/pci/controller/dwc/pcie-al.c index 6dfdda59f328..643115f74092 100644 --- a/drivers/pci/controller/dwc/pcie-al.c +++ b/drivers/pci/controller/dwc/pcie-al.c @@ -242,18 +242,24 @@ static struct pci_ops al_child_pci_ops = { .write = pci_generic_config_write, }; -static void al_pcie_config_prepare(struct al_pcie *pcie) +static int al_pcie_config_prepare(struct al_pcie *pcie) { struct al_pcie_target_bus_cfg *target_bus_cfg; struct dw_pcie_rp *pp = &pcie->pci->pp; unsigned int ecam_bus_mask; + struct resource_entry *ft; u32 cfg_control_offset; + struct resource *bus; u8 subordinate_bus; u8 secondary_bus; u32 cfg_control; u32 reg; - struct resource *bus = resource_list_first_type(&pp->bridge->windows, IORESOURCE_BUS)->res; + ft = resource_list_first_type(&pp->bridge->windows, IORESOURCE_BUS); + if (!ft) + return -ENODEV; + + bus = ft->res; target_bus_cfg = &pcie->target_bus_cfg; ecam_bus_mask = (pcie->ecam_size >> PCIE_ECAM_BUS_SHIFT) - 1; @@ -287,6 +293,8 @@ static void al_pcie_config_prepare(struct al_pcie *pcie) FIELD_PREP(CFG_CONTROL_SEC_BUS_MASK, secondary_bus); al_pcie_controller_writel(pcie, cfg_control_offset, reg); + + return 0; } static int al_pcie_host_init(struct dw_pcie_rp *pp) @@ -305,7 +313,9 @@ static int al_pcie_host_init(struct dw_pcie_rp *pp) if (rc) return rc; - al_pcie_config_prepare(pcie); + rc = al_pcie_config_prepare(pcie); + if (rc) + return rc; return 0; } -- 2.30.2