Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: aospan@netup.ru (Abylay Ospan)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] PCI: iproc: fix resource allocation for BCMA PCIe
Date: Fri, 13 Jan 2017 02:58:41 +0300	[thread overview]
Message-ID: <1484265521-13497-1-git-send-email-aospan@netup.ru> (raw)

Resource allocated on stack was saved by 'devm_request_resource' to
global 'iomem_resource' but become invalid after 'iproc_pcie_bcma_probe' exit.
So the global 'iomem_resource' was poisoned. This may cause kernel crash
or second PCIe bridge registration failure.

Tested on Broadcom NorthStar machine ('Edgecore ECW7220-L') with two PCIe wifi
adapters (b43 BCM4331 and ath10k QCA988X).

Signed-off-by: Abylay Ospan <aospan@netup.ru>
---
 drivers/pci/host/pcie-iproc-bcma.c | 18 ++++++++----------
 drivers/pci/host/pcie-iproc.h      |  2 ++
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/pci/host/pcie-iproc-bcma.c b/drivers/pci/host/pcie-iproc-bcma.c
index bd4c9ec..28f9b89 100644
--- a/drivers/pci/host/pcie-iproc-bcma.c
+++ b/drivers/pci/host/pcie-iproc-bcma.c
@@ -44,8 +44,6 @@ static int iproc_pcie_bcma_probe(struct bcma_device *bdev)
 {
 	struct device *dev = &bdev->dev;
 	struct iproc_pcie *pcie;
-	LIST_HEAD(res);
-	struct resource res_mem;
 	int ret;
 
 	pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
@@ -62,21 +60,21 @@ static int iproc_pcie_bcma_probe(struct bcma_device *bdev)
 	}
 
 	pcie->base_addr = bdev->addr;
+	INIT_LIST_HEAD(&pcie->resources);
 
-	res_mem.start = bdev->addr_s[0];
-	res_mem.end = bdev->addr_s[0] + SZ_128M - 1;
-	res_mem.name = "PCIe MEM space";
-	res_mem.flags = IORESOURCE_MEM;
-	pci_add_resource(&res, &res_mem);
+	pcie->res_mem.start = bdev->addr_s[0];
+	pcie->res_mem.end = bdev->addr_s[0] + SZ_128M - 1;
+	pcie->res_mem.name = "PCIe MEM space";
+	pcie->res_mem.flags = IORESOURCE_MEM;
+	pcie->res_mem.child = NULL;
+	pci_add_resource(&pcie->resources, &pcie->res_mem);
 
 	pcie->map_irq = iproc_pcie_bcma_map_irq;
 
-	ret = iproc_pcie_setup(pcie, &res);
+	ret = iproc_pcie_setup(pcie, &pcie->resources);
 	if (ret)
 		dev_err(dev, "PCIe controller setup failed\n");
 
-	pci_free_resource_list(&res);
-
 	bcma_set_drvdata(bdev, pcie);
 	return ret;
 }
diff --git a/drivers/pci/host/pcie-iproc.h b/drivers/pci/host/pcie-iproc.h
index 04fed8e..866d649 100644
--- a/drivers/pci/host/pcie-iproc.h
+++ b/drivers/pci/host/pcie-iproc.h
@@ -105,6 +105,8 @@ struct iproc_pcie {
 
 	bool need_msi_steer;
 	struct iproc_msi *msi;
+	struct resource res_mem;
+	struct list_head resources;
 };
 
 int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res);
-- 
2.7.4

             reply	other threads:[~2017-01-12 23:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-12 23:58 Abylay Ospan [this message]
2017-01-13  0:40 ` [PATCH] PCI: iproc: fix resource allocation for BCMA PCIe Ray Jui
2017-01-13  5:32   ` Abylay Ospan
2017-01-28 20:44 ` Bjorn Helgaas
     [not found]   ` <CAK3bHNV-O+k1rHSj-KTKOBNNDXpWxp7rXw8bi7ve7-T9qqs8dw@mail.gmail.com>
2017-02-08 20:48     ` Bjorn Helgaas
2017-02-08 22:07       ` Abylay Ospan
2017-02-08 22:27         ` Bjorn Helgaas
2017-02-08 22:39           ` Abylay Ospan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1484265521-13497-1-git-send-email-aospan@netup.ru \
    --to=aospan@netup.ru \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox