Skip to content

Commit 96a233e

Browse files
bjdooks-sifiveborkmann
authored andcommitted
bpf: Add endian modifiers to fix endian warnings
A couple of the syscalls which load values (bpf_skb_load_helper_16() and bpf_skb_load_helper_32()) are using u16/u32 types which are triggering warnings as they are then converted from big-endian to CPU-endian. Fix these by making the types __be instead. Fixes the following sparse warnings: net/core/filter.c:246:32: warning: cast to restricted __be16 net/core/filter.c:246:32: warning: cast to restricted __be16 net/core/filter.c:246:32: warning: cast to restricted __be16 net/core/filter.c:246:32: warning: cast to restricted __be16 net/core/filter.c:273:32: warning: cast to restricted __be32 net/core/filter.c:273:32: warning: cast to restricted __be32 net/core/filter.c:273:32: warning: cast to restricted __be32 net/core/filter.c:273:32: warning: cast to restricted __be32 net/core/filter.c:273:32: warning: cast to restricted __be32 net/core/filter.c:273:32: warning: cast to restricted __be32 Signed-off-by: Ben Dooks <ben.dooks@sifive.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20220714105101.297304-1-ben.dooks@sifive.com
1 parent 5002615 commit 96a233e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/core/filter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ BPF_CALL_2(bpf_skb_load_helper_8_no_cache, const struct sk_buff *, skb,
237237
BPF_CALL_4(bpf_skb_load_helper_16, const struct sk_buff *, skb, const void *,
238238
data, int, headlen, int, offset)
239239
{
240-
u16 tmp, *ptr;
240+
__be16 tmp, *ptr;
241241
const int len = sizeof(tmp);
242242

243243
if (offset >= 0) {
@@ -264,7 +264,7 @@ BPF_CALL_2(bpf_skb_load_helper_16_no_cache, const struct sk_buff *, skb,
264264
BPF_CALL_4(bpf_skb_load_helper_32, const struct sk_buff *, skb, const void *,
265265
data, int, headlen, int, offset)
266266
{
267-
u32 tmp, *ptr;
267+
__be32 tmp, *ptr;
268268
const int len = sizeof(tmp);
269269

270270
if (likely(offset >= 0)) {

0 commit comments

Comments
 (0)