diff options
author | Burt P <pburt0@gmail.com> | 2020-01-10 10:46:07 -0600 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2020-01-17 16:14:30 -0800 |
commit | 7114175cdb6ff611dfb164959c5aec2099f9e887 (patch) | |
tree | 3a4b654ff073049804cbb21a98703d6f4a0ffb85 /hardinfo | |
parent | 1b66b4442410ef6a7f9939845977d0fd9d840f71 (diff) |
pci_util: use GSList for pcid_list
Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'hardinfo')
-rw-r--r-- | hardinfo/gpu_util.c | 15 | ||||
-rw-r--r-- | hardinfo/pci_util.c | 73 |
2 files changed, 24 insertions, 64 deletions
diff --git a/hardinfo/gpu_util.c b/hardinfo/gpu_util.c index b203b426..d7b31d4d 100644 --- a/hardinfo/gpu_util.c +++ b/hardinfo/gpu_util.c @@ -397,15 +397,15 @@ gpud *gpu_get_device_list() { gpud *list = NULL; /* Can we just ask DRM someway? ... */ + /* TODO: yes. /sys/class/drm/card* */ /* Try PCI ... */ - pcid *pci_list = pci_get_device_list(0x300,0x3ff); - pcid *curr = pci_list; + pcid_list pci_list = pci_get_device_list(0x300,0x3ff); + GSList *l = pci_list; - int c = pcid_list_count(pci_list); - - if (c > 0) { - while(curr) { + if (l) { + while(l) { + pcid *curr = (pcid*)l->data; char *pci_loc = NULL; gpud *new_gpu = gpud_new(); new_gpu->pci_dev = curr; @@ -457,10 +457,11 @@ gpud *gpu_get_device_list() { gpud_list_append(list, new_gpu); free(pci_loc); - curr=curr->next; + l=l->next; } /* don't pcid_list_free(pci_list); They will be freed by gpud_free() */ + g_slist_free(pci_list); /* just the linking data */ return list; } diff --git a/hardinfo/pci_util.c b/hardinfo/pci_util.c index 3078f477..9502b23b 100644 --- a/hardinfo/pci_util.c +++ b/hardinfo/pci_util.c @@ -151,10 +151,6 @@ static gboolean pci_lookup_ids(pcid *d) { return ret; } -pcid *pcid_new() { - return g_new0(pcid, 1); -} - void pcid_free(pcid *s) { if (s) { g_free(s->slot_str); @@ -169,36 +165,6 @@ void pcid_free(pcid *s) { } } -void pcid_list_free(pcid *s) { - pcid *n; - while(s != NULL) { - n = s->next; - pcid_free(s); - s = n; - } -} - -/* returns number of items after append */ -static int pcid_list_append(pcid *l, pcid *n) { - int c = 0; - while(l != NULL) { - c++; - if (l->next == NULL) { - if (n != NULL) { - l->next = n; - c++; - } - break; - } - l = l->next; - } - return c; -} - -int pcid_list_count(pcid *s) { - return pcid_list_append(s, NULL); -} - static char *lspci_line_value(char *line, const char *prefix) { if (g_str_has_prefix(g_strstrip(line), prefix)) { line += strlen(prefix) + 1; @@ -408,11 +374,12 @@ pcid *pci_get_device(uint32_t dom, uint32_t bus, uint32_t dev, uint32_t func) { return s; } -static pcid *pci_get_device_list_lspci(uint32_t class_min, uint32_t class_max) { +static pcid_list pci_get_device_list_lspci(uint32_t class_min, uint32_t class_max) { if (nolspci) return NULL; gboolean spawned; gchar *out, *err, *p, *next_nl; - pcid *head = NULL, *nd; + pcid_list dl = NULL; + pcid *nd; uint32_t dom, bus, dev, func, cls; int ec; @@ -429,12 +396,7 @@ static pcid *pci_get_device_list_lspci(uint32_t class_min, uint32_t class_max) { if (cls >= class_min && cls <= class_max) { nd = pci_get_device(dom, bus, dev, func); pci_fill_details(nd); - - if (head == NULL) { - head = nd; - } else { - pcid_list_append(head, nd); - } + dl = g_slist_append(dl, nd); } } p = next_nl + 1; @@ -442,11 +404,12 @@ static pcid *pci_get_device_list_lspci(uint32_t class_min, uint32_t class_max) { g_free(out); g_free(err); } - return head; + return dl; } -static pcid *pci_get_device_list_sysfs(uint32_t class_min, uint32_t class_max) { - pcid *head = NULL, *nd; +static pcid_list pci_get_device_list_sysfs(uint32_t class_min, uint32_t class_max) { + pcid_list dl = NULL; + pcid *nd; uint32_t dom, bus, dev, func, cls; int ec; @@ -466,11 +429,7 @@ static pcid *pci_get_device_list_sysfs(uint32_t class_min, uint32_t class_max) { if (cls >= class_min && cls <= class_max) { nd = pci_get_device(dom, bus, dev, func); pci_fill_details(nd); - if (head == NULL) { - head = nd; - } else { - pcid_list_append(head, nd); - } + dl = g_slist_append(dl, nd); } } g_free(cstr); @@ -478,14 +437,14 @@ static pcid *pci_get_device_list_sysfs(uint32_t class_min, uint32_t class_max) { } } g_dir_close(d); - return head; + return dl; } -pcid *pci_get_device_list(uint32_t class_min, uint32_t class_max) { - pcid *ret = NULL; - ret = pci_get_device_list_sysfs(class_min, class_max); - if (!ret) - ret = pci_get_device_list_lspci(class_min, class_max); - return ret; +pcid_list pci_get_device_list(uint32_t class_min, uint32_t class_max) { + pcid_list dl = NULL; + dl = pci_get_device_list_sysfs(class_min, class_max); + if (!dl) + dl = pci_get_device_list_lspci(class_min, class_max); + return dl; } |