summaryrefslogtreecommitdiffstats
path: root/tools/make-pci-ids.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xtools/make-pci-ids.py39
1 files changed, 7 insertions, 32 deletions
diff --git a/tools/make-pci-ids.py b/tools/make-pci-ids.py
index 093637d7..0aadef14 100755
--- a/tools/make-pci-ids.py
+++ b/tools/make-pci-ids.py
@@ -35,6 +35,9 @@ CODE_PREFIX = """\
#include <config.h>
#include <stddef.h>
+#include <stdlib.h>
+
+#include "wsutil/array.h"
#include "pci-ids.h"
@@ -59,38 +62,10 @@ typedef struct
"""
CODE_POSTFIX = """
-static pci_vid_index_t const *get_vid_index(uint16_t vid)
+static int vid_search(const void *key, const void *tbl_entry)
{
- uint32_t start_index = 0;
- uint32_t end_index = 0;
- uint32_t idx = 0;
-
- end_index = sizeof(pci_vid_index)/sizeof(pci_vid_index[0]);
-
- while(start_index != end_index)
- {
- if(end_index - start_index == 1)
- {
- if(pci_vid_index[start_index].vid == vid)
- return &pci_vid_index[start_index];
-
- break;
- }
-
- idx = (start_index + end_index)/2;
-
- if(pci_vid_index[idx].vid < vid)
- start_index = idx;
- else
- if(pci_vid_index[idx].vid > vid)
- end_index = idx;
- else
- return &pci_vid_index[idx];
-
- }
-
- return NULL;
-
+ return (int)*(const uint16_t *)key -
+ (int)((const pci_vid_index_t *)tbl_entry)->vid;
}
const char *pci_id_str(uint16_t vid, uint16_t did, uint16_t svid, uint16_t ssid)
@@ -100,7 +75,7 @@ const char *pci_id_str(uint16_t vid, uint16_t did, uint16_t svid, uint16_t ssid)
pci_vid_index_t const *index_ptr;
pci_id_t const *ids_ptr;
- index_ptr = get_vid_index(vid);
+ index_ptr = bsearch(&vid, pci_vid_index, array_length(pci_vid_index), sizeof pci_vid_index[0], vid_search);
if(index_ptr == NULL)
return not_found;