From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ijAFNssG; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 347C65A0265 for ; Fri, 06 Mar 2026 08:02:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772780551; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Haa1StvX4wZFY2CelFPOXIgVdEJia2+IHNAjcz8ICb4=; b=ijAFNssGRmpMqT2ica/rHOWNGBVIdAE3n5qqfwQExsevjed8XsW55fm8802plsV0Ezq0KH 0aU18+rPNzU13KMFrOQwkBRRpLYfaJ2XyeM2WEVv+LjI2MsbyvRIwmVa7/RWQC1wyBKUCB MPP8T27H09089kKc/hJtGw+BtFgD1Q8= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-163-aq55dzGLPc-jGT6pnWH6fw-1; Fri, 06 Mar 2026 02:02:30 -0500 X-MC-Unique: aq55dzGLPc-jGT6pnWH6fw-1 X-Mimecast-MFC-AGG-ID: aq55dzGLPc-jGT6pnWH6fw_1772780549 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-439cbfcfc21so2075207f8f.2 for ; Thu, 05 Mar 2026 23:02:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772780549; x=1773385349; h=date:content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Haa1StvX4wZFY2CelFPOXIgVdEJia2+IHNAjcz8ICb4=; b=lGr0ZKa26/a4dXD+9cbNfy66in7MrNOMnRewBDR2al67BSYQtKr636RXWr8ADZhydP 5JGQh14mfBM5rCBunLrzkSY0WGyejUmDu8lKhamzPhy1QtN8ORXP81Ey3JXVO20mSn1v ukfhsJAoMXiRCEsUFtOhsWa9L8OykQ7Chfqm3aak7rLHUdS0K0ykxS/FcyB9PUb6bhrE RCN+ywBPl9wG6y/Vd9iOezjLa3SkpjHgp9cCys8qVzIrT4RdF97QvF/kRSuH5PpgOvTF XejG/FL3HmkSkuGK51JT+9iy75Za77VMz4VneHCi6iPBDYjBGFFjAm1LXzjU805QVkOU eXmw== X-Gm-Message-State: AOJu0Yw9ktX+BWlDVRXtzSyX3Y3cVPKfpl3yRFeLO7xoSXyCE6gOwGLj N12NdyKQY7RQPjLk3mttP1/J2oRJiFJkGm4JlsXMUFyfm7lsKlvjyl26sZLTawtk0DOs0dgs/Ob 36HLwueIXVYnzgtGG4YZ+j/4DTx4UEZ9I9zz0XSf/PgsKvpvTbw8BXg== X-Gm-Gg: ATEYQzwiifvKOfjkLrOJ6oGUd7doh6x1+n70/dPSopTHuxl36Zq/WakP6ZpxR59hKLJ kpuFrl8K6z2fpLCHaS9u0rKv67J4Gf3CFysCvGQp3WFi0srPeYwmIR56G5wiSIR/TcT1DTMPORV qlcjpc5aSs5WvE7CXcabcOBkuQ8qpqgUHAvVUODZBKRyLOEQYfYa/qDd/ywQnhYxBJvtIuslDU/ hNkUODNI59zykR3fLwh8KN1dLqFp3z4rVQeUccXMIG3tX7/mM+WO+RPe4BfFbxrRocxndHuxlES P/gciTyDHdTR6/Go2TKG6/78IzQBnvDpg5nEJ0yvKXEyGiKpt5j3GI5U3uqc68Um8CGiOt4Uoei M7YhxkC+E6zWPefzzmIJJGuAjV9dWSgMw02Z/yhSmGGRPtkxqBg== X-Received: by 2002:a05:6000:2204:b0:439:b1d8:608e with SMTP id ffacd0b85a97d-439da35f606mr1618586f8f.13.1772780548771; Thu, 05 Mar 2026 23:02:28 -0800 (PST) X-Received: by 2002:a05:6000:2204:b0:439:b1d8:608e with SMTP id ffacd0b85a97d-439da35f606mr1618506f8f.13.1772780547938; Thu, 05 Mar 2026 23:02:27 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-439dae3a20fsm1802330f8f.28.2026.03.05.23.02.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2026 23:02:27 -0800 (PST) From: Stefano Brivio To: David Gibson Subject: Re: [PATCH] tcp: Avoid comparison of expressions with different signedness in RTT_SET() Message-ID: <20260306080122.22ff92e4@elisabeth> In-Reply-To: References: <20260304163232.2440892-1-sbrivio@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 Date: Fri, 06 Mar 2026 08:02:26 +0100 (CET) X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: DUCFWxezy2tWiRDn_6dVjsyvvL269RPaA6bpc4Ln86Y_1772780549 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: DJK7PFLAJPEGOSNCT7G2DY4QAFNDPTRO X-Message-ID-Hash: DJK7PFLAJPEGOSNCT7G2DY4QAFNDPTRO X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Thu, 5 Mar 2026 13:32:08 +1100 David Gibson wrote: > On Wed, Mar 04, 2026 at 05:32:32PM +0100, Stefano Brivio wrote: > > 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, as it's always > > positive the way we're using it. Should this ever break this for > > whatever unlikely reason, RTT_EXP_MAX is the fallback value we want to > > use anyway. > > > > Fixes: 000601ba86da ("tcp: Adaptive interval based on RTT for socket-side acknowledgement checks") > > Signed-off-by: Stefano Brivio > > This is correct, so > > Reviewed-by: David Gibson > > It's kind of inelegant, though - ilog2() only returns a signed to > report an error case, which we avoid with the MAX inside the argument. > That's not a super obvious connection. I guess we could do: > > (unsigned)MAX(0, ilog2(rtt / RTT_STORE_MIN)) > > which should be equivalent and makes it slightly more obvious that the > cast is safe. Not sure if it's really an improvement, though. Right, yes, at this point I guess it's clearer. Changed to that in v2. > This is the only user of ilog2(), so we could also consider replacing > it with a version that explicitly clamps its argument to >= 1 and > returns unsigned. I thought about doing that, but on the other hand we would have a rather arithmetic function returning an obviously wrong value for some arguments, which doesn't sound great either. -- Stefano