Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1690887pxb; Thu, 4 Mar 2021 19:00:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVatbfItTHf70Rml8DzqAvVqYOnrkdpdQQmL6hqyXDgObCiDpZ0P/pyD1Vi3uH6qytFDQE X-Received: by 2002:aa7:c496:: with SMTP id m22mr7286660edq.292.1614913256312; Thu, 04 Mar 2021 19:00:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614913256; cv=none; d=google.com; s=arc-20160816; b=Fb7jbDOqxvcwC2+rI7Q/UOgTGR0SD2rIiB9bQ/VvSFjztVQmaB8jZYtm+KsF3RR96O a1+q7DoLiKMZw4OV4uGJCBruMGhO2gt59rQ2CNcVxtSETIAjTY82Q6np1kyCpK/ujYO8 IvcIEYbu2Yykn7fu2h77Ef0THj5Kwe3TfaB+V0etkebPSOL2XMG7BOHCAm9jGLgRJUza CawKOQ2b3TZvrVVKkFbmuiUAi1MvcxIFb2+0XFO4jC3qmU6P8CvtNafz3EB1ovnpA38w ZIY0bwarp2iudJT7VpNvccxr4FoHeEQPX1gYtyzVtnslYfiz8MohwQSb1buNaNPcf8R/ yRhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=4ahj61Ka0+iqhWERh7yRL39qOUve4QTofA7lhdzVP6M=; b=ywUV9UTiKLWdKUpfHTprGW4SpPz7fMynsPYDA7nvNyU2GqO/QeQAhkK8lMaKcWAVFB GX0yA6Cnp1xhhB5LacLgKmbT+/hVI1W65T4FIhEqRsCjqNqttgl6JpDg7UwdCwGe68t7 DJcvpmgtX2HszQ9gFZo7UPW4o6m5p4RFPelhi/RnVeK3/pAu8OzUQqRYOwyiI1de4SXk zHmTejz5pTJWWgRr9zW+WLvcs1Xyc4h+vM7xnVLAYqhKUEMMyfuxndDSudbGBuUmV6WL dzKoUXwki7KurnhLEQE7iZtd/M7oC8JK06XgIC7uS3Xj85sd91Tnx527JMjJBx5xNPY8 MQew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=atLib6If; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lr3si598335ejb.514.2021.03.04.19.00.32; Thu, 04 Mar 2021 19:00:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=atLib6If; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229575AbhCEC7Z (ORCPT + 99 others); Thu, 4 Mar 2021 21:59:25 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:45160 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbhCEC7Y (ORCPT ); Thu, 4 Mar 2021 21:59:24 -0500 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 1252xIXF026556; Thu, 4 Mar 2021 20:59:18 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1614913158; bh=4ahj61Ka0+iqhWERh7yRL39qOUve4QTofA7lhdzVP6M=; h=From:To:CC:Subject:Date; b=atLib6IfCvdhxB2qqxzMrqn582vEurvNRni4xyzQuAkfXOra5h8suuBnrBcC1c7rm lCxSZQg2+eMzFjYbEptSnJG1wTNZDfLxVk+PJvoDf6sfZRYbYv9STrk4EOII4GU0XV pEUqNUYaXxqSWO3yZNbyu1PTj4ha0VYMUG/khIjI= Received: from DLEE105.ent.ti.com (dlee105.ent.ti.com [157.170.170.35]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 1252xI3c051045 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 4 Mar 2021 20:59:18 -0600 Received: from DLEE111.ent.ti.com (157.170.170.22) by DLEE105.ent.ti.com (157.170.170.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Thu, 4 Mar 2021 20:59:18 -0600 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE111.ent.ti.com (157.170.170.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Thu, 4 Mar 2021 20:59:18 -0600 Received: from a0393678-ssd.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 1252xDqN121008; Thu, 4 Mar 2021 20:59:14 -0600 From: Kishon Vijay Abraham I To: Kishon Vijay Abraham I , Jingoo Han , Gustavo Pimentel , Lorenzo Pieralisi , Rob Herring , Bjorn Helgaas CC: , , Lokesh Vutla Subject: [PATCH] PCI: designware-ep: Fix NULL pointer dereference error Date: Fri, 5 Mar 2021 08:29:10 +0530 Message-ID: <20210305025910.9652-1-kishon@ti.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit 281f1f99cf3a ("PCI: dwc: Detect number of iATU windows") detected the number of inbound and outbound windows dynamically at runtime in dw_pcie_setup(). However pcie-designware-ep.c accessed the variables holding the number of inbound and outbound windows even before dw_pcie_setup() was invoked. Fix the sequence here. Fixes: 281f1f99cf3a ("PCI: dwc: Detect number of iATU windows") Signed-off-by: Kishon Vijay Abraham I --- .../pci/controller/dwc/pcie-designware-ep.c | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c index 1c25d8337151..2c0f837af458 100644 --- a/drivers/pci/controller/dwc/pcie-designware-ep.c +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c @@ -636,9 +636,11 @@ static unsigned int dw_pcie_ep_find_ext_capability(struct dw_pcie *pci, int cap) int dw_pcie_ep_init_complete(struct dw_pcie_ep *ep) { struct dw_pcie *pci = to_dw_pcie_from_ep(ep); + struct device *dev = pci->dev; unsigned int offset; unsigned int nbars; u8 hdr_type; + void *addr; u32 reg; int i; @@ -665,6 +667,27 @@ int dw_pcie_ep_init_complete(struct dw_pcie_ep *ep) } dw_pcie_setup(pci); + + ep->ib_window_map = devm_kcalloc(dev, + BITS_TO_LONGS(pci->num_ib_windows), + sizeof(long), + GFP_KERNEL); + if (!ep->ib_window_map) + return -ENOMEM; + + ep->ob_window_map = devm_kcalloc(dev, + BITS_TO_LONGS(pci->num_ob_windows), + sizeof(long), + GFP_KERNEL); + if (!ep->ob_window_map) + return -ENOMEM; + + addr = devm_kcalloc(dev, pci->num_ob_windows, sizeof(phys_addr_t), + GFP_KERNEL); + if (!addr) + return -ENOMEM; + ep->outbound_addr = addr; + dw_pcie_dbi_ro_wr_dis(pci); return 0; @@ -674,7 +697,6 @@ EXPORT_SYMBOL_GPL(dw_pcie_ep_init_complete); int dw_pcie_ep_init(struct dw_pcie_ep *ep) { int ret; - void *addr; u8 func_no; struct resource *res; struct pci_epc *epc; @@ -712,26 +734,6 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) ep->phys_base = res->start; ep->addr_size = resource_size(res); - ep->ib_window_map = devm_kcalloc(dev, - BITS_TO_LONGS(pci->num_ib_windows), - sizeof(long), - GFP_KERNEL); - if (!ep->ib_window_map) - return -ENOMEM; - - ep->ob_window_map = devm_kcalloc(dev, - BITS_TO_LONGS(pci->num_ob_windows), - sizeof(long), - GFP_KERNEL); - if (!ep->ob_window_map) - return -ENOMEM; - - addr = devm_kcalloc(dev, pci->num_ob_windows, sizeof(phys_addr_t), - GFP_KERNEL); - if (!addr) - return -ENOMEM; - ep->outbound_addr = addr; - if (pci->link_gen < 1) pci->link_gen = of_pci_get_max_link_speed(np); -- 2.17.1