From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: passt-dev@passt.top
Subject: [PATCH v2] tcp: Avoid comparison of expressions with different signedness in RTT_SET()
Date: Fri, 6 Mar 2026 08:02:35 +0100 [thread overview]
Message-ID: <20260306070235.2687041-1-sbrivio@redhat.com> (raw)
With gcc 14.2, building against musl 1.2.5 (slightly outdated Alpine
on x86_64):
tcp.c: In function 'tcp_update_seqack_wnd':
util.h:40:39: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
40 | #define MIN(x, y) (((x) < (y)) ? (x) : (y))
| ^
tcp_conn.h:63:26: note: in expansion of macro 'MIN'
63 | (conn->rtt_exp = MIN(RTT_EXP_MAX, ilog2(MAX(1, rtt / RTT_STORE_MIN))))
| ^~~
tcp.c:1234:17: note: in expansion of macro 'RTT_SET'
1234 | RTT_SET(conn, tinfo->tcpi_rtt);
| ^~~~~~~
util.h:40:54: warning: operand of '?:' changes signedness from 'int' to 'unsigned int' due to unsignedness of other operand [-Wsign-compare]
40 | #define MIN(x, y) (((x) < (y)) ? (x) : (y))
| ^~~
tcp_conn.h:63:26: note: in expansion of macro 'MIN'
63 | (conn->rtt_exp = MIN(RTT_EXP_MAX, ilog2(MAX(1, rtt / RTT_STORE_MIN))))
| ^~~
tcp.c:1234:17: note: in expansion of macro 'RTT_SET'
1234 | RTT_SET(conn, tinfo->tcpi_rtt);
| ^~~~~~~
for some reason, that's not reported by gcc with glibc.
Cast the result of ilog2() to unsigned before using it, and introduce
0 as lower bound, to make it obvious that we expect the argument to be
always valid, the way we're using it.
Suggested-by: David Gibson <david@gibson.dropbear.id.au>
Fixes: 000601ba86da ("tcp: Adaptive interval based on RTT for socket-side acknowledgement checks")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
v2: Apply lower bound to the result of ilog2() instead of its argument,
as suggested by David
tcp_conn.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tcp_conn.h b/tcp_conn.h
index b7b85c1..6985426 100644
--- a/tcp_conn.h
+++ b/tcp_conn.h
@@ -60,7 +60,8 @@ struct tcp_tap_conn {
#define RTT_STORE_MIN 100 /* us, minimum representable */
#define RTT_STORE_MAX ((long)(RTT_STORE_MIN << RTT_EXP_MAX))
#define RTT_SET(conn, rtt) \
- (conn->rtt_exp = MIN(RTT_EXP_MAX, ilog2(MAX(1, rtt / RTT_STORE_MIN))))
+ (conn->rtt_exp = MIN(RTT_EXP_MAX, \
+ (unsigned)MAX(0, ilog2(rtt / RTT_STORE_MIN))))
#define RTT_GET(conn) (RTT_STORE_MIN << conn->rtt_exp)
bool tap_inactive :1;
--
2.43.0
next reply other threads:[~2026-03-06 7:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-06 7:02 Stefano Brivio [this message]
2026-03-06 12:02 ` David Gibson
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=20260306070235.2687041-1-sbrivio@redhat.com \
--to=sbrivio@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
/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).