]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: make several sd_device_get_*() accepts NULL pointer for buffer of returned...
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 29 Oct 2018 08:17:57 +0000 (17:17 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 29 Oct 2018 08:18:00 +0000 (17:18 +0900)
When only the existence of the value are important, then we can set
NULL now.

src/libsystemd/sd-device/device-private.c
src/libsystemd/sd-device/sd-device.c

index eb27346786239835ff49380a8b38509f0028f6c2..0bd31216bf73e12c217712105b898301532aab38 100644 (file)
@@ -271,7 +271,6 @@ int device_get_devnode_mode(sd_device *device, mode_t *mode) {
         int r;
 
         assert(device);
-        assert(mode);
 
         r = device_read_db(device);
         if (r < 0)
@@ -280,7 +279,8 @@ int device_get_devnode_mode(sd_device *device, mode_t *mode) {
         if (device->devmode == (mode_t) -1)
                 return -ENOENT;
 
-        *mode = device->devmode;
+        if (mode)
+                *mode = device->devmode;
 
         return 0;
 }
@@ -289,7 +289,6 @@ int device_get_devnode_uid(sd_device *device, uid_t *uid) {
         int r;
 
         assert(device);
-        assert(uid);
 
         r = device_read_db(device);
         if (r < 0)
@@ -298,7 +297,8 @@ int device_get_devnode_uid(sd_device *device, uid_t *uid) {
         if (device->devuid == (uid_t) -1)
                 return -ENOENT;
 
-        *uid = device->devuid;
+        if (uid)
+                *uid = device->devuid;
 
         return 0;
 }
@@ -327,7 +327,6 @@ int device_get_devnode_gid(sd_device *device, gid_t *gid) {
         int r;
 
         assert(device);
-        assert(gid);
 
         r = device_read_db(device);
         if (r < 0)
@@ -336,7 +335,8 @@ int device_get_devnode_gid(sd_device *device, gid_t *gid) {
         if (device->devgid == (gid_t) -1)
                 return -ENOENT;
 
-        *gid = device->devgid;
+        if (gid)
+                *gid = device->devgid;
 
         return 0;
 }
@@ -726,7 +726,6 @@ int device_get_watch_handle(sd_device *device, int *handle) {
         int r;
 
         assert(device);
-        assert(handle);
 
         r = device_read_db(device);
         if (r < 0)
@@ -735,7 +734,8 @@ int device_get_watch_handle(sd_device *device, int *handle) {
         if (device->watch_handle < 0)
                 return -ENOENT;
 
-        *handle = device->watch_handle;
+        if (handle)
+                *handle = device->watch_handle;
 
         return 0;
 }
index b97c1b97198becdfba426d29b9b081bb221361fd..a89c54bb87838dfde378985d52dfc787db58b177 100644 (file)
@@ -572,7 +572,6 @@ _public_ int sd_device_get_ifindex(sd_device *device, int *ifindex) {
         int r;
 
         assert_return(device, -EINVAL);
-        assert_return(ifindex, -EINVAL);
 
         r = device_read_uevent_file(device);
         if (r < 0)
@@ -581,7 +580,8 @@ _public_ int sd_device_get_ifindex(sd_device *device, int *ifindex) {
         if (device->ifindex <= 0)
                 return -ENOENT;
 
-        *ifindex = device->ifindex;
+        if (ifindex)
+                *ifindex = device->ifindex;
 
         return 0;
 }
@@ -889,7 +889,6 @@ _public_ int sd_device_get_devnum(sd_device *device, dev_t *devnum) {
         int r;
 
         assert_return(device, -EINVAL);
-        assert_return(devnum, -EINVAL);
 
         r = device_read_uevent_file(device);
         if (r < 0)
@@ -898,7 +897,8 @@ _public_ int sd_device_get_devnum(sd_device *device, dev_t *devnum) {
         if (major(device->devnum) <= 0)
                 return -ENOENT;
 
-        *devnum = device->devnum;
+        if (devnum)
+                *devnum = device->devnum;
 
         return 0;
 }
@@ -1677,7 +1677,6 @@ _public_ int sd_device_get_property_value(sd_device *device, const char *key, co
 
         assert_return(device, -EINVAL);
         assert_return(key, -EINVAL);
-        assert_return(_value, -EINVAL);
 
         r = device_properties_prepare(device);
         if (r < 0)
@@ -1687,7 +1686,8 @@ _public_ int sd_device_get_property_value(sd_device *device, const char *key, co
         if (!value)
                 return -ENOENT;
 
-        *_value = value;
+        if (_value)
+                *_value = value;
 
         return 0;
 }