diff options
author | Thierry Vignaud <tv@mageia.org> | 2013-01-14 20:24:32 +0000 |
---|---|---|
committer | Thierry Vignaud <tv@mageia.org> | 2013-01-14 20:24:32 +0000 |
commit | cd134962064d824cb883c082d563bb7b7325827f (patch) | |
tree | 212a56caca3a5cc819869f0a648109c7c8fb3f76 | |
parent | a3d75c7c9d9aac00d72aef6088a9c2cd415bc213 (diff) | |
download | ldetect-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)
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | dmi.c | 10 | ||||
-rw-r--r-- | pci.c | 8 | ||||
-rw-r--r-- | usb.c | 7 |
4 files changed, 24 insertions, 3 deletions
@@ -1,3 +1,5 @@ +- dynamically resize memory when reaching max devices limit (mga#8320) + Version 0.12.4 - 11 December 2012, Thierry Vignaud - bump max devices number per bus from 100 to 300 (mga#8320) @@ -109,6 +109,7 @@ static struct criteria criteria_from_dmidecode(void) { char buf[BUF_SIZE]; struct criteria r = {0, NULL}; + size_t allocated = MAX_DEVICES; if (!(f = dmidecode_file ? fopen(dmidecode_file, "r") : popen("dmidecode", "r"))) { perror("dmidecode"); @@ -142,6 +143,10 @@ static struct criteria criteria_from_dmidecode(void) { char *s = buf + tab_level + 1; char *val = get_after_colon(s); if (val && lookup_field(category, s)) { + if (r.nb >= allocated) { + allocated = r.nb*2; + r.criteria = realloc(r.criteria, sizeof(struct criterion) * allocated); + } struct criterion *criterion = &r.criteria[r.nb++]; asprintf(&criterion->name, "%s/%s", category->cat_name, s); remove_ending_spaces(val); @@ -179,6 +184,7 @@ static struct dmi_entries entries_matching_criteria(struct criteria criteria) { enum state { in_constraints, in_implies } state = in_implies; int was_a_blank_line = 1; + size_t allocated = MAX_DEVICES; r.nb = 0; f = fh_open("dmitable"); @@ -210,6 +216,10 @@ static struct dmi_entries entries_matching_criteria(struct criteria criteria) { was_a_blank_line = 0; if (valid[refine]) { + if (r.nb >= allocated) { + allocated = r.nb*2; + r.entries = realloc(r.entries, sizeof(struct criterion) * allocated); + } struct dmi_entry *entry = &r.entries[r.nb++]; s += strlen("=> "); @@ -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); @@ -44,6 +44,7 @@ extern struct pciusb_entries usb_probe(void) { struct pciusb_entries r; struct pciusb_entry *e = NULL; char *vendor_text = NULL, *product_text = NULL; + size_t allocated = MAX_DEVICES; r.nb = 0; names_init("/usr/share/usb.ids"); @@ -63,7 +64,11 @@ extern struct pciusb_entries usb_probe(void) { r.entries = malloc(sizeof(struct pciusb_entry) * MAX_DEVICES); /* for further information on the format parsed by this state machine, * read /usr/share/doc/kernel-doc-X.Y.Z/usb/proc_usb_info.txt */ - for(line = 1; fgets(buf, sizeof(buf) - 1, f) && r.nb < MAX_DEVICES; line++) { + for(line = 1; fgets(buf, sizeof(buf) - 1, f); line++) { + if (r.nb >= allocated) { + allocated = r.nb*2; + r.entries = realloc(r.entries, sizeof(struct pciusb_entry) * allocated); + } switch (buf[0]) { case 'T': { |