This reverts commit e002474158d1054a7a2ff9a66149384c639ff242. Commit e002474158d1 ("pci: pci-uclass: Dynamically allocate the PCI regions") changes 'struct pci_controller'.regions from pre-allocated array of regions to dynamically allocated, which unfortunately broken lots of boards that still use the non-DM PCI driver.
We may update every non-DM PCI board codes to do the dynamical allocation of PCI regions but that's a lot of work (e.g.: almost all Freescale PowerPC boards are broken now and need to be fixed). Let's do the easy way. Signed-off-by: Bin Meng <bmeng...@gmail.com> --- drivers/pci/pci-uclass.c | 14 ++++++-------- include/pci.h | 4 +++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index ba65f47..8a94ea2 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -907,7 +907,6 @@ static void decode_regions(struct pci_controller *hose, ofnode parent_node, int cells_per_record; struct bd_info *bd; const u32 *prop; - int max_regions; int len; int i; @@ -927,13 +926,7 @@ static void decode_regions(struct pci_controller *hose, ofnode parent_node, hose->region_count = 0; debug("%s: len=%d, cells_per_record=%d\n", __func__, len, cells_per_record); - - /* Dynamically allocate the regions array */ - max_regions = len / cells_per_record + CONFIG_NR_DRAM_BANKS; - hose->regions = (struct pci_region *) - calloc(1, max_regions * sizeof(struct pci_region)); - - for (i = 0; i < max_regions; i++, len -= cells_per_record) { + for (i = 0; i < MAX_PCI_REGIONS; i++, len -= cells_per_record) { u64 pci_addr, addr, size; int space_code; u32 flags; @@ -987,6 +980,11 @@ static void decode_regions(struct pci_controller *hose, ofnode parent_node, return; for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) { + if (hose->region_count == MAX_PCI_REGIONS) { + pr_err("maximum number of regions parsed, aborting\n"); + break; + } + if (bd->bi_dram[i].size) { pci_set_region(hose->regions + hose->region_count++, bd->bi_dram[i].start, diff --git a/include/pci.h b/include/pci.h index 5f36537..64dff55 100644 --- a/include/pci.h +++ b/include/pci.h @@ -610,6 +610,8 @@ extern void pci_cfgfunc_do_nothing(struct pci_controller* hose, pci_dev_t dev, extern void pci_cfgfunc_config_device(struct pci_controller* hose, pci_dev_t dev, struct pci_config_table *); +#define MAX_PCI_REGIONS 7 + #define INDIRECT_TYPE_NO_PCIE_LINK 1 /** @@ -650,7 +652,7 @@ struct pci_controller { * for PCI controllers and a separate UCLASS (or perhaps * UCLASS_PCI_GENERIC) is used for bridges. */ - struct pci_region *regions; + struct pci_region regions[MAX_PCI_REGIONS]; int region_count; struct pci_config_table *config_table; -- 2.7.4