Skip to content

Commit 7a02814

Browse files
MehdibenhadjkhelifaKernel Patches Daemon
authored andcommitted
selftests/bpf: Add -Wsign-compare C compilation flag
-Change all the source files and the corresponding headers to having matching sign comparisons. Signed-off-by: Mehdi Ben Hadj Khelifa <[email protected]>
1 parent 7eb88ba commit 7a02814

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+109
-107
lines changed

tools/lib/bpf/usdt.bpf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ int bpf_usdt_arg_size(struct pt_regs *ctx, __u64 arg_num)
148148
if (arg_num >= BPF_USDT_MAX_ARG_CNT)
149149
return -ENOENT;
150150
barrier_var(arg_num);
151-
if (arg_num >= spec->arg_cnt)
151+
if (arg_num >= (__u64)spec->arg_cnt)
152152
return -ENOENT;
153153

154154
arg_spec = &spec->args[arg_num];
@@ -184,7 +184,7 @@ int bpf_usdt_arg(struct pt_regs *ctx, __u64 arg_num, long *res)
184184
if (arg_num >= BPF_USDT_MAX_ARG_CNT)
185185
return -ENOENT;
186186
barrier_var(arg_num);
187-
if (arg_num >= spec->arg_cnt)
187+
if (arg_num >= (__u64)spec->arg_cnt)
188188
return -ENOENT;
189189

190190
arg_spec = &spec->args[arg_num];

tools/testing/selftests/bpf/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,8 @@ BPF_CFLAGS = -g -Wall -Werror -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \
453453
-I$(abspath $(OUTPUT)/../usr/include) \
454454
-std=gnu11 \
455455
-fno-strict-aliasing \
456-
-Wno-compare-distinct-pointer-types
457-
# TODO: enable me -Wsign-compare
456+
-Wno-compare-distinct-pointer-types \
457+
-Wsign-compare
458458

459459
CLANG_CFLAGS = $(CLANG_SYS_INCLUDES)
460460

tools/testing/selftests/bpf/bpf_arena_htab.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static hashtab_elem_t *lookup_elem_raw(arena_list_head_t *head, __u32 hash, int
4242
hashtab_elem_t *l;
4343

4444
list_for_each_entry(l, head, hash_node)
45-
if (l->hash == hash && l->key == key)
45+
if ((__u32)l->hash == hash && l->key == key)
4646
return l;
4747

4848
return NULL;

tools/testing/selftests/bpf/progs/arena_list.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int arena_list_add(void *ctx)
5050

5151
list_head = &global_head;
5252

53-
for (i = zero; i < cnt && can_loop; i++) {
53+
for (i = zero; i < (__u64)cnt && can_loop; i++) {
5454
struct elem __arena *n = bpf_alloc(sizeof(*n));
5555

5656
test_val++;

tools/testing/selftests/bpf/progs/bench_local_storage_create.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ int BPF_PROG(sched_process_fork, struct task_struct *parent, struct task_struct
4444
{
4545
struct storage *stg;
4646

47-
if (parent->tgid != bench_pid)
47+
if ((__u32)parent->tgid != bench_pid)
4848
return 0;
4949

5050
stg = bpf_task_storage_get(&task_storage_map, child, NULL,

tools/testing/selftests/bpf/progs/bind_perm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <bpf/bpf_helpers.h>
88
#include <bpf/bpf_endian.h>
99

10-
static __always_inline int bind_prog(struct bpf_sock_addr *ctx, int family)
10+
static __always_inline int bind_prog(struct bpf_sock_addr *ctx, __u32 family)
1111
{
1212
struct bpf_sock *sk;
1313

tools/testing/selftests/bpf/progs/bpf_cc_cubic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static void tcp_cwnd_reduction(struct sock *sk, int newly_acked_sacked,
9191
(__u64)tp->snd_ssthresh * prr_delivered + tp->prior_cwnd - 1;
9292
sndcnt = (__u32)div64_u64(dividend, (__u64)tp->prior_cwnd) - tp->prr_out;
9393
} else {
94-
sndcnt = max(prr_delivered - tp->prr_out, newly_acked_sacked);
94+
sndcnt = max(prr_delivered - tp->prr_out, (__u32)newly_acked_sacked);
9595
if (flag & FLAG_SND_UNA_ADVANCED && !newly_lost)
9696
sndcnt++;
9797
sndcnt = min(delta, sndcnt);

tools/testing/selftests/bpf/progs/bpf_cubic.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ static void bictcp_update(struct bpf_bictcp *ca, __u32 cwnd, __u32 acked)
277277
ca->ack_cnt += acked; /* count the number of ACKed packets */
278278

279279
if (ca->last_cwnd == cwnd &&
280-
(__s32)(tcp_jiffies32 - ca->last_time) <= HZ / 32)
280+
(__s32)(tcp_jiffies32 - ca->last_time) <= (__s32)HZ / 32)
281281
return;
282282

283283
/* The CUBIC function can update ca->cnt at most once per jiffy.
@@ -474,7 +474,7 @@ static void hystart_update(struct sock *sk, __u32 delay)
474474
if (sk->sk_pacing_status == SK_PACING_NONE)
475475
threshold >>= 1;
476476

477-
if ((__s32)(now - ca->round_start) > threshold) {
477+
if ((__s32)(now - ca->round_start) > (__s32)threshold) {
478478
ca->found = 1;
479479
tp->snd_ssthresh = tp->snd_cwnd;
480480
}
@@ -512,7 +512,7 @@ void BPF_PROG(bpf_cubic_acked, struct sock *sk, const struct ack_sample *sample)
512512
return;
513513

514514
/* Discard delay samples right after fast recovery */
515-
if (ca->epoch_start && (__s32)(tcp_jiffies32 - ca->epoch_start) < HZ)
515+
if (ca->epoch_start && (__s32)(tcp_jiffies32 - ca->epoch_start) < (__s32)HZ)
516516
return;
517517

518518
delay = sample->rtt_us;
@@ -525,7 +525,7 @@ void BPF_PROG(bpf_cubic_acked, struct sock *sk, const struct ack_sample *sample)
525525

526526
/* hystart triggers when cwnd is larger than some threshold */
527527
if (!ca->found && tcp_in_slow_start(tp) && hystart &&
528-
tp->snd_cwnd >= hystart_low_window)
528+
tp->snd_cwnd >= (__u32)hystart_low_window)
529529
hystart_update(sk, delay);
530530
}
531531

tools/testing/selftests/bpf/progs/bpf_iter_bpf_percpu_array_map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int dump_bpf_percpu_array_map(struct bpf_iter__bpf_map_elem *ctx)
2424
__u32 *key = ctx->key;
2525
void *pptr = ctx->value;
2626
__u32 step;
27-
int i;
27+
__u32 i;
2828

2929
if (key == (void *)0 || pptr == (void *)0)
3030
return 0;

tools/testing/selftests/bpf/progs/bpf_iter_task_stack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int dump_task_stack(struct bpf_iter__task *ctx)
2727
BPF_SEQ_PRINTF(seq, "pid: %8u num_entries: %8u\n", task->pid,
2828
retlen / SIZE_OF_ULONG);
2929
for (i = 0; i < MAX_STACK_TRACE_DEPTH; i++) {
30-
if (retlen > i * SIZE_OF_ULONG)
30+
if ((__u32)retlen > i * SIZE_OF_ULONG)
3131
BPF_SEQ_PRINTF(seq, "[<0>] %pB\n", (void *)entries[i]);
3232
}
3333
BPF_SEQ_PRINTF(seq, "\n");

0 commit comments

Comments
 (0)