Re: [PATCH bpf-next v2 2/4] bpf: bpf_csum_diff: optimize and homogenize for all archs

From: Daniel Borkmann
Date: Fri Oct 25 2024 - 07:33:07 EST


On 10/25/24 12:11 PM, Puranjay Mohan wrote:
[...]
This file has a lot of such sparse warnings. Specifically, to fix the
warning introduced by me, I can apply the following diff:

--- >8 ---

diff --git a/net/core/filter.c b/net/core/filter.c
index e00bec7de9ed..b94037f29b2a 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2019,16 +2019,18 @@ BPF_CALL_5(bpf_csum_diff, __be32 *, from, u32, from_size,
* Even for diffing, from_size and to_size don't need to be equal.
*/

+ __wsum ret = seed;
+
if (from_size && to_size)
- return csum_from32to16(csum_sub(csum_partial(to, to_size, seed),
- csum_partial(from, from_size, 0)));
+ ret = csum_sub(csum_partial(to, to_size, seed), csum_partial(from, from_size, 0));

Lets also pass ret into csum_partial() instead of seed given the arg
is of type __wsum there too, otherwise lgtm and yes lets fix these.

+
if (to_size)
- return csum_from32to16(csum_partial(to, to_size, seed));
+ ret = csum_partial(to, to_size, seed);

if (from_size)
- return csum_from32to16(~csum_partial(from, from_size, ~seed));
+ ret = ~csum_partial(from, from_size, ~seed);

- return seed;
+ return csum_from32to16((__force unsigned int)ret);
}

--- 8< ---

If others feel that fixing these warnings is useful, I can send another
version with above diff. I will then also send a separate patch to fix
all other such warnings in this file.

That would be great, as separate patch, agree.

Thanks,
Daniel