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