diff options
author | Niklas Cassel <niklas.cassel@axis.com> | 2017-04-03 18:35:12 -0400 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2017-04-04 09:24:25 -0400 |
commit | 794a8604fe6e4a311373cde57a86ad4aab9d32b8 (patch) | |
tree | 6e6a8ef04b340b3e0a9044ea506e2102c8fdc249 | |
parent | 6665f8a307696a0edd4c1233b4cc0f5ed6083525 (diff) |
PCI: dwc: Fix dw_pcie_ops NULL pointer dereference
Fix a crash from dereferencing a NULL dw_pcie_ops pointer. For example,
on ARTPEC-6:
Unable to handle kernel NULL pointer dereference at virtual address 00000004
pgd = c0204000
[00000004] *pgd=00000000
Internal error: Oops: 5 [#1] SMP ARM
Modules linked in:
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.11.0-rc3-next-20170321 #1
Hardware name: Axis ARTPEC-6 Platform
task: db098000 task.stack: db096000
PC is at dw_pcie_writel_dbi+0x2c/0xd0
Prior to 442ec4c04d12 ("PCI: dwc: all: Split struct pcie_port into
host-only and core structures"), every driver had a struct pcie_host_ops
with function pointers, typically used as:
if (pp->ops->readl_rc)
return pp->ops->readl_rc(...);
442ec4c04d12 split struct pcie_host_ops into two pieces: struct
dw_pcie_host_ops and struct dw_pcie_ops, so the above became:
if (pci->ops->readl_dbi)
return pci->ops->readl_dbi(...);
But pcie-artpec6.c and pcie-designware-plat.c don't need the dw_pcie_ops
pointers and didn't supply a pci->ops struct, which leads to NULL pointer
dereferences.
Supply an empty struct dw_pcie_ops to avoid the NULL pointer dereferences.
[bhelgaas: changelog]
Fixes: 442ec4c04d12 ("PCI: dwc: all: Split struct pcie_port into host-only and core structures")
Signed-off-by: Niklas Cassel <niklas.cassel@axis.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Kishon Vijay Abraham I <kishon@ti.com>
Acked-by: Joao Pinto <jpinto@synopsys.com>
-rw-r--r-- | drivers/pci/dwc/pcie-artpec6.c | 4 | ||||
-rw-r--r-- | drivers/pci/dwc/pcie-designware-plat.c | 4 |
2 files changed, 8 insertions, 0 deletions
diff --git a/drivers/pci/dwc/pcie-artpec6.c b/drivers/pci/dwc/pcie-artpec6.c index fcd3ef845883..6d23683c0892 100644 --- a/drivers/pci/dwc/pcie-artpec6.c +++ b/drivers/pci/dwc/pcie-artpec6.c | |||
@@ -234,6 +234,9 @@ static int artpec6_add_pcie_port(struct artpec6_pcie *artpec6_pcie, | |||
234 | return 0; | 234 | return 0; |
235 | } | 235 | } |
236 | 236 | ||
237 | static const struct dw_pcie_ops dw_pcie_ops = { | ||
238 | }; | ||
239 | |||
237 | static int artpec6_pcie_probe(struct platform_device *pdev) | 240 | static int artpec6_pcie_probe(struct platform_device *pdev) |
238 | { | 241 | { |
239 | struct device *dev = &pdev->dev; | 242 | struct device *dev = &pdev->dev; |
@@ -252,6 +255,7 @@ static int artpec6_pcie_probe(struct platform_device *pdev) | |||
252 | return -ENOMEM; | 255 | return -ENOMEM; |
253 | 256 | ||
254 | pci->dev = dev; | 257 | pci->dev = dev; |
258 | pci->ops = &dw_pcie_ops; | ||
255 | 259 | ||
256 | artpec6_pcie->pci = pci; | 260 | artpec6_pcie->pci = pci; |
257 | 261 | ||
diff --git a/drivers/pci/dwc/pcie-designware-plat.c b/drivers/pci/dwc/pcie-designware-plat.c index b6c832ba39dd..f20d494922ab 100644 --- a/drivers/pci/dwc/pcie-designware-plat.c +++ b/drivers/pci/dwc/pcie-designware-plat.c | |||
@@ -86,6 +86,9 @@ static int dw_plat_add_pcie_port(struct pcie_port *pp, | |||
86 | return 0; | 86 | return 0; |
87 | } | 87 | } |
88 | 88 | ||
89 | static const struct dw_pcie_ops dw_pcie_ops = { | ||
90 | }; | ||
91 | |||
89 | static int dw_plat_pcie_probe(struct platform_device *pdev) | 92 | static int dw_plat_pcie_probe(struct platform_device *pdev) |
90 | { | 93 | { |
91 | struct device *dev = &pdev->dev; | 94 | struct device *dev = &pdev->dev; |
@@ -103,6 +106,7 @@ static int dw_plat_pcie_probe(struct platform_device *pdev) | |||
103 | return -ENOMEM; | 106 | return -ENOMEM; |
104 | 107 | ||
105 | pci->dev = dev; | 108 | pci->dev = dev; |
109 | pci->ops = &dw_pcie_ops; | ||
106 | 110 | ||
107 | dw_plat_pcie->pci = pci; | 111 | dw_plat_pcie->pci = pci; |
108 | 112 | ||