From patchwork Thu Jan 11 20:36:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ray Jui X-Patchwork-Id: 10158515 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2F10F605BA for ; Thu, 11 Jan 2018 20:38:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 214F528590 for ; Thu, 11 Jan 2018 20:38:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16144287AC; Thu, 11 Jan 2018 20:38:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B56828590 for ; Thu, 11 Jan 2018 20:38:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932537AbeAKUhw (ORCPT ); Thu, 11 Jan 2018 15:37:52 -0500 Received: from mail-qt0-f194.google.com ([209.85.216.194]:34638 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932377AbeAKUhu (ORCPT ); Thu, 11 Jan 2018 15:37:50 -0500 Received: by mail-qt0-f194.google.com with SMTP id 33so3469208qtv.1 for ; Thu, 11 Jan 2018 12:37:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1KU+5XrLmBAVOQIaJAQvUyzetHcb4PEglKZ9xJvmv/4=; b=RPaOhlIGWPBgtgKmjF7qKWBbx1eN9jS/hCQB+mR+TMheh4dSMBvHASC4wDtHB64tSr /jxYj0nouvUpLsUfLNO1iTkgwTdIIZMC9loy+bcw1KkA0RfA0vrqHKFEaoMDYQiUnQAR vXscAYQHXL/FCG7ef1q9RUxaqOaQVgLp1KB1o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1KU+5XrLmBAVOQIaJAQvUyzetHcb4PEglKZ9xJvmv/4=; b=efDvPUREdXNoWDDJMKAdSIf+DvAt6yB9ZHZV9xQSLFRV9iVF0e0WMGmzeXGxtB3PqH tYMGHU5Z1MGXoNWwlF2Zh2Oqt5mM4fz+Ww3WvUQHYwQZl8tzWQtDKE+525ONqMBYlXaR xHIH1qLLtKkEN4msROynT3d3P2naOtL+27VImmPRWHG2pzWx2HX0PBx8/EGaQwio6gFn /FZ1+F0si2m6uMkowaopRlEudadgZt0m2stihPOZUipD7aEGzEAuaCqnoKqtdPE72ym0 CghOdR3sSIIE+/4w0YRZCkj47FedE+CQkY5V8qxE458xYYU3Zz7pYXxMI9nL+9/tj4BG jRYA== X-Gm-Message-State: AKwxytcZENiGVRUXuzRw1WcLFuOgdVYkHocJRpClywyTZB/QGBF9xa5+ ZIqHfOnQuwOOzavwNz7keW9m0Q== X-Google-Smtp-Source: ACJfBosBgw1rxiNDUfZXwvOvCxjH20MlnneHNcwlyiCdLcz4POKpqVKuXrhN8Hgf06VmFs0xllNzLA== X-Received: by 10.200.56.234 with SMTP id g39mr33686171qtc.209.1515703068959; Thu, 11 Jan 2018 12:37:48 -0800 (PST) Received: from lbrmn-lnxub44-1.ric.broadcom.com ([192.19.224.250]) by smtp.gmail.com with ESMTPSA id h20sm13015754qke.29.2018.01.11.12.37.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Jan 2018 12:37:47 -0800 (PST) From: Ray Jui To: Lorenzo Pieralisi , Bjorn Helgaas , Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-pci@vger.kernel.org, Rafal Milecki , Ray Jui , Subject: [PATCH v2] PCI: iproc: Fix NULL pointer dereference for BCMA Date: Thu, 11 Jan 2018 12:36:16 -0800 Message-Id: <1515702976-29275-1-git-send-email-ray.jui@broadcom.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP With the inbound DMA mapping supported added, the iProc PCIe driver parses DT property "dma-ranges" through call to "of_pci_dma_range_parser_init". In the case of BCMA, this results in a NULL pointer deference due to a missing of_node. Fix this by adding a guard in pcie-iproc-platform.c to only enable the inbound DMA mapping logic when DT property "dma-ranges" is present Fixes: dd9d4e7498de3 ("PCI: iproc: Add inbound DMA mapping support") Reported-by: Rafał Miłecki Signed-off-by: Ray Jui Tested-by: Rafał Miłecki cc: # 4.10+ --- drivers/pci/host/pcie-iproc-platform.c | 7 +++++++ drivers/pci/host/pcie-iproc.c | 8 +++++--- drivers/pci/host/pcie-iproc.h | 2 ++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/pci/host/pcie-iproc-platform.c b/drivers/pci/host/pcie-iproc-platform.c index a5073a9..32228d4 100644 --- a/drivers/pci/host/pcie-iproc-platform.c +++ b/drivers/pci/host/pcie-iproc-platform.c @@ -92,6 +92,13 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev) pcie->need_ob_cfg = true; } + /* + * DT nodes are not used by all platforms that use the iProc PCIe + * core driver. For platforms that require explict inbound mapping + * configuration, "dma-ranges" would have been present in DT + */ + pcie->need_ib_cfg = of_property_read_bool(np, "dma-ranges"); + /* PHY use is optional */ pcie->phy = devm_phy_get(dev, "pcie-phy"); if (IS_ERR(pcie->phy)) { diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c index 935909b..7583606 100644 --- a/drivers/pci/host/pcie-iproc.c +++ b/drivers/pci/host/pcie-iproc.c @@ -1378,9 +1378,11 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res) } } - ret = iproc_pcie_map_dma_ranges(pcie); - if (ret && ret != -ENOENT) - goto err_power_off_phy; + if (pcie->need_ib_cfg) { + ret = iproc_pcie_map_dma_ranges(pcie); + if (ret && ret != -ENOENT) + goto err_power_off_phy; + } #ifdef CONFIG_ARM pcie->sysdata.private_data = pcie; diff --git a/drivers/pci/host/pcie-iproc.h b/drivers/pci/host/pcie-iproc.h index a6b55ce..4ac6282 100644 --- a/drivers/pci/host/pcie-iproc.h +++ b/drivers/pci/host/pcie-iproc.h @@ -74,6 +74,7 @@ struct iproc_msi; * @ob: outbound mapping related parameters * @ob_map: outbound mapping related parameters specific to the controller * + * @need_ib_cfg: indicates SW needs to configure the inbound mapping window * @ib: inbound mapping related parameters * @ib_map: outbound mapping region related parameters * @@ -101,6 +102,7 @@ struct iproc_pcie { struct iproc_pcie_ob ob; const struct iproc_pcie_ob_map *ob_map; + bool need_ib_cfg; struct iproc_pcie_ib ib; const struct iproc_pcie_ib_map *ib_map;