hwdb: Allow loading of v2 or v3 hwdb.bin files
PATCH 1/3 hwdb: Allow loading of v2 or v3 hwdb.bin files
The hwdb trie entry has been extended in a reverse-compatible way, but ELL had a strict check for the size of struct trie_entry that caused the load to fail. Instead of requiring an exact size, only make sure the entry is not too small.
--- ell/hwdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ell/hwdb.c +1 -1
@@ -136,7 +136,7 @@ LIB_EXPORT struct l_hwdb *l_hwdb_new(const char *pathname)if (L_LE64_TO_CPU (hdr->child_size) !=sizeof (struct trie_child )) goto failed; -if (L_LE64_TO_CPU (hdr->entry_size) !=sizeof (struct trie_entry )) +if (L_LE64_TO_CPU (hdr->entry_size) <sizeof (struct trie_entry )) goto failed; if (L_LE64_TO_CPU(hdr->header_size) + L_LE64_TO_CPU(hdr->nodes_size) +
Signature · 1 line
2.18.0
PATCH 2/3 unit: Print message if test-hwdb does not find a database
--- unit/test-hwdb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
unit/test-hwdb.c +3 -1
@@ -69,8 +69,10 @@ int main(int argc, char *argv[])struct l_hwdb *hwdb; hwdb =l_hwdb_new_default (); -if (!hwdb) +if (!hwdb) { +printf ("hwdb.bin not loaded\n" );return 0 ; + }l_hwdb_foreach (hwdb, print_entry,NULL );
Signature · 1 line
2.18.0
PATCH 3/3 unit: Report hwdb summary stats rather than dump the whole db
In reply to Mat Martineau--- unit/test-hwdb.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)
unit/test-hwdb.c +20 -8
@@ -24,10 +24,16 @@#include <config.h> #endif +#include <assert.h> #include <stdio.h> #include <ell/ell.h> +struct hwdb_stats { +int aliases; +int entries; +}; +static void print_modalias (struct l_hwdb *hwdb,const char *format, ...) {struct l_hwdb_entry *entries, *entry;
@@ -51,22 +57,26 @@ static void print_modalias(struct l_hwdb *hwdb, const char *format, ...)printf ("\n" ); } -static void print_entry (const char *modalias, -struct l_hwdb_entry *entries,void *user_data) +static void check_entry (const char *modalias,struct l_hwdb_entry *entries, +void *user_data) {struct l_hwdb_entry *entry; +struct hwdb_stats *stats = user_data; -printf ("%s\n" , modalias); - -for (entry = entries; entry; entry = entry->next) -printf (" %s=%s\n" , entry->key, entry->value); +assert (modalias); + stats->aliases++; -printf ("\n" ); +for (entry = entries; entry; entry = entry->next) { +assert (entry->key); +assert (entry->value); + stats->entries++; + } }int main (int argc,char *argv[]) {struct l_hwdb *hwdb; +struct hwdb_stats stats = {0 }; hwdb =l_hwdb_new_default ();if (!hwdb) {
@@ -74,7 +84,9 @@ int main(int argc, char *argv[])return 0 ; } -l_hwdb_foreach (hwdb, print_entry,NULL ); +l_hwdb_foreach (hwdb, check_entry, &stats); +printf ("Found %d aliases with %d total entries\n\n" , + stats.aliases, stats.entries);/* Bluetooth Interest Group Inc. */ print_modalias (hwdb,"OUI:000F79" );
Signature · 1 line
2.18.0
Hi Mat,
Quoted 7 lines · Mat Martineau
The hwdb trie entry has been extended in a reverse-compatible way, but ELL had a strict check for the size of struct
trie_entrythat caused the load to fail. Instead of requiring an exact size, only make sure the entry is not too small.--- ell/hwdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
All applied, thanks.
Regards,
-Denis