WSL2-Linux-Kernel/drivers/pci/controller/cadence
Bjorn Helgaas 053ca37c87 PCI: j721e: Initialize pcie->cdns_pcie before using it
Christian reported a NULL pointer dereference in j721e_pcie_probe() caused
by 19e863828a ("PCI: j721e: Drop redundant struct device *"), which
removed struct j721e_pcie.dev since there's another copy in struct
cdns_pcie.dev reachable via j721e_pcie->cdns_pcie->dev.

The problem is that j721e_pcie->cdns_pcie was dereferenced before being
initialized:

  j721e_pcie_probe
    pcie = devm_kzalloc()             # struct j721e_pcie
    j721e_pcie_ctrl_init(pcie)
      dev = pcie->cdns_pcie->dev      <-- dereference cdns_pcie
    switch (mode) {
    case PCI_MODE_RC:
      cdns_pcie = ...                 # alloc as part of pci_host_bridge
      pcie->cdns_pcie = cdns_pcie     <-- initialize pcie->cdns_pcie

Move the cdns_pcie initialization earlier so it is done before it is used.
This also simplifies the error exits.

Fixes: 19e863828a ("PCI: j721e: Drop redundant struct device *")
Link: https://lore.kernel.org/r/20220127222951.GA144828@bhelgaas
Link: https://lore.kernel.org/r/20220124122132.435743-1-christian.gmeiner@gmail.com
Reported-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Tested-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2022-02-01 11:13:52 -06:00
..
Kconfig PCI: j721e: Add TI J721E PCIe driver 2020-08-03 14:49:55 +01:00
Makefile PCI: j721e: Add TI J721E PCIe driver 2020-08-03 14:49:55 +01:00
pci-j721e.c PCI: j721e: Initialize pcie->cdns_pcie before using it 2022-02-01 11:13:52 -06:00
pcie-cadence-ep.c Merge branch 'remotes/lorenzo/pci/endpoint' 2021-09-02 14:56:51 -05:00
pcie-cadence-host.c PCI: cadence: Add quirk flag to set minimum delay in LTSSM Detect.Quiet state 2021-08-19 15:37:51 +01:00
pcie-cadence-plat.c PCI: cadence: Prefer of_device_get_match_data() 2022-01-03 15:01:04 -06:00
pcie-cadence.c PCI: cadence: Add quirk flag to set minimum delay in LTSSM Detect.Quiet state 2021-08-19 15:37:51 +01:00
pcie-cadence.h PCI: Correct misspelled words 2022-01-07 20:43:23 -06:00