diff options
author | Lennart Poettering <lennart@poettering.net> | 2017-09-09 22:31:09 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-09-09 22:31:09 +0200 |
commit | 309f631d41374ec8e724b1debdafd7ae40489b6e (patch) | |
tree | 29f31e19ea0aefbb860c5abfa9294e41a799d521 /src/libudev/libudev-hwdb.c | |
parent | 0aabe74749918c97e9562631fcc55e41ec3a73cd (diff) | |
download | systemd-309f631d41374ec8e724b1debdafd7ae40489b6e.tar.gz |
libudev: add missing errno initialization/error propagation (#6781)
In libudev (which es much older code than the rest of systemd), we
propagate errors in functions not returning an int, via (positive) errno
(i.e. libc-style), and as negative Exyz values in those returning an int
(much preferred, i.e. Linux kernel style). Let's fix up a few place,
where this was incorrectly done, or not done at all.
Fixes: #6613
Diffstat (limited to 'src/libudev/libudev-hwdb.c')
-rw-r--r-- | src/libudev/libudev-hwdb.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/libudev/libudev-hwdb.c b/src/libudev/libudev-hwdb.c index a53f000015..4bdc37d973 100644 --- a/src/libudev/libudev-hwdb.c +++ b/src/libudev/libudev-hwdb.c @@ -57,15 +57,19 @@ _public_ struct udev_hwdb *udev_hwdb_new(struct udev *udev) { struct udev_hwdb *hwdb; int r; - assert_return(udev, NULL); + assert_return_errno(udev, NULL, EINVAL); r = sd_hwdb_new(&hwdb_internal); - if (r < 0) + if (r < 0) { + errno = -r; return NULL; + } hwdb = new0(struct udev_hwdb, 1); - if (!hwdb) + if (!hwdb) { + errno = ENOMEM; return NULL; + } hwdb->refcount = 1; hwdb->hwdb = hwdb_internal; @@ -127,6 +131,7 @@ _public_ struct udev_hwdb *udev_hwdb_unref(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) { const char *key, *value; + struct udev_list_entry *e; if (!hwdb || !modalias) { errno = EINVAL; @@ -142,5 +147,9 @@ _public_ struct udev_list_entry *udev_hwdb_get_properties_list_entry(struct udev } } - return udev_list_get_entry(&hwdb->properties_list); + e = udev_list_get_entry(&hwdb->properties_list); + if (!e) + errno = ENODATA; + + return e; } |