From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202606 header.b=LCHdMGW4; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id C04D85A0619 for ; Mon, 15 Jun 2026 10:18:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202606; t=1781511516; bh=Vvbm4IGy8XATtOEaW3uPBdihiLI7KOnaOSkdjhZ8GTQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LCHdMGW4dVj2E1TILKl+AL6oVdek1HoyvM3MkG7hEcaDCbkEd2xEYw4+ovB1lN8/0 SLz73WsT9ESH8iegFD+zHYsf3aIRrk/qV1vrNZ60K98LMIAO3eYTkpGxaFar/SLrU8 9Rb/8wUYdD3Fu+JX3Abkh4bBrGwlKFJGh0Nu/Y/NnKVzrDw7Dcjr3e7eHSouAeyF98 isjXPfdpuZ5mHP+zjwtuEdeJJqMY/L/mxPcfcis4u3uMtX43uSYYWqQU9d7KFpEFsx p5lYw5SjmYMRTigCm1bXd7qaVReifpTFsFCvlA4Uxhe9WAhfLGPoJjUXEc8DKuqjyx IXbcGFM6meWMw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gf30r1wqdz4wTZ; Mon, 15 Jun 2026 18:18:36 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 5/5] tcp: MAX_WINDOW should be unsigned Date: Mon, 15 Jun 2026 18:18:33 +1000 Message-ID: <20260615081833.1061725-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260615081833.1061725-1-david@gibson.dropbear.id.au> References: <20260615081833.1061725-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: EMULKRNJDIET7DTFD5Z2MV2XMMDW2RNQ X-Message-ID-Hash: EMULKRNJDIET7DTFD5Z2MV2XMMDW2RNQ X-MailFrom: dgibson@gandalf.ozlabs.org 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: David Gibson 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: 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 --- 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