aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYafang Shao <laoar.shao@gmail.com>2023-08-30 03:03:25 +0000
committerQuentin Monnet <qmonnet+github@qoba.lt>2023-09-26 11:17:14 +0200
commit99b794f23b11d0c323c878d50b68dc2c93fd24a7 (patch)
treeb856e1f984afa594304d768930e1c28f6cc48845
parentc3686c66f620c4aaac63ebba096899965d41e7da (diff)
downloadbpftool-99b794f23b11d0c323c878d50b68dc2c93fd24a7.tar.gz
bpftool: Fix build warnings with -Wtype-limits
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: 62b57e3ddd64 ("bpftool: Add perf event names") Reported-by: Quentin Monnet <quentin@isovalent.com> Suggested-by: Quentin Monnet <quentin@isovalent.com> Signed-off-by: Yafang Shao <laoar.shao@gmail.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Quentin Monnet <quentin@isovalent.com> Closes: https://lore.kernel.org/bpf/a35d9a2d-54a0-49ec-9ed1-8fcf1369d3cc@isovalent.com Link: https://lore.kernel.org/bpf/20230830030325.3786-1-laoar.shao@gmail.com
-rw-r--r--src/link.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/link.c b/src/link.c
index 0b214f6..2e5c231 100644
--- a/src/link.c
+++ b/src/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; \
})