X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibudev%2Flibudev-hwdb.c;h=42ab6d9a6b356748d21d3ecfd433a71966ed6450;hb=76d14b876a1c286ea62c4e0e4fc5ba3c695e169f;hp=a3f815f83f7d32455cf0d9e1e3d12ba402546b82;hpb=f2d433e178df7df01a836e95775261e1d85ec60d;p=elogind.git diff --git a/src/libudev/libudev-hwdb.c b/src/libudev/libudev-hwdb.c index a3f815f83..42ab6d9a6 100644 --- a/src/libudev/libudev-hwdb.c +++ b/src/libudev/libudev-hwdb.c @@ -1,7 +1,7 @@ /*** This file is part of systemd. - Copyright 2012 Kay Sievers + Copyright 2012 Kay Sievers Copyright 2008 Alan Jenkins systemd is free software; you can redistribute it and/or modify it @@ -169,8 +169,8 @@ static int trie_fnmatch_f(struct udev_hwdb *hwdb, const struct trie_node_f *node linebuf_rem_char(buf); } - if (node->values_count && fnmatch(linebuf_get(buf), search, 0) == 0) - for (i = 0; i < node->values_count; i++) { + if (le64toh(node->values_count) && fnmatch(linebuf_get(buf), search, 0) == 0) + for (i = 0; i < le64toh(node->values_count); i++) { err = hwdb_add_property(hwdb, trie_string(hwdb, trie_node_values(hwdb, node)[i].key_off), trie_string(hwdb, trie_node_values(hwdb, node)[i].value_off)); if (err < 0) @@ -236,7 +236,7 @@ static int trie_search_f(struct udev_hwdb *hwdb, const char *search) { if (search[i] == '\0') { size_t n; - for (n = 0; n < node->values_count; n++) { + for (n = 0; n < le64toh(node->values_count); n++) { err = hwdb_add_property(hwdb, trie_string(hwdb, trie_node_values(hwdb, node)[n].key_off), trie_string(hwdb, trie_node_values(hwdb, node)[n].value_off)); if (err < 0) @@ -338,10 +338,10 @@ _public_ struct udev_hwdb *udev_hwdb_unref(struct udev_hwdb *hwdb) { hwdb->refcount--; if (hwdb->refcount > 0) return hwdb; - if (hwdb->f) - fclose(hwdb->f); if (hwdb->map) munmap((void *)hwdb->map, hwdb->st.st_size); + if (hwdb->f) + fclose(hwdb->f); udev_list_cleanup(&hwdb->properties_list); free(hwdb); return NULL; @@ -356,7 +356,7 @@ bool udev_hwdb_validate(struct udev_hwdb *hwdb) { return false; if (fstat(fileno(hwdb->f), &st) < 0) return true; - if (ts_usec(&hwdb->st.st_mtim) != ts_usec(&st.st_mtim)) + if (timespec_load(&hwdb->st.st_mtim) != timespec_load(&st.st_mtim)) return true; return false; } @@ -377,11 +377,12 @@ bool udev_hwdb_validate(struct udev_hwdb *hwdb) { _public_ struct udev_list_entry *udev_hwdb_get_properties_list_entry(struct udev_hwdb *hwdb, const char *modalias, unsigned int flags) { int err; - if (!hwdb->f) { + if (!hwdb || !hwdb->f) { errno = EINVAL; return NULL; } + udev_list_cleanup(&hwdb->properties_list); err = trie_search_f(hwdb, modalias); if (err < 0) { errno = -err;