netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Oleksij Rempel <o.rempel@pengutronix.de>
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
	kernel@pengutronix.de, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org,
	Maxime Chevallier <maxime.chevallier@bootlin.com>
Subject: Re: [PATCH net-next v2 1/1] net: selftests: add PHY-loopback test for bad TCP checksums
Date: Mon, 14 Jul 2025 16:41:42 -0700	[thread overview]
Message-ID: <20250714164142.341e37a2@kernel.org> (raw)
In-Reply-To: <20250711072449.802677-1-o.rempel@pengutronix.de>

On Fri, 11 Jul 2025 09:24:49 +0200 Oleksij Rempel wrote:
> +			/* To avoid sparse warnings about operating on
> +			 * restricted __sum16/__be16 types, explicitly cast the
> +			 * checksum to a plain u16, perform the manipulation,
> +			 * and then cast the result back.
> +			 */
> +			csum = (__force u16)thdr->check;
> +
> +			/* Mangle the checksum by flipping the LSB. */
> +			csum ^= 1;
> +			/* If mangling resulted in 0, use the raw value for a
> +			 * mangled-zero checksum. We use the literal 0xffff
> +			 * because CSUM_MANGLED_0 has a restricted type.
> +			 */
> +			if (!csum)
> +				csum = 0xffff;
> +
> +			/* Cast the final integer value back to the restricted
> +			 * type
> +			 */
> +			thdr->check = (__force __sum16)csum;

Way to manny lines of code for something this simple.
Can csum_add() help you get rid of all these casts and comments?
-- 
pw-bot: cr

      parent reply	other threads:[~2025-07-14 23:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-11  7:24 [PATCH net-next v2 1/1] net: selftests: add PHY-loopback test for bad TCP checksums Oleksij Rempel
2025-07-12 12:25 ` Simon Horman
2025-07-14 23:41 ` Jakub Kicinski [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=20250714164142.341e37a2@kernel.org \
    --to=kuba@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maxime.chevallier@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=pabeni@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.
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 NNTP newsgroup(s).