diff mbox series

[bpf-next] bpftool: Fix build error with -Werror=type-limits

Message ID 20230829154248.3762-1-laoar.shao@gmail.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [bpf-next] bpftool: Fix build error with -Werror=type-limits | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/cc_maintainers warning 1 maintainers not CCed: yonghong.song@linux.dev
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 9 this patch: 9
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-1 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-8 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-21 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for veristat
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-7 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-0 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-5 success Logs for set-matrix

Commit Message

Yafang Shao Aug. 29, 2023, 3:42 p.m. UTC
Quentin reported a build error as follows,

    link.c: In function ‘perf_config_hw_cache_str’:
    link.c:86:18: warning: comparison of unsigned expression in ‘>= 0’ is always true [-Wtype-limits]
       86 |         if ((id) >= 0 && (id) < ARRAY_SIZE(array))      \
          |                  ^~
    link.c:320:20: note: in expansion of macro ‘perf_event_name’
      320 |         hw_cache = perf_event_name(evsel__hw_cache, config & 0xff);
          |                    ^~~~~~~~~~~~~~~
    [... more of the same for the other calls to perf_event_name ...]

He also pointed out the reason and the solution:

  We're always passing unsigned, so it should be safe to drop the check on
  (id) >= 0.

Fixes: 62b57e3ddd64 ("bpftool: Add perf event names")
Reported-by: Quentin Monnet <quentin@isovalent.com>
Closes: https://lore.kernel.org/bpf/a35d9a2d-54a0-49ec-9ed1-8fcf1369d3cc@isovalent.com
Suggested-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 tools/bpf/bpftool/link.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Quentin Monnet Aug. 29, 2023, 3:51 p.m. UTC | #1
On 29/08/2023 16:42, Yafang Shao wrote:
> Quentin reported a build error as follows,

Just a warning :)

> 
>     link.c: In function ‘perf_config_hw_cache_str’:
>     link.c:86:18: warning: comparison of unsigned expression in ‘>= 0’ is always true [-Wtype-limits]
>        86 |         if ((id) >= 0 && (id) < ARRAY_SIZE(array))      \
>           |                  ^~
>     link.c:320:20: note: in expansion of macro ‘perf_event_name’
>       320 |         hw_cache = perf_event_name(evsel__hw_cache, config & 0xff);
>           |                    ^~~~~~~~~~~~~~~
>     [... more of the same for the other calls to perf_event_name ...]
> 
> He also pointed out the reason and the solution:
> 
>   We're always passing unsigned, so it should be safe to drop the check on
>   (id) >= 0.
> 
> Fixes: 62b57e3ddd64 ("bpftool: Add perf event names")
> Reported-by: Quentin Monnet <quentin@isovalent.com>
> Closes: https://lore.kernel.org/bpf/a35d9a2d-54a0-49ec-9ed1-8fcf1369d3cc@isovalent.com
> Suggested-by: Quentin Monnet <quentin@isovalent.com>
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>

Thank you!

Acked-by: Quentin Monnet <quentin@isovalent.com>
Yafang Shao Aug. 30, 2023, 2:41 a.m. UTC | #2
On Tue, Aug 29, 2023 at 11:51 PM Quentin Monnet <quentin@isovalent.com> wrote:
>
> On 29/08/2023 16:42, Yafang Shao wrote:
> > Quentin reported a build error as follows,
>
> Just a warning :)

Will reword it in the next version.

>
> >
> >     link.c: In function ‘perf_config_hw_cache_str’:
> >     link.c:86:18: warning: comparison of unsigned expression in ‘>= 0’ is always true [-Wtype-limits]
> >        86 |         if ((id) >= 0 && (id) < ARRAY_SIZE(array))      \
> >           |                  ^~
> >     link.c:320:20: note: in expansion of macro ‘perf_event_name’
> >       320 |         hw_cache = perf_event_name(evsel__hw_cache, config & 0xff);
> >           |                    ^~~~~~~~~~~~~~~
> >     [... more of the same for the other calls to perf_event_name ...]
> >
> > He also pointed out the reason and the solution:
> >
> >   We're always passing unsigned, so it should be safe to drop the check on
> >   (id) >= 0.
> >
> > Fixes: 62b57e3ddd64 ("bpftool: Add perf event names")
> > Reported-by: Quentin Monnet <quentin@isovalent.com>
> > Closes: https://lore.kernel.org/bpf/a35d9a2d-54a0-49ec-9ed1-8fcf1369d3cc@isovalent.com
> > Suggested-by: Quentin Monnet <quentin@isovalent.com>
> > Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
>
> Thank you!
>
> Acked-by: Quentin Monnet <quentin@isovalent.com>
>

Thanks for your review.
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
index 0b214f6ab5c8..2e5c231e08ac 100644
--- a/tools/bpf/bpftool/link.c
+++ b/tools/bpf/bpftool/link.c
@@ -83,7 +83,7 @@  const char *evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX] = {
 #define perf_event_name(array, id) ({			\
 	const char *event_str = NULL;			\
 							\
-	if ((id) >= 0 && (id) < ARRAY_SIZE(array))	\
+	if ((id) < ARRAY_SIZE(array))			\
 		event_str = array[id];			\
 	event_str;					\
 })