From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>, passt-dev@passt.top
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 5/5] tcp: MAX_WINDOW should be unsigned
Date: Mon, 15 Jun 2026 18:18:33 +1000 [thread overview]
Message-ID: <20260615081833.1061725-6-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20260615081833.1061725-1-david@gibson.dropbear.id.au>
Currently MAX_WINDOW is defined as a (signed) int, since '1' is a signed
literal. This means that when it's used in the SEQ_*() macros, we're
making a signed / unsigned comparison. While I don't think it was
incorrect in practice, confirming that requires reasoning though arcane
C type promotion rules.
Since it's obviously a non-negative value, change the constant to unsigned.
Change BUF_DISCARD_SIZE for the same reason, and because they're linked
via DISCARD_IOV_NUM, which must also be non-negative. Change the types
of a few variables in tcp_prepare_iov() to match (otherwise we'd get some
compiler warnings).
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
tcp.c | 3 +--
tcp_internal.h | 4 ++--
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/tcp.c b/tcp.c
index edcabe27..10d9d0d5 100644
--- a/tcp.c
+++ b/tcp.c
@@ -4069,9 +4069,8 @@ int tcp_prepare_iov(struct msghdr *msg, struct iovec *iov,
msg->msg_iov = iov + DISCARD_IOV_NUM;
msg->msg_iovlen = payload_iov_cnt;
} else {
- int discard_cnt, discard_iov_rem;
+ unsigned discard_cnt, discard_iov_rem, i;
struct iovec *iov_start;
- int i;
discard_cnt = DIV_ROUND_UP(already_sent, BUF_DISCARD_SIZE);
if (discard_cnt > DISCARD_IOV_NUM) {
diff --git a/tcp_internal.h b/tcp_internal.h
index 40472c99..c623569c 100644
--- a/tcp_internal.h
+++ b/tcp_internal.h
@@ -12,9 +12,9 @@
#include "util.h"
#define MAX_WS 8
-#define MAX_WINDOW (1 << (16 + (MAX_WS)))
+#define MAX_WINDOW (1U << (16 + (MAX_WS)))
-#define BUF_DISCARD_SIZE (1 << 20)
+#define BUF_DISCARD_SIZE (1U << 20)
#define DISCARD_IOV_NUM DIV_ROUND_UP(MAX_WINDOW, BUF_DISCARD_SIZE)
#define MSS4 ROUND_DOWN(IP_MAX_MTU - \
--
2.54.0
prev parent reply other threads:[~2026-06-15 8:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-15 8:18 [PATCH 0/5] Fix cppcheck-2.21.0 warnings David Gibson
2026-06-15 8:18 ` [PATCH 1/5] cppcheck: Remove unused CPPCHECK_6936 David Gibson
2026-06-15 8:18 ` [PATCH 2/5] cppcheck: Add workaround for cppcheck bug 14847 David Gibson
2026-06-15 8:18 ` [PATCH 3/5] tcp: Merge common sequence logic from tcp_{buf,vu}_data_from_sock() David Gibson
2026-06-15 8:50 ` Laurent Vivier
2026-06-15 8:18 ` [PATCH 4/5] tcp: Avoid SEQ_*() comparisons against 0 David Gibson
2026-06-15 8:18 ` David Gibson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260615081833.1061725-6-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).