aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/testing/selftests/uevent
diff options
context:
space:
mode:
authorJavier Carrasco <javier.carrasco.cruz@gmail.com>2023-10-01 10:37:44 +0200
committerShuah Khan <skhan@linuxfoundation.org>2023-10-05 14:28:53 -0600
commit5b45a753776be5d21cf395ec97e81c9187fbeaca (patch)
tree66fb1e4b4910d54e9046890921e01a89c345868a /tools/testing/selftests/uevent
parentkbuild: Merge per-arch config for kselftest-merge target (diff)
downloadwireguard-linux-5b45a753776be5d21cf395ec97e81c9187fbeaca.tar.xz
wireguard-linux-5b45a753776be5d21cf395ec97e81c9187fbeaca.zip
selftests: uevent filtering: fix return on error in uevent_listener
The ret variable is used to check function return values and assigning values to it on error has no effect as it is an unused value. The current implementation uses an additional variable (fret) to return the error value, which in this case is unnecessary and lead to the above described misuse. There is no restriction in the current implementation to always return -1 on error and the actual negative error value can be returned safely without storing -1 in a specific variable. Simplify the error checking by using a single variable which always holds the returned value. Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'tools/testing/selftests/uevent')
-rw-r--r--tools/testing/selftests/uevent/uevent_filtering.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/tools/testing/selftests/uevent/uevent_filtering.c b/tools/testing/selftests/uevent/uevent_filtering.c
index 5cebfb356345..dbe55f3a66f4 100644
--- a/tools/testing/selftests/uevent/uevent_filtering.c
+++ b/tools/testing/selftests/uevent/uevent_filtering.c
@@ -78,7 +78,7 @@ static int uevent_listener(unsigned long post_flags, bool expect_uevent,
{
int sk_fd, ret;
socklen_t sk_addr_len;
- int fret = -1, rcv_buf_sz = __UEVENT_BUFFER_SIZE;
+ int rcv_buf_sz = __UEVENT_BUFFER_SIZE;
uint64_t sync_add = 1;
struct sockaddr_nl sk_addr = { 0 }, rcv_addr = { 0 };
char buf[__UEVENT_BUFFER_SIZE] = { 0 };
@@ -121,6 +121,7 @@ static int uevent_listener(unsigned long post_flags, bool expect_uevent,
if ((size_t)sk_addr_len != sizeof(sk_addr)) {
fprintf(stderr, "Invalid socket address size\n");
+ ret = -1;
goto on_error;
}
@@ -147,11 +148,12 @@ static int uevent_listener(unsigned long post_flags, bool expect_uevent,
ret = write_nointr(sync_fd, &sync_add, sizeof(sync_add));
close(sync_fd);
if (ret != sizeof(sync_add)) {
+ ret = -1;
fprintf(stderr, "Failed to synchronize with parent process\n");
goto on_error;
}
- fret = 0;
+ ret = 0;
for (;;) {
ssize_t r;
@@ -187,7 +189,7 @@ static int uevent_listener(unsigned long post_flags, bool expect_uevent,
on_error:
close(sk_fd);
- return fret;
+ return ret;
}
int trigger_uevent(unsigned int times)