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=202410 header.b=HyEW+tOT; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 0D1865A061C for ; Fri, 08 Nov 2024 03:23:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202410; t=1731032623; bh=mK0HtFrcKUYsiM8CBr9L4EILVvJhDneCfgiCR0jwLDA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HyEW+tOT5icmYNK7t+YHY1oRGGcD0V0k8lHcAT5/SvOnnJgQq/HIPrHtC3UoxrzO2 CsH9aYSf3LuagQirId+ClrCJJa8K4SLQSapqONAtC4nXowT7M+Wr0XCOZJMNbo20Zr 0iXYOkWVsnKuwy4+AgG5sbKZwL0drC4OW+EEDwJXqP6ymlSiF3zDgEsvQ3K16J9ztM /hr0pcwjQ0YChlGygofQe+3HUaGZqs5Ly6kAvXtYrVKQHtRUm4Ps4f4bYQ7wlbmxJ7 L87lr2vOoYd/DrckIBPBxs2MOe92SmD9obWgJNKXBSvliHN+Rqvo2oZv1RSi+sT6gS L2EPrX/qZd6Vw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Xl2mv2Bytz4x7H; Fri, 8 Nov 2024 13:23:43 +1100 (AEDT) Date: Fri, 8 Nov 2024 11:28:43 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 3/6] tap: Cast TAP_BUF_BYTES - ETH_MAX_MTU to ssize_t, not TAP_BUF_BYTES Message-ID: References: <20241107184331.3164784-1-sbrivio@redhat.com> <20241107184331.3164784-4-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="wPQfhER97a1Ox4FA" Content-Disposition: inline In-Reply-To: <20241107184331.3164784-4-sbrivio@redhat.com> Message-ID-Hash: D35UMPQIYSWV4RG4NBOWAQ5SQREE4QZP X-Message-ID-Hash: D35UMPQIYSWV4RG4NBOWAQ5SQREE4QZP 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: 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: --wPQfhER97a1Ox4FA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Nov 07, 2024 at 07:43:28PM +0100, Stefano Brivio wrote: > Given that we're comparing against 'n', which is signed, we cast > TAP_BUF_BYTES to ssize_t so that the maximum buffer usage, calculated > as the difference between TAP_BUF_BYTES and ETH_MAX_MTU, will also be > signed. >=20 > This doesn't necessarily happen on 32-bit architectures, though. On > armhf and i686, clang-tidy 18.1.8 and 19.1.2 report: >=20 > /home/pi/passt/tap.c:1087:16: error: comparison of integers of different = signs: 'ssize_t' (aka 'int') and 'unsigned int' [clang-diagnostic-sign-comp= are,-warnings-as-errors] > 1087 | for (n =3D 0; n <=3D (ssize_t)TAP_BUF_BYTES - ETH_MAX_MTU= ; n +=3D len) { > | ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >=20 > cast the whole difference to ssize_t, as we know it's going to be > positive anyway, instead of relying on that side effect. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > tap.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/tap.c b/tap.c > index f638f2c..a3ba958 100644 > --- a/tap.c > +++ b/tap.c > @@ -1084,7 +1084,7 @@ static void tap_pasta_input(struct ctx *c, const st= ruct timespec *now) > =20 > tap_flush_pools(); > =20 > - for (n =3D 0; n <=3D (ssize_t)TAP_BUF_BYTES - ETH_MAX_MTU; n +=3D len) { > + for (n =3D 0; n <=3D (ssize_t)(TAP_BUF_BYTES - ETH_MAX_MTU); n +=3D len= ) { > len =3D read(c->fd_tap, pkt_buf + n, ETH_MAX_MTU); > =20 > if (len =3D=3D 0) { --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --wPQfhER97a1Ox4FA Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmctWzoACgkQzQJF27ox 2GenfA//QqEFqJfseirahzfZab7LkClITRsyOCcScETwo1WD00k1LY8MRz+g9n37 kHIETf9VKSvxIJps7ZAy5coo7f9fvMW2pDHZlgFtAqegW6HYeWjstCo9DU6lMg2o ymQ1AO+i0H23Wxm2OmiOZ3bPrV4JtIzOdshVsP/Pk0nsW4NJ0WM70Zs6qAHALHf2 LiYQj6WFSu+ieT7WdZyVYVJvWprdZdBa7ghEVJaikMK3oQL/6y3Igrrq5gfCsXxo W5FFboIOHZaX6Rw/IjWrpucClDbLuWaeG70cB7swkFCUhR+jHNIH+OepDLHuHU18 3/YNCCeqLa+9TweuUa0qQcwOLyBGl/pjaRZlyLAbr7pXG/pum0uRlJo1MlX2RG30 8XT1JetYGR2F4VZGcO4G3UXPChIFfQrTPXNXuGxDBQ84BSOeiZZOL79KaL6T4do7 iX/qrfDzcS9Ryru4HNufpOgEVE4ZVs/q6k2j8vn8uDYfhHKK8T6Ljp9Da3H5dlJl tmEUbdB2gQE/XOdURjSRteOXrVQzX607kF4qDWu7n94UADxbPqD37Rfeq3f1xZru Oi4+Wm7cX5/bXkdVGx9/GYT/Qm1gXxmBE4SfSvam8aP8IdwI7FnRNxyQ/Jp1PBV3 CvFkEExVZJooI9Md02pIBAjYZkIJ429UkIG2qC4GXP1MrFc2REM= =NJGj -----END PGP SIGNATURE----- --wPQfhER97a1Ox4FA--