Re: [PATCH net-next v2 1/1] net: selftests: add PHY-loopback test for bad TCP checksums
From: Jakub Kicinski
Date: Mon Jul 14 2025 - 19:41:59 EST
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