All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] PCI: dra7xx: Fix potential NULL dereference
@ 2018-01-18 14:00 ` Wei Yongjun
  0 siblings, 0 replies; 27+ messages in thread
From: Wei Yongjun @ 2018-01-18 13:54 UTC (permalink / raw)
  To: Kishon Vijay Abraham I, Lorenzo Pieralisi, Bjorn Helgaas
  Cc: Wei Yongjun, linux-omap, linux-pci, kernel-janitors

platform_get_resource_byname() may fail and return NULL, so we should
better check it's return value to avoid a NULL pointer dereference a
bit later in the code.

This is detected by Coccinelle semantic patch.

@@
expression pdev, res, n, t, e, e1, e2;
@@

res = platform_get_resource_byname(pdev, t, n);
+ if (!res)
+   return -EINVAL;
... when != res = NULL
e = devm_ioremap(e1, res->start, e2);

Fixes: 608793e27b33 ("PCI: dwc: dra7xx: Add EP mode support")
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 drivers/pci/dwc/pci-dra7xx.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/pci/dwc/pci-dra7xx.c b/drivers/pci/dwc/pci-dra7xx.c
index 8bf7c27..aafded8 100644
--- a/drivers/pci/dwc/pci-dra7xx.c
+++ b/drivers/pci/dwc/pci-dra7xx.c
@@ -409,11 +409,15 @@ static int __init dra7xx_add_pcie_ep(struct dra7xx_pcie *dra7xx,
 	ep->ops = &pcie_ep_ops;
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ep_dbics");
+	if (!res)
+		return -EINVAL;
 	pci->dbi_base = devm_ioremap(dev, res->start, resource_size(res));
 	if (!pci->dbi_base)
 		return -ENOMEM;
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ep_dbics2");
+	if (!res)
+		return -EINVAL;
 	pci->dbi_base2 = devm_ioremap(dev, res->start, resource_size(res));
 	if (!pci->dbi_base2)
 		return -ENOMEM;
@@ -462,6 +466,8 @@ static int __init dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx,
 		return ret;
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rc_dbics");
+	if (!res)
+		return -EINVAL;
 	pci->dbi_base = devm_ioremap(dev, res->start, resource_size(res));
 	if (!pci->dbi_base)
 		return -ENOMEM;


^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2018-11-16 11:51 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-18 13:54 [PATCH -next] PCI: dra7xx: Fix potential NULL dereference Wei Yongjun
2018-01-18 14:00 ` Wei Yongjun
2018-01-18 14:00 ` Wei Yongjun
2018-01-18 14:42 ` Bjorn Helgaas
2018-01-18 14:42   ` Bjorn Helgaas
2018-01-18 14:54 ` Ladislav Michl
2018-01-18 14:54   ` Ladislav Michl
2018-01-18 18:35   ` Bjorn Helgaas
2018-01-18 18:35     ` Bjorn Helgaas
2018-01-18 21:34     ` Ladislav Michl
2018-01-18 21:34       ` Ladislav Michl
2018-01-19  1:54       ` weiyongjun (A)
2018-01-19  1:54         ` weiyongjun (A)
2018-01-19  1:54         ` weiyongjun (A)
2018-01-19  5:56         ` Julia Lawall
2018-01-19  5:56           ` Julia Lawall
2018-01-19  7:03         ` Ladislav Michl
2018-01-19  7:03           ` Ladislav Michl
2018-01-19  9:16           ` Ladislav Michl
2018-01-19  9:16             ` Ladislav Michl
2018-01-19  9:58     ` Ladislav Michl
2018-01-19  9:58       ` Ladislav Michl
2018-01-19 17:06       ` Ladislav Michl
2018-01-19 17:06         ` Ladislav Michl
2018-01-20  0:16         ` Ladislav Michl
2018-01-20  0:16           ` Ladislav Michl
2018-11-16 11:51           ` Lorenzo Pieralisi

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.