diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-10-23 17:49:03 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-10-24 11:48:08 +0200 |
commit | 730b76bd2cd5f0866baa738ae283e3b62544a28f (patch) | |
tree | 236935c214c56f239143c22be0055611f737404b | |
parent | 0e7f5ad9d3c73f50582b87d96912790b51b641d7 (diff) | |
download | systemd-730b76bd2cd5f0866baa738ae283e3b62544a28f.tar.gz |
sd-device: allow sd_device_get_devtype to be called with NULL arg and do not assert
We shouldn't call assert() on user-specified arguments in public functions.
While at it, let's return 1 if the type exists, and 0 otherwise.
-rw-r--r-- | src/libsystemd/sd-device/sd-device.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index c4a7f2f3d3..183110cbe2 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -838,8 +838,7 @@ _public_ int sd_device_get_subsystem(sd_device *device, const char **ret) { _public_ int sd_device_get_devtype(sd_device *device, const char **devtype) { int r; - assert(devtype); - assert(device); + assert_return(device, -EINVAL); r = device_read_uevent_file(device); if (r < 0) @@ -848,9 +847,10 @@ _public_ int sd_device_get_devtype(sd_device *device, const char **devtype) { if (!device->devtype) return -ENOENT; - *devtype = device->devtype; + if (devtype) + *devtype = device->devtype; - return 0; + return !!device->devtype; } _public_ int sd_device_get_parent_with_subsystem_devtype(sd_device *child, const char *subsystem, const char *devtype, sd_device **ret) { |