Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <baihaowen@meizu.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/1648779354-14700-1-git-send-email-baihaowen@meizu.com

authored by

Haowen Bai and committed by
Andrii Nakryiko
f6d60fac e299bcd4

+7 -7
+1 -1
tools/testing/selftests/bpf/progs/test_l4lb_noinline.c
··· 218 218 219 219 if (hash != 0x358459b7 /* jhash of ipv4 packet */ && 220 220 hash != 0x2f4bc6bb /* jhash of ipv6 packet */) 221 - return 0; 221 + return false; 222 222 223 223 real_pos = bpf_map_lookup_elem(&ch_rings, &key); 224 224 if (!real_pos)
+6 -6
tools/testing/selftests/bpf/progs/test_xdp_noinline.c
··· 564 564 hash = get_packet_hash(pckt, hash_16bytes); 565 565 if (hash != 0x358459b7 /* jhash of ipv4 packet */ && 566 566 hash != 0x2f4bc6bb /* jhash of ipv6 packet */) 567 - return 0; 567 + return false; 568 568 key = 2 * vip_info->vip_num + hash % 2; 569 569 real_pos = bpf_map_lookup_elem(&ch_rings, &key); 570 570 if (!real_pos) 571 - return 0; 571 + return false; 572 572 key = *real_pos; 573 573 *real = bpf_map_lookup_elem(&reals, &key); 574 574 if (!(*real)) 575 - return 0; 575 + return false; 576 576 if (!(vip_info->flags & (1 << 1))) { 577 577 __u32 conn_rate_key = 512 + 2; 578 578 struct lb_stats *conn_rate_stats = 579 579 bpf_map_lookup_elem(&stats, &conn_rate_key); 580 580 581 581 if (!conn_rate_stats) 582 - return 1; 582 + return true; 583 583 cur_time = bpf_ktime_get_ns(); 584 584 if ((cur_time - conn_rate_stats->v2) >> 32 > 0xffFFFF) { 585 585 conn_rate_stats->v1 = 1; ··· 587 587 } else { 588 588 conn_rate_stats->v1 += 1; 589 589 if (conn_rate_stats->v1 >= 1) 590 - return 1; 590 + return true; 591 591 } 592 592 if (pckt->flow.proto == IPPROTO_UDP) 593 593 new_dst_lru.atime = cur_time; 594 594 new_dst_lru.pos = key; 595 595 bpf_map_update_elem(lru_map, &pckt->flow, &new_dst_lru, 0); 596 596 } 597 - return 1; 597 + return true; 598 598 } 599 599 600 600 __attribute__ ((noinline))