Skip to content

Commit

Permalink
bpftool: Fix build warnings with -Wtype-limits
Browse files Browse the repository at this point in the history
Quentin reported build warnings when building bpftool :

    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: 62b57e3 ("bpftool: Add perf event names")
Reported-by: Quentin Monnet <[email protected]>
Suggested-by: Quentin Monnet <[email protected]>
Signed-off-by: Yafang Shao <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Acked-by: Quentin Monnet <[email protected]>
Closes: https://lore.kernel.org/bpf/[email protected]
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
laoar authored and borkmann committed Aug 30, 2023
1 parent 32337c0 commit 6a8faf1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tools/bpf/bpftool/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
})
Expand Down

0 comments on commit 6a8faf1

Please sign in to comment.