* [PATCH] PCI: designware-ep: Fix NULL pointer dereference error
@ 2021-03-05 2:59 Kishon Vijay Abraham I
2021-03-05 16:19 ` Rob Herring
0 siblings, 1 reply; 2+ messages in thread
From: Kishon Vijay Abraham I @ 2021-03-05 2:59 UTC (permalink / raw)
To: Kishon Vijay Abraham I, Jingoo Han, Gustavo Pimentel,
Lorenzo Pieralisi, Rob Herring, Bjorn Helgaas
Cc: linux-pci, linux-kernel, Lokesh Vutla
commit 281f1f99cf3a ("PCI: dwc: Detect number of iATU windows") detected
the number of inbound and outbound windows dynamically at runtime in
dw_pcie_setup(). However pcie-designware-ep.c accessed the variables
holding the number of inbound and outbound windows even before
dw_pcie_setup() was invoked. Fix the sequence here.
Fixes: 281f1f99cf3a ("PCI: dwc: Detect number of iATU windows")
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
.../pci/controller/dwc/pcie-designware-ep.c | 44 ++++++++++---------
1 file changed, 23 insertions(+), 21 deletions(-)
diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c
index 1c25d8337151..2c0f837af458 100644
--- a/drivers/pci/controller/dwc/pcie-designware-ep.c
+++ b/drivers/pci/controller/dwc/pcie-designware-ep.c
@@ -636,9 +636,11 @@ static unsigned int dw_pcie_ep_find_ext_capability(struct dw_pcie *pci, int cap)
int dw_pcie_ep_init_complete(struct dw_pcie_ep *ep)
{
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+ struct device *dev = pci->dev;
unsigned int offset;
unsigned int nbars;
u8 hdr_type;
+ void *addr;
u32 reg;
int i;
@@ -665,6 +667,27 @@ int dw_pcie_ep_init_complete(struct dw_pcie_ep *ep)
}
dw_pcie_setup(pci);
+
+ ep->ib_window_map = devm_kcalloc(dev,
+ BITS_TO_LONGS(pci->num_ib_windows),
+ sizeof(long),
+ GFP_KERNEL);
+ if (!ep->ib_window_map)
+ return -ENOMEM;
+
+ ep->ob_window_map = devm_kcalloc(dev,
+ BITS_TO_LONGS(pci->num_ob_windows),
+ sizeof(long),
+ GFP_KERNEL);
+ if (!ep->ob_window_map)
+ return -ENOMEM;
+
+ addr = devm_kcalloc(dev, pci->num_ob_windows, sizeof(phys_addr_t),
+ GFP_KERNEL);
+ if (!addr)
+ return -ENOMEM;
+ ep->outbound_addr = addr;
+
dw_pcie_dbi_ro_wr_dis(pci);
return 0;
@@ -674,7 +697,6 @@ EXPORT_SYMBOL_GPL(dw_pcie_ep_init_complete);
int dw_pcie_ep_init(struct dw_pcie_ep *ep)
{
int ret;
- void *addr;
u8 func_no;
struct resource *res;
struct pci_epc *epc;
@@ -712,26 +734,6 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
ep->phys_base = res->start;
ep->addr_size = resource_size(res);
- ep->ib_window_map = devm_kcalloc(dev,
- BITS_TO_LONGS(pci->num_ib_windows),
- sizeof(long),
- GFP_KERNEL);
- if (!ep->ib_window_map)
- return -ENOMEM;
-
- ep->ob_window_map = devm_kcalloc(dev,
- BITS_TO_LONGS(pci->num_ob_windows),
- sizeof(long),
- GFP_KERNEL);
- if (!ep->ob_window_map)
- return -ENOMEM;
-
- addr = devm_kcalloc(dev, pci->num_ob_windows, sizeof(phys_addr_t),
- GFP_KERNEL);
- if (!addr)
- return -ENOMEM;
- ep->outbound_addr = addr;
-
if (pci->link_gen < 1)
pci->link_gen = of_pci_get_max_link_speed(np);
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] PCI: designware-ep: Fix NULL pointer dereference error
2021-03-05 2:59 [PATCH] PCI: designware-ep: Fix NULL pointer dereference error Kishon Vijay Abraham I
@ 2021-03-05 16:19 ` Rob Herring
0 siblings, 0 replies; 2+ messages in thread
From: Rob Herring @ 2021-03-05 16:19 UTC (permalink / raw)
To: Kishon Vijay Abraham I
Cc: Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi, Bjorn Helgaas,
PCI, linux-kernel, Lokesh Vutla
On Thu, Mar 4, 2021 at 8:59 PM Kishon Vijay Abraham I <kishon@ti.com> wrote:
>
> commit 281f1f99cf3a ("PCI: dwc: Detect number of iATU windows") detected
> the number of inbound and outbound windows dynamically at runtime in
> dw_pcie_setup(). However pcie-designware-ep.c accessed the variables
> holding the number of inbound and outbound windows even before
> dw_pcie_setup() was invoked. Fix the sequence here.
>
> Fixes: 281f1f99cf3a ("PCI: dwc: Detect number of iATU windows")
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
> .../pci/controller/dwc/pcie-designware-ep.c | 44 ++++++++++---------
> 1 file changed, 23 insertions(+), 21 deletions(-)
There's already another fix posted. I prodded Bjorn to apply it.
Rob
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-03-05 16:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05 2:59 [PATCH] PCI: designware-ep: Fix NULL pointer dereference error Kishon Vijay Abraham I
2021-03-05 16:19 ` Rob Herring
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.