Skip to content

Commit 2498e62

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
selftests/bpf: prevent unused variable warning in bpf_for()
Add __attribute__((unused)) to inner __p variable inside bpf_for(), bpf_for_each(), and bpf_repeat() macros to avoid compiler warnings about unused variable. Reported-by: Tejun Heo <tj@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20230309054015.4068562-2-andrii@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 63d78b7 commit 2498e62

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tools/testing/selftests/bpf/progs/bpf_misc.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ extern void bpf_iter_num_destroy(struct bpf_iter_num *it) __ksym;
115115
struct bpf_iter_##type ___it __attribute__((aligned(8), /* enforce, just in case */, \
116116
cleanup(bpf_iter_##type##_destroy))), \
117117
/* ___p pointer is just to call bpf_iter_##type##_new() *once* to init ___it */ \
118-
*___p = (bpf_iter_##type##_new(&___it, ##args), \
118+
*___p __attribute__((unused)) = ( \
119+
bpf_iter_##type##_new(&___it, ##args), \
119120
/* this is a workaround for Clang bug: it currently doesn't emit BTF */ \
120121
/* for bpf_iter_##type##_destroy() when used from cleanup() attribute */ \
121122
(void)bpf_iter_##type##_destroy, (void *)0); \
@@ -143,7 +144,8 @@ extern void bpf_iter_num_destroy(struct bpf_iter_num *it) __ksym;
143144
struct bpf_iter_num ___it __attribute__((aligned(8), /* enforce, just in case */ \
144145
cleanup(bpf_iter_num_destroy))), \
145146
/* ___p pointer is necessary to call bpf_iter_num_new() *once* to init ___it */ \
146-
*___p = (bpf_iter_num_new(&___it, (start), (end)), \
147+
*___p __attribute__((unused)) = ( \
148+
bpf_iter_num_new(&___it, (start), (end)), \
147149
/* this is a workaround for Clang bug: it currently doesn't emit BTF */ \
148150
/* for bpf_iter_num_destroy() when used from cleanup() attribute */ \
149151
(void)bpf_iter_num_destroy, (void *)0); \
@@ -167,7 +169,8 @@ extern void bpf_iter_num_destroy(struct bpf_iter_num *it) __ksym;
167169
struct bpf_iter_num ___it __attribute__((aligned(8), /* enforce, just in case */ \
168170
cleanup(bpf_iter_num_destroy))), \
169171
/* ___p pointer is necessary to call bpf_iter_num_new() *once* to init ___it */ \
170-
*___p = (bpf_iter_num_new(&___it, 0, (N)), \
172+
*___p __attribute__((unused)) = ( \
173+
bpf_iter_num_new(&___it, 0, (N)), \
171174
/* this is a workaround for Clang bug: it currently doesn't emit BTF */ \
172175
/* for bpf_iter_num_destroy() when used from cleanup() attribute */ \
173176
(void)bpf_iter_num_destroy, (void *)0); \

0 commit comments

Comments
 (0)