Skip to content
Snippets Groups Projects
Commit 261df640 authored by Jerome Marchand's avatar Jerome Marchand
Browse files

bpftool: Fix a bug in subskeleton code generation

Bugzilla: https://bugzilla.redhat.com/2120966



commit f97b8b9b
Author: Yonghong Song <yhs@fb.com>
Date:   Sat Mar 19 20:20:09 2022 -0700

    bpftool: Fix a bug in subskeleton code generation

    Compiled with clang by adding LLVM=1 both kernel and selftests/bpf
    build, I hit the following compilation error:

    In file included from /.../tools/testing/selftests/bpf/prog_tests/subskeleton.c:6:
      ./test_subskeleton_lib.subskel.h:168:6: error: variable 'err' is used uninitialized whenever
          'if' condition is true [-Werror,-Wsometimes-uninitialized]
              if (!s->progs)
                  ^~~~~~~~~
      ./test_subskeleton_lib.subskel.h:181:11: note: uninitialized use occurs here
              errno = -err;
                       ^~~
      ./test_subskeleton_lib.subskel.h:168:2: note: remove the 'if' if its condition is always false
              if (!s->progs)
              ^~~~~~~~~~~~~~

    The compilation error is triggered by the following code
            ...
            int err;

            obj = (struct test_subskeleton_lib *)calloc(1, sizeof(*obj));
            if (!obj) {
                    errno = ENOMEM;
                    goto err;
            }
            ...

      err:
            test_subskeleton_lib__destroy(obj);
            errno = -err;
            ...
    in test_subskeleton_lib__open(). The 'err' is not initialized, yet it
    is used in 'errno = -err' later.

    The fix is to remove 'errno = -err' since errno has been set properly
    in all incoming branches.

    Fixes: 00389c58 ("bpftool: Add support for subskeletons")
Signed-off-by: default avatarYonghong Song <yhs@fb.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Link: https://lore.kernel.org/bpf/20220320032009.3106133-1-yhs@fb.com



Signed-off-by: default avatarJerome Marchand <jmarchan@redhat.com>
parent d4f3e612
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment