* [PATCH] usb: xhci-pci: Check for errors from dm_pci_map_bar()
@ 2021-01-18 11:13 Pali Rohár
2021-01-18 11:23 ` Bin Meng
2021-01-18 13:26 ` [PATCH] " Stefan Roese
0 siblings, 2 replies; 7+ messages in thread
From: Pali Rohár @ 2021-01-18 11:13 UTC (permalink / raw)
To: u-boot
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
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH] usb: xhci-pci: Check for errors from dm_pci_map_bar()
2021-01-18 11:13 [PATCH] usb: xhci-pci: Check for errors from dm_pci_map_bar() Pali Rohár
@ 2021-01-18 11:23 ` Bin Meng
2021-01-18 11:30 ` [PATCH v2] " Pali Rohár
2021-01-18 13:26 ` [PATCH] " Stefan Roese
1 sibling, 1 reply; 7+ messages in thread
From: Bin Meng @ 2021-01-18 11:23 UTC (permalink / raw)
To: u-boot
On Mon, Jan 18, 2021 at 7:13 PM Pali Roh?r <pali@kernel.org> wrote:
>
> 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)
nits: please make "struct xhci_hcor" align to "struct udevice" above
> {
> 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");
nits: use lower case "xhci-pci"
> + 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);
> }
Other than above,
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v2] usb: xhci-pci: Check for errors from dm_pci_map_bar()
2021-01-18 11:23 ` Bin Meng
@ 2021-01-18 11:30 ` Pali Rohár
2021-01-18 11:44 ` Bin Meng
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Pali Rohár @ 2021-01-18 11:30 UTC (permalink / raw)
To: u-boot
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 | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 2b445f21b5..6c5024d3f1 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -13,8 +13,8 @@
#include <usb.h>
#include <usb/xhci.h>
-static void xhci_pci_init(struct udevice *dev, struct xhci_hccr **ret_hccr,
- struct xhci_hcor **ret_hcor)
+static int xhci_pci_init(struct udevice *dev, struct xhci_hccr **ret_hccr,
+ struct xhci_hcor **ret_hcor)
{
struct xhci_hccr *hccr;
struct xhci_hcor *hcor;
@@ -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
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v2] usb: xhci-pci: Check for errors from dm_pci_map_bar()
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
2 siblings, 0 replies; 7+ messages in thread
From: Bin Meng @ 2021-01-18 11:44 UTC (permalink / raw)
To: u-boot
On Mon, Jan 18, 2021 at 7:30 PM Pali Roh?r <pali@kernel.org> wrote:
>
> 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 | 15 ++++++++++++---
> 1 file changed, 12 insertions(+), 3 deletions(-)
>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] usb: xhci-pci: Check for errors from dm_pci_map_bar()
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
2 siblings, 0 replies; 7+ messages in thread
From: Marek Vasut @ 2021-01-18 12:28 UTC (permalink / raw)
To: u-boot
On 1/18/21 12:30 PM, Pali Roh?r wrote:
> 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.
Applied, thanks
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] usb: xhci-pci: Check for errors from dm_pci_map_bar()
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
2 siblings, 0 replies; 7+ messages in thread
From: Stefan Roese @ 2021-01-18 13:27 UTC (permalink / raw)
To: u-boot
On 18.01.21 12:30, Pali Roh?r wrote:
> 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>
Reviewed-by: Stefan Roese <sr@denx.de>
Thanks,
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] usb: xhci-pci: Check for errors from dm_pci_map_bar()
2021-01-18 11:13 [PATCH] usb: xhci-pci: Check for errors from dm_pci_map_bar() Pali Rohár
2021-01-18 11:23 ` Bin Meng
@ 2021-01-18 13:26 ` Stefan Roese
1 sibling, 0 replies; 7+ messages in thread
From: Stefan Roese @ 2021-01-18 13:26 UTC (permalink / raw)
To: u-boot
On 18.01.21 12:13, Pali Roh?r wrote:
> 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>
Reviewed-by: Stefan Roese <sr@denx.de>
Thanks,
Stefan
> ---
> 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);
> }
>
Viele Gr??e,
Stefan
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-01-18 13:27 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-18 11:13 [PATCH] usb: xhci-pci: Check for errors from dm_pci_map_bar() Pali Rohár
2021-01-18 11:23 ` 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
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.