selftests: mptcp: diag: drop nlh parameter of recv_nlmsg
authorGeliang Tang <tanggeliang@kylinos.cn>
Sun, 13 Apr 2025 09:34:38 +0000 (11:34 +0200)
committerJakub Kicinski <kuba@kernel.org>
Tue, 15 Apr 2025 15:21:47 +0000 (08:21 -0700)
It's strange that 'nlh' variable is set to NULL in get_mptcpinfo() and then
this NULL pointer is passed to recv_nlmsg(). In fact, this variable should
be defined in recv_nlmsg(), not get_mptcpinfo().

So this patch drops this useless 'nlh' parameter of recv_nlmsg() and define
'nlh' variable in recv_nlmsg().

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20250413-net-next-mptcp-sched-mib-sft-misc-v2-7-0f83a4350150@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/mptcp/mptcp_diag.c

index 284286c..37d5015 100644 (file)
@@ -185,9 +185,10 @@ static void parse_nlmsg(struct nlmsghdr *nlh)
        }
 }
 
-static void recv_nlmsg(int fd, struct nlmsghdr *nlh)
+static void recv_nlmsg(int fd)
 {
        char rcv_buff[8192];
+       struct nlmsghdr *nlh = (struct nlmsghdr *)rcv_buff;
        struct sockaddr_nl rcv_nladdr = {
                .nl_family = AF_NETLINK
        };
@@ -204,7 +205,6 @@ static void recv_nlmsg(int fd, struct nlmsghdr *nlh)
        int len;
 
        len = recvmsg(fd, &rcv_msg, 0);
-       nlh = (struct nlmsghdr *)rcv_buff;
 
        while (NLMSG_OK(nlh, len)) {
                if (nlh->nlmsg_type == NLMSG_DONE) {
@@ -225,7 +225,6 @@ static void recv_nlmsg(int fd, struct nlmsghdr *nlh)
 
 static void get_mptcpinfo(__u32 token)
 {
-       struct nlmsghdr *nlh = NULL;
        int fd;
 
        fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG);
@@ -233,7 +232,7 @@ static void get_mptcpinfo(__u32 token)
                die_perror("Netlink socket");
 
        send_query(fd, token);
-       recv_nlmsg(fd, nlh);
+       recv_nlmsg(fd);
 
        close(fd);
 }