summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--dmi.c10
-rw-r--r--pci.c8
-rw-r--r--usb.c7
4 files changed, 24 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index afad4bc..2465a23 100644
--- a/NEWS
+++ b/NEWS
@@ -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)
diff --git a/dmi.c b/dmi.c
index b927994..1a59834 100644
--- a/dmi.c
+++ b/dmi.c
@@ -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("=> ");
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);
diff --git a/usb.c b/usb.c
index c275a89..6a52fe9 100644
--- a/usb.c
+++ b/usb.c
@@ -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': {