aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hardinfo/gpu_util.c15
-rw-r--r--hardinfo/pci_util.c73
-rw-r--r--includes/pci_util.h21
-rw-r--r--modules/devices/pci.c22
4 files changed, 44 insertions, 87 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;
}
diff --git a/includes/pci_util.h b/includes/pci_util.h
index 2a9e4a4b..6178be21 100644
--- a/includes/pci_util.h
+++ b/includes/pci_util.h
@@ -53,26 +53,25 @@ typedef struct pcid {
/* ... */
- struct pcid *next; /* this is a linked list */
} pcid;
+pcid *pci_get_device(uint32_t dom, uint32_t bus, uint32_t dev, uint32_t func);
+pcid *pci_get_device_str(const char *addy);
+#define pcid_new() g_new0(pcid, 1)
+void pcid_free(pcid *);
+
+typedef GSList* pcid_list;
/* examples:
* to get all pci devices:
* pcid *list = pci_get_device_list(0, 0);
* to get all display controllers:
* pcid *list = pci_get_device_list(0x300, 0x3ff);
*/
-pcid *pci_get_device_list(uint32_t class_min, uint32_t class_max);
-int pcid_list_count(pcid *);
-void pcid_list_free(pcid *);
-
-pcid *pci_get_device(uint32_t dom, uint32_t bus, uint32_t dev, uint32_t func);
-pcid *pci_get_device_str(const char *addy);
-
-void pcid_free(pcid *);
-
-char *pci_lookup_ids_vendor_str(uint32_t id);
+pcid_list pci_get_device_list(uint32_t class_min, uint32_t class_max);
+#define pcid_list_count(l) g_slist_length(l);
+#define pcid_list_free(l) g_slist_free_full(l, (GDestroyNotify)pcid_free)
const gchar *find_pci_ids_file();
+char *pci_lookup_ids_vendor_str(uint32_t id);
#endif
diff --git a/modules/devices/pci.c b/modules/devices/pci.c
index 14f51a94..04a8a0cf 100644
--- a/modules/devices/pci.c
+++ b/modules/devices/pci.c
@@ -176,19 +176,17 @@ void scan_pci_do(void) {
gchar *pci_icons = g_strdup("");
- pcid *list = pci_get_device_list(0,0);
- pcid *curr = list;
-
- int c = pcid_list_count(list);
-
- if (c > 0) {
- while(curr) {
- pci_icons = _pci_dev(curr, pci_icons);
- curr=curr->next;
- }
-
- pcid_list_free(list);
+ pcid_list list = pci_get_device_list(0,0);
+ GSList *l = list;
+
+ int c = 0;
+ while(l) {
+ pcid *curr = (pcid*)l->data;
+ pci_icons = _pci_dev(curr, pci_icons);
+ c++;
+ l=l->next;
}
+ pcid_list_free(list);
if (c) {
pci_list = g_strconcat(pci_list, "[$ShellParam$]\n", "ViewType=1\n", pci_icons, NULL);