Skip to content

Commit f6d60fa

Browse files
Lotte-Baianakryiko
authored andcommitted
selftests/bpf: Return true/false (not 1/0) from bool functions
Return boolean values ("true" or "false") instead of 1 or 0 from bool functions. This fixes the following warnings from coccicheck: ./tools/testing/selftests/bpf/progs/test_xdp_noinline.c:567:9-10: WARNING: return of 0/1 in function 'get_packet_dst' with return type bool ./tools/testing/selftests/bpf/progs/test_l4lb_noinline.c:221:9-10: WARNING: return of 0/1 in function 'get_packet_dst' with return type bool Signed-off-by: Haowen Bai <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Reviewed-by: Shuah Khan <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent e299bcd commit f6d60fa

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ static __noinline bool get_packet_dst(struct real_definition **real,
218218

219219
if (hash != 0x358459b7 /* jhash of ipv4 packet */ &&
220220
hash != 0x2f4bc6bb /* jhash of ipv6 packet */)
221-
return 0;
221+
return false;
222222

223223
real_pos = bpf_map_lookup_elem(&ch_rings, &key);
224224
if (!real_pos)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -564,37 +564,37 @@ static bool get_packet_dst(struct real_definition **real,
564564
hash = get_packet_hash(pckt, hash_16bytes);
565565
if (hash != 0x358459b7 /* jhash of ipv4 packet */ &&
566566
hash != 0x2f4bc6bb /* jhash of ipv6 packet */)
567-
return 0;
567+
return false;
568568
key = 2 * vip_info->vip_num + hash % 2;
569569
real_pos = bpf_map_lookup_elem(&ch_rings, &key);
570570
if (!real_pos)
571-
return 0;
571+
return false;
572572
key = *real_pos;
573573
*real = bpf_map_lookup_elem(&reals, &key);
574574
if (!(*real))
575-
return 0;
575+
return false;
576576
if (!(vip_info->flags & (1 << 1))) {
577577
__u32 conn_rate_key = 512 + 2;
578578
struct lb_stats *conn_rate_stats =
579579
bpf_map_lookup_elem(&stats, &conn_rate_key);
580580

581581
if (!conn_rate_stats)
582-
return 1;
582+
return true;
583583
cur_time = bpf_ktime_get_ns();
584584
if ((cur_time - conn_rate_stats->v2) >> 32 > 0xffFFFF) {
585585
conn_rate_stats->v1 = 1;
586586
conn_rate_stats->v2 = cur_time;
587587
} else {
588588
conn_rate_stats->v1 += 1;
589589
if (conn_rate_stats->v1 >= 1)
590-
return 1;
590+
return true;
591591
}
592592
if (pckt->flow.proto == IPPROTO_UDP)
593593
new_dst_lru.atime = cur_time;
594594
new_dst_lru.pos = key;
595595
bpf_map_update_elem(lru_map, &pckt->flow, &new_dst_lru, 0);
596596
}
597-
return 1;
597+
return true;
598598
}
599599

600600
__attribute__ ((noinline))

0 commit comments

Comments
 (0)