]> git.baikalelectronics.ru Git - kernel.git/commit
selftests/bpf: Fix a tautological-constant-out-of-range-compare compiler warning
authorYonghong Song <yhs@fb.com>
Fri, 12 Nov 2021 20:48:38 +0000 (12:48 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 12 Nov 2021 22:11:46 +0000 (14:11 -0800)
commit6b7351067c106c09a69603c0d156d4451bc3194e
tree6a295bc8db626e139f4e1e7a1326d08e69e43285
parentec6fafe1d1f17c8e2b4b2af4807b5de673bf4ef6
selftests/bpf: Fix a tautological-constant-out-of-range-compare compiler warning

When using clang to build selftests with LLVM=1 in make commandline,
I hit the following compiler warning:

  benchs/bench_bloom_filter_map.c:84:46: warning: result of comparison of constant 256
    with expression of type '__u8' (aka 'unsigned char') is always false
    [-Wtautological-constant-out-of-range-compare]
                if (args.value_size < 2 || args.value_size > 256) {
                                           ~~~~~~~~~~~~~~~ ^ ~~~

The reason is arg.vaue_size has type __u8, so comparison "args.value_size > 256"
is always false.

This patch fixed the issue by doing proper comparison before assigning the
value to args.value_size. The patch also fixed the same issue in two
other places.

Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211112204838.3579953-1-yhs@fb.com
tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c