Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1765205lqm; Fri, 3 May 2024 06:09:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUmQS8RdldzFrafiXevuqVCNElFngq2imKEiO7ddJ+AKyNb2bkV6UmLSofUUdkUr7vl/BOnz5olqiYkOlmQUrLP6EhWI+/si7EFdLqJmg== X-Google-Smtp-Source: AGHT+IGwpqk09jxSj3Mgyu+8+coWk/4mbKj+cEnGJknT9eKB9pZraPMZMiwT2gK3/xN/wG7G8H97 X-Received: by 2002:a50:a452:0:b0:56b:cfef:b2de with SMTP id v18-20020a50a452000000b0056bcfefb2demr1508057edb.26.1714741762286; Fri, 03 May 2024 06:09:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714741762; cv=pass; d=google.com; s=arc-20160816; b=0jy3mu0awMF4e499CWrQ0jTqb7rm8+ZEllx6xddxA/p/jyxdJew33Pma7mypywAJng RAmm04JmeEbvXXL8YQ0pV4DIAlU119jD1SL7wonns8WDUE681x8B4MvBZpnHJcFaBQJm T0ftaEmajc1i0G59Wgens+7kT+tJQ6UL/LfYkaMchfENfyH1aRKTzLxxuC8X+NYO+Iqt aH3UREvaU2siGBx79f0zdSh8zLp/d39zQKnD2xBQbK4ejvj8F20qBH4U7sNgG+btjjy5 o4UvO+jm1nu20fyrMpyy9pEO4kU5fwY6T7AYXf7C1TW+YjzOkT1uiXQHZCo5QlAMfn+2 6BSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=eVo+sqixpVSIXoZvCWGWulhPdG3v/sDUTXHvwVOwTVo=; fh=Po5/RpXIixs2niKFGOeE6ow7Xdwa3VvXJwBkHDxlxjI=; b=lhekZcG2pNg3XOP4OF/LrLUNOWd1DVaD5O2wzZWvMFeN6V8VSGq9DxeNtfSH70AzRK QqBHLRUISfi31ED89n+ly6wTx74Q1nz5oD7OI36SarT6uX9/Zy3LLnpTmmYHz2KYU8GX yFy/xFvFzxe0/mde6Q3eU5QwddhLYYaIyNgIekgShEj42AplO97ElD/TcDxBxfOpTsRC OH/iETuynTRKC96SPzKPs5JwkajCqv75+8KWwrql9l+rraghnfwKEgZl19ThEEqJNWiq o9hsd3Q+ivc5dvakO+AY1yVWPQh+s+xI8YWo6xdsSKl77kPxJuBJSN5kjHseeC7ewqGh Lthg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@t-argos.ru header.s=mail header.b=sN7akbRC; arc=pass (i=1 spf=pass spfdomain=t-argos.ru dkim=pass dkdomain=t-argos.ru dmarc=pass fromdomain=t-argos.ru); spf=pass (google.com: domain of linux-kernel+bounces-167671-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167671-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=t-argos.ru Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u10-20020a056402064a00b00572be1bb6f4si1515804edx.573.2024.05.03.06.09.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 06:09:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167671-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@t-argos.ru header.s=mail header.b=sN7akbRC; arc=pass (i=1 spf=pass spfdomain=t-argos.ru dkim=pass dkdomain=t-argos.ru dmarc=pass fromdomain=t-argos.ru); spf=pass (google.com: domain of linux-kernel+bounces-167671-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167671-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=t-argos.ru Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 072061F21C7E for ; Fri, 3 May 2024 13:09:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 963F915380B; Fri, 3 May 2024 13:09:14 +0000 (UTC) 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 (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 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-kernel@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