Skip to content

Commit 49a6c16

Browse files
unicornxMani-Sadhasivam
authored andcommitted
PCI: cadence: Check for the existence of cdns_pcie::ops before using it
cdns_pcie::ops might not be populated by all the Cadence glue drivers. This is going to be true for the upcoming Sophgo platform which doesn't set the ops. Hence, add a check to prevent NULL pointer dereference. Signed-off-by: Chen Wang <unicorn_wang@outlook.com> [mani: reworded subject and description] Signed-off-by: Manivannan Sadhasivam <mani@kernel.org> Link: https://patch.msgid.link/35182ee1d972dfcd093a964e11205efcebbdc044.1757643388.git.unicorn_wang@outlook.com
1 parent 4e4a4f5 commit 49a6c16

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

drivers/pci/controller/cadence/pcie-cadence-host.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ static int cdns_pcie_host_init_address_translation(struct cdns_pcie_rc *rc)
531531
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR1(0), addr1);
532532
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC1(0), desc1);
533533

534-
if (pcie->ops->cpu_addr_fixup)
534+
if (pcie->ops && pcie->ops->cpu_addr_fixup)
535535
cpu_addr = pcie->ops->cpu_addr_fixup(pcie, cpu_addr);
536536

537537
addr0 = CDNS_PCIE_AT_OB_REGION_CPU_ADDR0_NBITS(12) |

drivers/pci/controller/cadence/pcie-cadence.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void cdns_pcie_set_outbound_region(struct cdns_pcie *pcie, u8 busnr, u8 fn,
9292
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC1(r), desc1);
9393

9494
/* Set the CPU address */
95-
if (pcie->ops->cpu_addr_fixup)
95+
if (pcie->ops && pcie->ops->cpu_addr_fixup)
9696
cpu_addr = pcie->ops->cpu_addr_fixup(pcie, cpu_addr);
9797

9898
addr0 = CDNS_PCIE_AT_OB_REGION_CPU_ADDR0_NBITS(nbits) |
@@ -123,7 +123,7 @@ void cdns_pcie_set_outbound_region_for_normal_msg(struct cdns_pcie *pcie,
123123
}
124124

125125
/* Set the CPU address */
126-
if (pcie->ops->cpu_addr_fixup)
126+
if (pcie->ops && pcie->ops->cpu_addr_fixup)
127127
cpu_addr = pcie->ops->cpu_addr_fixup(pcie, cpu_addr);
128128

129129
addr0 = CDNS_PCIE_AT_OB_REGION_CPU_ADDR0_NBITS(17) |

drivers/pci/controller/cadence/pcie-cadence.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,21 +468,21 @@ static inline u32 cdns_pcie_ep_fn_readl(struct cdns_pcie *pcie, u8 fn, u32 reg)
468468

469469
static inline int cdns_pcie_start_link(struct cdns_pcie *pcie)
470470
{
471-
if (pcie->ops->start_link)
471+
if (pcie->ops && pcie->ops->start_link)
472472
return pcie->ops->start_link(pcie);
473473

474474
return 0;
475475
}
476476

477477
static inline void cdns_pcie_stop_link(struct cdns_pcie *pcie)
478478
{
479-
if (pcie->ops->stop_link)
479+
if (pcie->ops && pcie->ops->stop_link)
480480
pcie->ops->stop_link(pcie);
481481
}
482482

483483
static inline bool cdns_pcie_link_up(struct cdns_pcie *pcie)
484484
{
485-
if (pcie->ops->link_up)
485+
if (pcie->ops && pcie->ops->link_up)
486486
return pcie->ops->link_up(pcie);
487487

488488
return true;

0 commit comments

Comments
 (0)