Skip to content

Commit e38de94

Browse files
committed
Merge branch 'pci/controller/al'
- Check IORESOURCE_BUS existence to avoid NULL pointer dereference (Aleksandr Mishin) * pci/controller/al: PCI: al: Check IORESOURCE_BUS existence during probe
2 parents 3785393 + a9927c2 commit e38de94

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

drivers/pci/controller/dwc/pcie-al.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,18 +242,24 @@ static struct pci_ops al_child_pci_ops = {
242242
.write = pci_generic_config_write,
243243
};
244244

245-
static void al_pcie_config_prepare(struct al_pcie *pcie)
245+
static int al_pcie_config_prepare(struct al_pcie *pcie)
246246
{
247247
struct al_pcie_target_bus_cfg *target_bus_cfg;
248248
struct dw_pcie_rp *pp = &pcie->pci->pp;
249249
unsigned int ecam_bus_mask;
250+
struct resource_entry *ft;
250251
u32 cfg_control_offset;
252+
struct resource *bus;
251253
u8 subordinate_bus;
252254
u8 secondary_bus;
253255
u32 cfg_control;
254256
u32 reg;
255-
struct resource *bus = resource_list_first_type(&pp->bridge->windows, IORESOURCE_BUS)->res;
256257

258+
ft = resource_list_first_type(&pp->bridge->windows, IORESOURCE_BUS);
259+
if (!ft)
260+
return -ENODEV;
261+
262+
bus = ft->res;
257263
target_bus_cfg = &pcie->target_bus_cfg;
258264

259265
ecam_bus_mask = (pcie->ecam_size >> PCIE_ECAM_BUS_SHIFT) - 1;
@@ -287,6 +293,8 @@ static void al_pcie_config_prepare(struct al_pcie *pcie)
287293
FIELD_PREP(CFG_CONTROL_SEC_BUS_MASK, secondary_bus);
288294

289295
al_pcie_controller_writel(pcie, cfg_control_offset, reg);
296+
297+
return 0;
290298
}
291299

292300
static int al_pcie_host_init(struct dw_pcie_rp *pp)
@@ -305,7 +313,9 @@ static int al_pcie_host_init(struct dw_pcie_rp *pp)
305313
if (rc)
306314
return rc;
307315

308-
al_pcie_config_prepare(pcie);
316+
rc = al_pcie_config_prepare(pcie);
317+
if (rc)
318+
return rc;
309319

310320
return 0;
311321
}

0 commit comments

Comments
 (0)