Re: [PATCH bpf-next v2 09/14] selftests/bpf: Add function pointer for __start_server

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2024-04-11 at 09:03 +0800, Geliang Tang wrote:


[...]

>  static int __start_server(int type, int protocol, const struct sockaddr *addr,
> -			  socklen_t addrlen, int timeout_ms, bool reuseport)
> +			  socklen_t addrlen, int timeout_ms,
> +			  int *(*setsockopt)(int fd, int val), int val)

There is no need for setsockopt to return pointer to int,
the code could be simplified e.g. as in the patch below (on top of this series):

---

diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index f6810bb54edc..30ac03322c61 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -80,7 +80,7 @@ int settimeo(int fd, int timeout_ms)
 
 static int __start_server(int type, int protocol, const struct sockaddr *addr,
 			  socklen_t addrlen, int timeout_ms,
-			  int *(*setsockopt)(int fd, int val), int val)
+			  int (*setsockopt)(int fd, int val), int val)
 {
 	int fd;
 
@@ -167,7 +167,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str,
 		return NULL;
 
 	fds[0] = __start_server(type, 0, (struct sockaddr *)&addr, addrlen,
-				timeout_ms, (void *)setsockopt_reuse, 1);
+				timeout_ms, setsockopt_reuse, 1);
 	if (fds[0] == -1)
 		goto close_fds;
 	nr_fds = 1;
@@ -177,7 +177,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str,
 
 	for (; nr_fds < nr_listens; nr_fds++) {
 		fds[nr_fds] = __start_server(type, 0, (struct sockaddr *)&addr,
-					     addrlen, timeout_ms, (void *)setsockopt_reuse, 1);
+					     addrlen, timeout_ms, setsockopt_reuse, 1);
 		if (fds[nr_fds] == -1)
 			goto close_fds;
 	}
@@ -195,7 +195,7 @@ int start_server_addr(const struct sockaddr *addr, socklen_t addrlen, int type)
 }
 
 int start_server_setsockopt(const struct sockaddr *addr, socklen_t addrlen, int type,
-			    int *(*setsockopt)(int fd, int val), int val)
+			    int (*setsockopt)(int fd, int val), int val)
 {
 	return __start_server(type, 0, addr, addrlen, 0, setsockopt, val);
 }
diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h
index 543295230062..0f0f1803e0c8 100644
--- a/tools/testing/selftests/bpf/network_helpers.h
+++ b/tools/testing/selftests/bpf/network_helpers.h
@@ -56,7 +56,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str,
 			    unsigned int nr_listens);
 int start_server_addr(const struct sockaddr *addr, socklen_t addrlen, int type);
 int start_server_setsockopt(const struct sockaddr *addr, socklen_t addrlen, int type,
-			    int *(*setsockopt)(int fd, int val), int val);
+			    int (*setsockopt)(int fd, int val), int val);
 void free_fds(int *fds, unsigned int nr_close_fds);
 int connect_to_addr(const struct sockaddr_storage *addr, socklen_t len, int type);
 int connect_to_fd(int server_fd, int timeout_ms);
diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c
index 4fee4b343255..0c39170d543a 100644
--- a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c
+++ b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c
@@ -97,7 +97,7 @@ static int start_server_lo(void)
 	if (make_sockaddr(AF_INET, "127.0.0.1", 0, &addr, &addrlen))
 		return -1;
 	return start_server_setsockopt((struct sockaddr *)&addr, addrlen,
-				       SOCK_STREAM, (void *)setsockopt_loop, 0);
+				       SOCK_STREAM, setsockopt_loop, 0);
 }
 
 static void run_test(int cgroup_fd)






[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux