samples/bpf: fix LLVM compilation warning with
Subsystems (3)
cover samples/bpf: fix LLVM compilation warning with
Currently, compiling samples/bpf with LLVM emits several warning. They are only small details, but they do not appear when compiled with GCC. Detailed compilation command and warning logs can be found from bpf CI.
Daniel T. Lee (3):
samples/bpf: remove unused function with test_lru_dist samples/bpf: replace meaningless counter with tracex4 samples/bpf: fix uninitialized warning with
test_current_task_under_cgroup
samples/bpf/test_current_task_under_cgroup_user.c | 6 ++++-- samples/bpf/test_lru_dist.c | 5 ----- samples/bpf/tracex4_user.c | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/3 samples/bpf: remove unused function with test_lru_dist
Currently, compiling samples/bpf with LLVM warns about the unused function with test_lru_dist.
./samples/bpf/test_lru_dist.c:45:19:
warning: unused function 'list_empty' [-Wunused-function] static inline int list_empty(const struct list_head *head)
^
1 warning generated.
This commit resolve this compiler warning by removing the abandoned function.
--- samples/bpf/test_lru_dist.c | 5 ----- 1 file changed, 5 deletions(-)
samples/bpf/test_lru_dist.c +0 -5
@@ -42,11 +42,6 @@ static inline void INIT_LIST_HEAD(struct list_head *list) list->prev = list; } -static inline int list_empty (const struct list_head *head) -{ -return head->next == head; -} -static inline void __list_add (struct list_head *new,struct list_head *prev,struct list_head *next)
Signature · 1 line
2.34.1
Re: [bpf-next 1/3] samples/bpf: remove unused function with test_lru_dist
Quoted 9 lines · Daniel T. Lee
Currently, compiling
samples/bpfwith LLVM warns about the unused function withtest_lru_dist.
./samples/bpf/test_lru_dist.c:45:19:
warning: unused function 'list_empty' [-Wunused-function] static inline intlist_empty(const struct list_head *head)
^
1 warning generated.
Quoted 4 lines
This commit resolve this compiler warning by removing the abandoned function.
Signed-off-by Daniel T. Lee <[email protected]>
PATCH 2/3 samples/bpf: replace meaningless counter with tracex4
In reply to Daniel T. LeeCurrently, compiling samples/bpf with LLVM warns about the unused but set variable with tracex4_user.
./samples/bpf/tracex4_user.c:54:14:
warning: variable 'i' set but not used [-Wunused-but-set-variable]
int map_fd, i, j = 0;
^
1 warning generated.This commit resolve this compiler warning by replacing the meaningless counter.
--- samples/bpf/tracex4_user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
samples/bpf/tracex4_user.c +2 -2
@@ -51,7 +51,7 @@ int main(int ac, char **argv)struct bpf_program *prog;struct bpf_object *obj;char filename[256 ]; -int map_fd, i, j =0 ; +int map_fd, j =0 ;snprintf (filename,sizeof (filename),"%s_kern.o" , argv[0 ]); obj =bpf_object__open_file (filename,NULL );
@@ -82,7 +82,7 @@ int main(int ac, char **argv) j++; } -for (i =0 ; ; i++) { +while (1 ) {print_old_objects (map_fd);sleep (1 ); }
Signature · 1 line
2.34.1
Re: [bpf-next 2/3] samples/bpf: replace meaningless counter with tracex4
Quoted 9 lines · Daniel T. Lee
Currently, compiling
samples/bpfwith LLVM warns about the unused but set variable withtracex4_user../samples/bpf/tracex4_user.c:54:14: warning: variable 'i' set but not used [-Wunused-but-set-variable] int map_fd, i, j = 0; ^ 1 warning generated.
Quoted 4 lines
This commit resolve this compiler warning by replacing the meaningless counter.
Signed-off-by Daniel T. Lee <[email protected]>
PATCH 3/3 samples/bpf: fix uninitialized warning with test_current_task_under_cgroup
In reply to Daniel T. LeeCurrently, compiling samples/bpf with LLVM warns about the uninitialized use of variable with test_current_task_under_cgroup.
./samples/bpf/test_current_task_under_cgroup_user.c:57:6:
warning: variable 'cg2' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (setup_cgroup_environment())
^~~~~~~~~~~~~~~~~~~~~~~~~~
./samples/bpf/test_current_task_under_cgroup_user.c:106:8:
note: uninitialized use occurs here
close(cg2);
^~~
./samples/bpf/test_current_task_under_cgroup_user.c:57:2:
note: remove the 'if' if its condition is always false
if (setup_cgroup_environment())
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./samples/bpf/test_current_task_under_cgroup_user.c:19:9:
note: initialize the variable 'cg2' to silence this warning
int cg2, idx = 0, rc = 1;
^
= 0
1 warning generated.This commit resolve this compiler warning by pre-initialize the variable with error for safeguard.
--- samples/bpf/test_current_task_under_cgroup_user.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
samples/bpf/test_current_task_under_cgroup_user.c +4 -2
@@ -14,9 +14,9 @@int main (int argc,char **argv) {pid_t remote_pid, local_pid =getpid (); +int cg2 =-1 , idx =0 , rc =1 ;struct bpf_link *link =NULL ;struct bpf_program *prog; -int cg2, idx =0 , rc =1 ;struct bpf_object *obj;char filename[256 ];int map_fd[2 ];
@@ -103,7 +103,9 @@ int main(int argc, char **argv) rc =0 ; err: -close (cg2); +if (cg2 !=-1 ) +close (cg2); +cleanup_cgroup_environment (); cleanup:
Signature · 1 line
2.34.1
Re: [bpf-next 3/3] samples/bpf: fix uninitialized warning with test_current_task_under_cgroup
Quoted 22 lines · Daniel T. Lee
Currently, compiling
samples/bpfwith LLVM warns about the uninitialized use of variable withtest_current_task_under_cgroup../samples/bpf/test_current_task_under_cgroup_user.c:57:6: warning: variable 'cg2' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] if (setup_cgroup_environment()) ^~~~~~~~~~~~~~~~~~~~~~~~~~ ./samples/bpf/test_current_task_under_cgroup_user.c:106:8: note: uninitialized use occurs here close(cg2); ^~~ ./samples/bpf/test_current_task_under_cgroup_user.c:57:2: note: remove the 'if' if its condition is always false if (setup_cgroup_environment()) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ./samples/bpf/test_current_task_under_cgroup_user.c:19:9: note: initialize the variable 'cg2' to silence this warning int cg2, idx = 0, rc = 1; ^ = 0 1 warning generated.
Quoted 4 lines
This commit resolve this compiler warning by pre-initialize the variable with error for safeguard.
Signed-off-by Daniel T. Lee <[email protected]>
Quoted 3 lines · Daniel T. Lee
Currently, compiling
samples/bpfwith LLVM emits several warning. They are only small details, but they do not appear when compiled with GCC. Detailed compilation command and warning logs can be found from bpf CI.
Could you change the subject line to
samples/bpf: fix LLVM compilation warning
Quoted 12 lines
Daniel T. Lee (3):
samples/bpf: remove unused function withtest_lru_distsamples/bpf: replace meaningless counter with tracex4samples/bpf: fix uninitialized warning with
test_current_task_under_cgroupsamples/bpf/test_current_task_under_cgroup_user.c | 6 ++++-- samples/bpf/test_lru_dist.c | 5 ----- samples/bpf/tracex4_user.c | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-)
Quoted 23 lines · Yonghong Song
Quoted 3 lines · Daniel T. Lee
Currently, compiling
samples/bpfwith LLVM emits several warning. They are only small details, but they do not appear when compiled with GCC. Detailed compilation command and warning logs can be found from bpf CI.Could you change the subject line to
samples/bpf: fix LLVM compilation warningQuoted 12 lines
Daniel T. Lee (3):
samples/bpf: remove unused function withtest_lru_distsamples/bpf: replace meaningless counter with tracex4samples/bpf: fix uninitialized warning with
test_current_task_under_cgroupsamples/bpf/test_current_task_under_cgroup_user.c | 6 ++++-- samples/bpf/test_lru_dist.c | 5 ----- samples/bpf/tracex4_user.c | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-)
Thanks for pointing this out.
I will send a v2 patch.