From cd134962064d824cb883c082d563bb7b7325827f Mon Sep 17 00:00:00 2001 From: Thierry Vignaud Date: Mon, 14 Jan 2013 20:24:32 +0000 Subject: dynamically resize memory when reaching max devices limit (mga#8320) --- pci.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'pci.c') diff --git a/pci.c b/pci.c index 370cb9c..c57d6c8 100644 --- a/pci.c +++ b/pci.c @@ -56,6 +56,7 @@ extern struct pciusb_entries pci_probe(void) { static struct pci_access *pacc; struct pci_dev *dev; char classbuf[128], vendorbuf[128], devbuf[128]; + size_t allocated = MAX_DEVICES; r.nb = 0; if ((access(proc_pci_path_default, R_OK) != 0) @@ -76,8 +77,11 @@ extern struct pciusb_entries pci_probe(void) { r.nb = 0; r.entries = malloc(sizeof(struct pciusb_entry) * MAX_DEVICES); - for (dev = pacc->devices; dev && r.nb < MAX_DEVICES; dev = dev->next, r.nb++) { - + for (dev = pacc->devices; dev; dev = dev->next, r.nb++) { + if (r.nb >= allocated) { + allocated = r.nb*2; + r.entries = realloc(r.entries, sizeof(struct pciusb_entry) * allocated); + } struct pciusb_entry *e = &r.entries[r.nb]; memset(buf, 0, CONFIG_SPACE_SIZE); // make sure not to retrieve values from previous devices pci_setup_cache(dev, (u8*)buf, CONFIG_SPACE_SIZE); -- cgit v1.2.1