• Daniel T. Lee's avatar
    samples/bpf: fix uninitialized warning with test_current_task_under_cgroup · 68be98e0
    Daniel T. Lee authored
    Currently, 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.
    Signed-off-by: default avatarDaniel T. Lee <danieltimlee@gmail.com>
    Acked-by: default avatarYonghong Song <yhs@fb.com>
    Link: https://lore.kernel.org/r/20221218061453.6287-4-danieltimlee@gmail.comSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
    68be98e0
test_current_task_under_cgroup_user.c 2.42 KB