All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: u-boot@lists.denx.de
Subject: [PATCH] usb: xhci-pci: Check for errors from dm_pci_map_bar()
Date: Mon, 18 Jan 2021 12:13:33 +0100	[thread overview]
Message-ID: <20210118111333.14532-1-pali@kernel.org> (raw)

Function dm_pci_map_bar() may fail and returns NULL. Check this to prevent
dereferencing a NULL pointer.

In xhci-pci this may happen when board does not enable CONFIG_PCI_PNP and
PCI_BASE_ADDRESS_0 contains unconfigured zero address.

Signed-off-by: Pali Roh?r <pali@kernel.org>
---
 drivers/usb/host/xhci-pci.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 2b445f21b5..7f5be95f6c 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -13,7 +13,7 @@
 #include <usb.h>
 #include <usb/xhci.h>
 
-static void xhci_pci_init(struct udevice *dev, struct xhci_hccr **ret_hccr,
+static int xhci_pci_init(struct udevice *dev, struct xhci_hccr **ret_hccr,
 			  struct xhci_hcor **ret_hcor)
 {
 	struct xhci_hccr *hccr;
@@ -22,6 +22,11 @@ static void xhci_pci_init(struct udevice *dev, struct xhci_hccr **ret_hccr,
 
 	hccr = (struct xhci_hccr *)dm_pci_map_bar(dev,
 			PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
+	if (!hccr) {
+		printf("XHCI-PCI init cannot map PCI mem bar\n");
+		return -EIO;
+	}
+
 	hcor = (struct xhci_hcor *)((uintptr_t) hccr +
 			HC_LENGTH(xhci_readl(&hccr->cr_capbase)));
 
@@ -35,14 +40,18 @@ static void xhci_pci_init(struct udevice *dev, struct xhci_hccr **ret_hccr,
 	dm_pci_read_config32(dev, PCI_COMMAND, &cmd);
 	cmd |= PCI_COMMAND_MASTER;
 	dm_pci_write_config32(dev, PCI_COMMAND, cmd);
+	return 0;
 }
 
 static int xhci_pci_probe(struct udevice *dev)
 {
 	struct xhci_hccr *hccr;
 	struct xhci_hcor *hcor;
+	int ret;
 
-	xhci_pci_init(dev, &hccr, &hcor);
+	ret = xhci_pci_init(dev, &hccr, &hcor);
+	if (ret)
+		return ret;
 
 	return xhci_register(dev, hccr, hcor);
 }
-- 
2.20.1

             reply	other threads:[~2021-01-18 11:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-18 11:13 Pali Rohár [this message]
2021-01-18 11:23 ` [PATCH] usb: xhci-pci: Check for errors from dm_pci_map_bar() Bin Meng
2021-01-18 11:30   ` [PATCH v2] " Pali Rohár
2021-01-18 11:44     ` Bin Meng
2021-01-18 12:28     ` Marek Vasut
2021-01-18 13:27     ` Stefan Roese
2021-01-18 13:26 ` [PATCH] " Stefan Roese

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=20210118111333.14532-1-pali@kernel.org \
    --to=pali@kernel.org \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.