Skip to content

Commit a231707

Browse files
Aleksandr Mishinbjorn-helgaas
authored andcommitted
PCI: keystone: Fix NULL pointer dereference in case of DT error in ks_pcie_setup_rc_app_regs()
If IORESOURCE_MEM is not provided in Device Tree due to any error, resource_list_first_type() will return NULL and pci_parse_request_of_pci_ranges() will just emit a warning. This will cause a NULL pointer dereference. Fix this bug by adding NULL return check. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 0f71c60 ("PCI: dwc: Remove storing of PCI resources") Link: https://lore.kernel.org/linux-pci/[email protected] Suggested-by: Bjorn Helgaas <[email protected]> Suggested-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Aleksandr Mishin <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]>
1 parent 9ffa0e7 commit a231707

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

drivers/pci/controller/dwc/pci-keystone.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,17 +400,22 @@ static const struct irq_domain_ops ks_pcie_intx_irq_domain_ops = {
400400
.xlate = irq_domain_xlate_onetwocell,
401401
};
402402

403-
static void ks_pcie_setup_rc_app_regs(struct keystone_pcie *ks_pcie)
403+
static int ks_pcie_setup_rc_app_regs(struct keystone_pcie *ks_pcie)
404404
{
405405
u32 val;
406406
u32 num_viewport = ks_pcie->num_viewport;
407407
struct dw_pcie *pci = ks_pcie->pci;
408408
struct dw_pcie_rp *pp = &pci->pp;
409-
u64 start, end;
409+
struct resource_entry *entry;
410410
struct resource *mem;
411+
u64 start, end;
411412
int i;
412413

413-
mem = resource_list_first_type(&pp->bridge->windows, IORESOURCE_MEM)->res;
414+
entry = resource_list_first_type(&pp->bridge->windows, IORESOURCE_MEM);
415+
if (!entry)
416+
return -ENODEV;
417+
418+
mem = entry->res;
414419
start = mem->start;
415420
end = mem->end;
416421

@@ -421,7 +426,7 @@ static void ks_pcie_setup_rc_app_regs(struct keystone_pcie *ks_pcie)
421426
ks_pcie_clear_dbi_mode(ks_pcie);
422427

423428
if (ks_pcie->is_am6)
424-
return;
429+
return 0;
425430

426431
val = ilog2(OB_WIN_SIZE);
427432
ks_pcie_app_writel(ks_pcie, OB_SIZE, val);
@@ -438,6 +443,8 @@ static void ks_pcie_setup_rc_app_regs(struct keystone_pcie *ks_pcie)
438443
val = ks_pcie_app_readl(ks_pcie, CMD_STATUS);
439444
val |= OB_XLAT_EN_VAL;
440445
ks_pcie_app_writel(ks_pcie, CMD_STATUS, val);
446+
447+
return 0;
441448
}
442449

443450
static void __iomem *ks_pcie_other_map_bus(struct pci_bus *bus,
@@ -798,7 +805,10 @@ static int __init ks_pcie_host_init(struct dw_pcie_rp *pp)
798805
return ret;
799806

800807
ks_pcie_stop_link(pci);
801-
ks_pcie_setup_rc_app_regs(ks_pcie);
808+
ret = ks_pcie_setup_rc_app_regs(ks_pcie);
809+
if (ret)
810+
return ret;
811+
802812
writew(PCI_IO_RANGE_TYPE_32 | (PCI_IO_RANGE_TYPE_32 << 8),
803813
pci->dbi_base + PCI_IO_BASE);
804814

0 commit comments

Comments
 (0)