[mptcp-next v2 3/7] selftests: mptcp: refine the 'iovlen' handling logic

Gang Yan posted 7 patches 8 months ago
There is a newer version of this series
[mptcp-next v2 3/7] selftests: mptcp: refine the 'iovlen' handling logic
Posted by Gang Yan 8 months ago
In the original version, the handling logic for the 'iovlen' appeared
somewhat redundant. Therefore, 'iovlen++' is used to simpify this
portion of the code and improve its readaility.

Co-developed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Gang Yan <yangang@kylinos.cn>
---
 tools/testing/selftests/net/mptcp/mptcp_diag.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_diag.c b/tools/testing/selftests/net/mptcp/mptcp_diag.c
index 8a5b7745c58c..2bf13bce59a5 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_diag.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_diag.c
@@ -91,10 +91,9 @@ static void send_query(int fd, struct inet_diag_req_v2 *r)
 		.iov_base = &req,
 		.iov_len = sizeof(req)
 	};
-	iov[iovlen] = (struct iovec){ &rta_proto, sizeof(rta_proto)};
-	iov[iovlen + 1] = (struct iovec){ &proto, sizeof(proto)};
+	iov[iovlen++] = (struct iovec){ &rta_proto, sizeof(rta_proto)};
+	iov[iovlen++] = (struct iovec){ &proto, sizeof(proto)};
 	req.nlh.nlmsg_len += RTA_LENGTH(sizeof(proto));
-	iovlen += 2;
 	struct msghdr msg = {
 		.msg_name = &nladdr,
 		.msg_namelen = sizeof(nladdr),
-- 
2.25.1
Re: [mptcp-next v2 3/7] selftests: mptcp: refine the 'iovlen' handling logic
Posted by Matthieu Baerts 8 months ago
Hi Gang,

On 16/04/2025 10:59, Gang Yan wrote:
> In the original version, the handling logic for the 'iovlen' appeared
> somewhat redundant. Therefore, 'iovlen++' is used to simpify this
> portion of the code and improve its readaility.
> 
> Co-developed-by: Geliang Tang <geliang@kernel.org>
> Signed-off-by: Geliang Tang <geliang@kernel.org>
> Signed-off-by: Gang Yan <yangang@kylinos.cn>
> ---
>  tools/testing/selftests/net/mptcp/mptcp_diag.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_diag.c b/tools/testing/selftests/net/mptcp/mptcp_diag.c
> index 8a5b7745c58c..2bf13bce59a5 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_diag.c
> +++ b/tools/testing/selftests/net/mptcp/mptcp_diag.c
> @@ -91,10 +91,9 @@ static void send_query(int fd, struct inet_diag_req_v2 *r)
>  		.iov_base = &req,
>  		.iov_len = sizeof(req)
>  	};

I guess you could also declare iovlen to 0, then start the increment above:

  iov[iovlen++] = (struct iovec) { (...) };

> -	iov[iovlen] = (struct iovec){ &rta_proto, sizeof(rta_proto)};
> -	iov[iovlen + 1] = (struct iovec){ &proto, sizeof(proto)};
> +	iov[iovlen++] = (struct iovec){ &rta_proto, sizeof(rta_proto)};
> +	iov[iovlen++] = (struct iovec){ &proto, sizeof(proto)};
>  	req.nlh.nlmsg_len += RTA_LENGTH(sizeof(proto));
> -	iovlen += 2;

For such very small and not complex change like that, I think there is
no need to create a dedicate patch. This can be squashed in the next
patch with a note like:

  While at it, increment iovlen directly when an item is added.

>  	struct msghdr msg = {
>  		.msg_name = &nladdr,
>  		.msg_namelen = sizeof(nladdr),

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.