Skip to contentSkip to conversation

selftests/bpf: fix const qualifier in fexit_bpf2bpf test

PATCH In review Woojin Ji 2 participants 3 messages Apr 9

Subsystems (3)
lore
Share & tools
lore

Woojin Ji

author
#0 lore raw

PATCH 1/1 selftests/bpf: fix const qualifier in fexit_bpf2bpf test

prog_name is an array of const char * strings, so strstr() returns a pointer into const data.

Store the result in a const char * to avoid discarding the const qualifier.

With GCC 15 this triggers -Werror=discarded-qualifiers and breaks the build of tools/testing/selftests/bpf.

---
 tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c +1 -1
index f29fc789c14b..d8225da4c1af 100644
@@ -111,7 +111,7 @@ static void test_fexit_bpf2bpf_common(const char *obj_file,
 		struct bpf_link_info link_info;
 		struct bpf_program *pos;
 		const char *pos_sec_name;
-		char *tgt_name;
+		const char *tgt_name;
 		__s32 btf_id;
 
 		tgt_name = strstr(prog_name[i], "/");
Signature · 1 line
2.53.0
#1 lore raw
Quoted 19 lines · Woojin Ji

prog_name is an array of const char * strings, so strstr() returns a pointer into const data.

Store the result in a const char * to avoid discarding the const qualifier.

With GCC 15 this triggers -Werror=discarded-qualifiers and breaks the build of tools/testing/selftests/bpf.

---
  tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c +0 -0
index f29fc789c14b..d8225da4c1af 100644

tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c static void test_fexit_bpf2bpf_common(const char *obj_file, · line 117

Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c +1 -1
@@ -111,7 +111,7 @@ static void test_fexit_bpf2bpf_common(const char *obj_file,
  		struct bpf_link_info link_info;
  		struct bpf_program *pos;
  		const char *pos_sec_name;
-		char *tgt_name;
+		const char *tgt_name;
  		__s32 btf_id;
 
  		tgt_name = strstr(prog_name[i], "/");

Already exist.

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c?id=ca0f39a369c5f927c3d004e63a5a778b08a9df94

author
#2 lore raw

Thanks for the pointer.

I missed that commit ca0f39a369c5 was already applied to bpf-next. Sorry for sending a duplicate patch.