summaryrefslogtreecommitdiffstats
path: root/pci.c
diff options
context:
space:
mode:
authorThierry Vignaud <tv@mageia.org>2013-01-14 20:24:32 +0000
committerThierry Vignaud <tv@mageia.org>2013-01-14 20:24:32 +0000
commitcd134962064d824cb883c082d563bb7b7325827f (patch)
tree212a56caca3a5cc819869f0a648109c7c8fb3f76 /pci.c
parenta3d75c7c9d9aac00d72aef6088a9c2cd415bc213 (diff)
downloadldetect-cd134962064d824cb883c082d563bb7b7325827f.tar
ldetect-cd134962064d824cb883c082d563bb7b7325827f.tar.gz
ldetect-cd134962064d824cb883c082d563bb7b7325827f.tar.bz2
ldetect-cd134962064d824cb883c082d563bb7b7325827f.tar.xz
ldetect-cd134962064d824cb883c082d563bb7b7325827f.zip
dynamically resize memory when reaching max devices limit (mga#8320)
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);