Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Javier Carrasco and committed by
Shuah Khan
5b45a753 37013b55

+5 -3
+5 -3
tools/testing/selftests/uevent/uevent_filtering.c
··· 78 78 { 79 79 int sk_fd, ret; 80 80 socklen_t sk_addr_len; 81 - int fret = -1, rcv_buf_sz = __UEVENT_BUFFER_SIZE; 81 + int rcv_buf_sz = __UEVENT_BUFFER_SIZE; 82 82 uint64_t sync_add = 1; 83 83 struct sockaddr_nl sk_addr = { 0 }, rcv_addr = { 0 }; 84 84 char buf[__UEVENT_BUFFER_SIZE] = { 0 }; ··· 121 121 122 122 if ((size_t)sk_addr_len != sizeof(sk_addr)) { 123 123 fprintf(stderr, "Invalid socket address size\n"); 124 + ret = -1; 124 125 goto on_error; 125 126 } 126 127 ··· 148 147 ret = write_nointr(sync_fd, &sync_add, sizeof(sync_add)); 149 148 close(sync_fd); 150 149 if (ret != sizeof(sync_add)) { 150 + ret = -1; 151 151 fprintf(stderr, "Failed to synchronize with parent process\n"); 152 152 goto on_error; 153 153 } 154 154 155 - fret = 0; 155 + ret = 0; 156 156 for (;;) { 157 157 ssize_t r; 158 158 ··· 189 187 on_error: 190 188 close(sk_fd); 191 189 192 - return fret; 190 + return ret; 193 191 } 194 192 195 193 int trigger_uevent(unsigned int times)