From 7f9e03952ac4c8050925f6093dded44e57dbbc7c Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 24 Aug 2018 17:12:04 +0900 Subject: libudev-monitor: use assert_return() in many places --- src/libudev/libudev-monitor.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/libudev/libudev-monitor.c') diff --git a/src/libudev/libudev-monitor.c b/src/libudev/libudev-monitor.c index 257621e050..ea44308351 100644 --- a/src/libudev/libudev-monitor.c +++ b/src/libudev/libudev-monitor.c @@ -320,8 +320,10 @@ _public_ int udev_monitor_filter_update(struct udev_monitor *udev_monitor) { return 0; } -int udev_monitor_allow_unicast_sender(struct udev_monitor *udev_monitor, struct udev_monitor *sender) -{ +int udev_monitor_allow_unicast_sender(struct udev_monitor *udev_monitor, struct udev_monitor *sender) { + assert_return(udev_monitor, -EINVAL); + assert_return(sender, -EINVAL); + udev_monitor->snl_trusted_sender.nl.nl_pid = sender->snl.nl.nl_pid; return 0; } @@ -372,10 +374,9 @@ _public_ int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor) { * * Returns: 0 on success, otherwise -1 on error. */ -_public_ int udev_monitor_set_receive_buffer_size(struct udev_monitor *udev_monitor, int size) -{ - if (udev_monitor == NULL) - return -EINVAL; +_public_ int udev_monitor_set_receive_buffer_size(struct udev_monitor *udev_monitor, int size) { + assert_return(udev_monitor, -EINVAL); + if (setsockopt(udev_monitor->sock, SOL_SOCKET, SO_RCVBUFFORCE, &size, sizeof(size)) < 0) return -errno; @@ -427,10 +428,9 @@ DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(struct udev_monitor, udev_monitor, udev_mon * * Returns: the udev library context **/ -_public_ struct udev *udev_monitor_get_udev(struct udev_monitor *udev_monitor) -{ - if (udev_monitor == NULL) - return NULL; +_public_ struct udev *udev_monitor_get_udev(struct udev_monitor *udev_monitor) { + assert_return(udev_monitor, NULL); + return udev_monitor->udev; } @@ -442,10 +442,9 @@ _public_ struct udev *udev_monitor_get_udev(struct udev_monitor *udev_monitor) * * Returns: the socket file descriptor **/ -_public_ int udev_monitor_get_fd(struct udev_monitor *udev_monitor) -{ - if (udev_monitor == NULL) - return -EINVAL; +_public_ int udev_monitor_get_fd(struct udev_monitor *udev_monitor) { + assert_return(udev_monitor, -EINVAL); + return udev_monitor->sock; } -- cgit v1.2.1