Skip to content

Commit ec2610b

Browse files
committed
Merge branch 'selftests-net-fix-a-few-small-compiler-warnings'
Willem de Bruijn says: ==================== selftests/net: fix a few small compiler warnings Observed a clang warning when backporting cmsg_sender. Ran the same build against all the .c files under selftests/net. This is clang-14 with -Wall Which is what tools/testing/selftests/net/Makefile also enables. ==================== Link: https://lore.kernel.org/r/20231124171645.1011043-1-willemdebruijn.kernel@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents ccf49ce + 00a4f8f commit ec2610b

5 files changed

Lines changed: 11 additions & 18 deletions

File tree

tools/testing/selftests/net/af_unix/diag_uid.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ void receive_response(struct __test_metadata *_metadata,
148148
.msg_iov = &iov,
149149
.msg_iovlen = 1
150150
};
151-
struct unix_diag_req *udr;
152151
struct nlmsghdr *nlh;
153152
int ret;
154153

tools/testing/selftests/net/cmsg_sender.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,9 @@ int main(int argc, char *argv[])
416416
{
417417
struct addrinfo hints, *ai;
418418
struct iovec iov[1];
419+
unsigned char *buf;
419420
struct msghdr msg;
420421
char cbuf[1024];
421-
char *buf;
422422
int err;
423423
int fd;
424424

tools/testing/selftests/net/ipsec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,7 @@ static int check_results(void)
22632263

22642264
int main(int argc, char **argv)
22652265
{
2266-
unsigned int nr_process = 1;
2266+
long nr_process = 1;
22672267
int route_sock = -1, ret = KSFT_SKIP;
22682268
int test_desc_fd[2];
22692269
uint32_t route_seq;
@@ -2284,7 +2284,7 @@ int main(int argc, char **argv)
22842284
exit_usage(argv);
22852285
}
22862286

2287-
if (nr_process > MAX_PROCESSES || !nr_process) {
2287+
if (nr_process > MAX_PROCESSES || nr_process < 1) {
22882288
printk("nr_process should be between [1; %u]",
22892289
MAX_PROCESSES);
22902290
exit_usage(argv);

tools/testing/selftests/net/mptcp/mptcp_connect.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <sys/ioctl.h>
2020
#include <sys/poll.h>
21+
#include <sys/random.h>
2122
#include <sys/sendfile.h>
2223
#include <sys/stat.h>
2324
#include <sys/socket.h>
@@ -1125,15 +1126,11 @@ int main_loop_s(int listensock)
11251126

11261127
static void init_rng(void)
11271128
{
1128-
int fd = open("/dev/urandom", O_RDONLY);
11291129
unsigned int foo;
11301130

1131-
if (fd > 0) {
1132-
int ret = read(fd, &foo, sizeof(foo));
1133-
1134-
if (ret < 0)
1135-
srand(fd + foo);
1136-
close(fd);
1131+
if (getrandom(&foo, sizeof(foo), 0) == -1) {
1132+
perror("getrandom");
1133+
exit(1);
11371134
}
11381135

11391136
srand(foo);

tools/testing/selftests/net/mptcp/mptcp_inq.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <time.h>
1919

2020
#include <sys/ioctl.h>
21+
#include <sys/random.h>
2122
#include <sys/socket.h>
2223
#include <sys/types.h>
2324
#include <sys/wait.h>
@@ -519,15 +520,11 @@ static int client(int unixfd)
519520

520521
static void init_rng(void)
521522
{
522-
int fd = open("/dev/urandom", O_RDONLY);
523523
unsigned int foo;
524524

525-
if (fd > 0) {
526-
int ret = read(fd, &foo, sizeof(foo));
527-
528-
if (ret < 0)
529-
srand(fd + foo);
530-
close(fd);
525+
if (getrandom(&foo, sizeof(foo), 0) == -1) {
526+
perror("getrandom");
527+
exit(1);
531528
}
532529

533530
srand(foo);

0 commit comments

Comments
 (0)