[PATCH mptcp-next v14 04/12] selftests: mptcp: sockopt: use size_t for byte counters
Geliang Tang <[email protected]> Thu, 30 Jul 2026 11:15:15 +0800
| Newsgroups | dev.linux.lists.mptcp |
|---|---|
| Message-ID | <1834a49a3960a167bb29e4506eb741e1764b3c38.1785380422.git.tanggeliang@kylinos.cn> |
From: Geliang Tang <[email protected]> Rename ret/ret2/ret3 to ret (ssize_t, for syscall return values) and r/w (size_t, for byte counters) for better readability. The byte counters were previously stored in ssize_t but never hold negative values; size_t is the natural type and matches the parameter types of do_getsockopts(s, fd, size_t r, size_t w). This also prepares for future updates where r will be modified via '+='. Signed-off-by: Geliang Tang <[email protected]> --- .../selftests/net/mptcp/mptcp_sockopt.c | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c index a68fbe13b096..3a7fcef5aa54 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c +++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c @@ -650,9 +650,10 @@ static void check_stat_equal(const char *name, uint64_t actual, static void process_one_client(int fd, int pipefd) { - ssize_t ret, ret2, ret3; struct so_state s; char buf[4096]; + ssize_t ret; + size_t r, w; memset(&s, 0, sizeof(s)); do_getsockopts(&s, fd, 0, 0); @@ -663,36 +664,39 @@ static void process_one_client(int fd, int pipefd) ret = read(fd, buf, sizeof(buf)); if (ret < 0) die_perror("read"); + r = ret; - assert(s.mptcpi_rcv_delta <= (uint64_t)ret); + assert(s.mptcpi_rcv_delta <= (uint64_t)r); if (s.tcpi_rcv_delta) - assert(s.tcpi_rcv_delta == (uint64_t)ret); + assert(s.tcpi_rcv_delta == (uint64_t)r); - ret2 = write(fd, buf, ret); - if (ret2 < 0) + ret = write(fd, buf, r); + if (ret < 0) die_perror("write"); + w = ret; /* wait for hangup */ - ret3 = read(fd, buf, 1); - if (ret3 != 0) - xerror("expected EOF, got %lu", ret3); + ret = read(fd, buf, 1); + if (ret != 0) + xerror("expected EOF, got %zd", ret); + r += ret; - do_getsockopts(&s, fd, ret, ret2); + do_getsockopts(&s, fd, r, w); check_stat_equal("mptcpi_rcv_delta", s.mptcpi_rcv_delta, - (uint64_t)ret + 1); /* +1 for FIN */ + (uint64_t)r + 1); /* +1 for FIN */ /* be nice when running on top of older kernel */ if (s.pkt_stats_avail) { check_stat_equal("mptcpi_bytes_sent", s.last_sample.mptcpi_bytes_sent, - (uint64_t)ret2); + (uint64_t)w); check_stat_equal("mptcpi_bytes_received", s.last_sample.mptcpi_bytes_received, - (uint64_t)ret); + (uint64_t)r); check_stat_equal("mptcpi_bytes_acked", s.last_sample.mptcpi_bytes_acked, - (uint64_t)ret2); + (uint64_t)w); } close(fd); -- 2.53.0