summaryrefslogtreecommitdiffstats
path: root/pci.c
diff options
context:
space:
mode:
Diffstat (limited to 'pci.c')
-rw-r--r--pci.c8
1 files changed, 6 insertions, 2 deletions
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);