/* SPDX-License-Identifier: LGPL-2.1+ */
+#include <errno.h>
+
#include "sd-hwdb.h"
#include "alloc-util.h"
#include "hwdb-util.h"
-#include "libudev-private.h"
+#include "libudev-list-internal.h"
/**
* SECTION:libudev-hwdb
struct udev_hwdb {
unsigned n_ref;
sd_hwdb *hwdb;
- struct udev_list properties_list;
+ struct udev_list *properties_list;
};
/**
* Returns: a hwdb context.
**/
_public_ struct udev_hwdb *udev_hwdb_new(struct udev *udev) {
+ _cleanup_(udev_list_freep) struct udev_list *list = NULL;
_cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb_internal = NULL;
struct udev_hwdb *hwdb;
int r;
r = sd_hwdb_new(&hwdb_internal);
- if (r < 0) {
- errno = -r;
- return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
+
+ list = udev_list_new(true);
+ if (!list)
+ return_with_errno(NULL, ENOMEM);
hwdb = new(struct udev_hwdb, 1);
- if (!hwdb) {
- errno = ENOMEM;
- return NULL;
- }
+ if (!hwdb)
+ return_with_errno(NULL, ENOMEM);
*hwdb = (struct udev_hwdb) {
.n_ref = 1,
.hwdb = TAKE_PTR(hwdb_internal),
+ .properties_list = TAKE_PTR(list),
};
- udev_list_init(udev, &hwdb->properties_list, true);
-
return hwdb;
}
assert(hwdb);
sd_hwdb_unref(hwdb->hwdb);
- udev_list_cleanup(&hwdb->properties_list);
+ udev_list_free(hwdb->properties_list);
return mfree(hwdb);
}
*
* Returns: a udev_list_entry.
*/
-_public_ struct udev_list_entry *udev_hwdb_get_properties_list_entry(struct udev_hwdb *hwdb, const char *modalias, unsigned int flags) {
+_public_ struct udev_list_entry *udev_hwdb_get_properties_list_entry(struct udev_hwdb *hwdb, const char *modalias, unsigned flags) {
const char *key, *value;
struct udev_list_entry *e;
assert_return_errno(hwdb, NULL, EINVAL);
assert_return_errno(modalias, NULL, EINVAL);
- udev_list_cleanup(&hwdb->properties_list);
+ udev_list_cleanup(hwdb->properties_list);
- SD_HWDB_FOREACH_PROPERTY(hwdb->hwdb, modalias, key, value) {
- if (udev_list_entry_add(&hwdb->properties_list, key, value) == NULL) {
- errno = ENOMEM;
- return NULL;
- }
- }
+ SD_HWDB_FOREACH_PROPERTY(hwdb->hwdb, modalias, key, value)
+ if (!udev_list_entry_add(hwdb->properties_list, key, value))
+ return_with_errno(NULL, ENOMEM);
- e = udev_list_get_entry(&hwdb->properties_list);
+ e = udev_list_get_entry(hwdb->properties_list);
if (!e)
- errno = ENODATA;
+ return_with_errno(NULL, ENODATA);
return e;
}