bpftool icon indicating copy to clipboard operation
bpftool copied to clipboard

Smatch: missing error code in do_loader()

Open qmonnet opened this issue 1 year ago • 0 comments

Commit d510296d331a ("bpftool: Use syscall/loader program in "prog
load" and "gen skeleton" command.") from May 13, 2021 (linux-next),
leads to the following Smatch static checker warning:

	./tools/bpf/bpftool/prog.c:1925 do_loader()
	warn: missing error code here? 'bpf_object__open_file()' failed. 'err' = '0'

./tools/bpf/bpftool/prog.c
    1906 static int do_loader(int argc, char **argv)
    1907 {
    1908         DECLARE_LIBBPF_OPTS(bpf_object_open_opts, open_opts);
    1909         DECLARE_LIBBPF_OPTS(gen_loader_opts, gen);
    1910         struct bpf_object *obj;
    1911         const char *file;
    1912         int err = 0;
    1913 
    1914         if (!REQ_ARGS(1))
    1915                 return -1;
    1916         file = GET_ARG();
    1917 
    1918         if (verifier_logs)
    1919                 /* log_level1 + log_level2 + stats, but not stable UAPI */
    1920                 open_opts.kernel_log_level = 1 + 2 + 4;
    1921 
    1922         obj = bpf_object__open_file(file, &open_opts);
    1923         if (!obj) {
    1924                 p_err("failed to open object file");
--> 1925                 goto err_close_obj;

set the error code?

    1926         }
    1927 
    1928         err = bpf_object__gen_loader(obj, &gen);
    1929         if (err)
    1930                 goto err_close_obj;
    1931 
    1932         err = bpf_object__load(obj);
    1933         if (err) {
    1934                 p_err("failed to load object file");
    1935                 goto err_close_obj;
    1936         }
    1937 
    1938         if (verifier_logs) {
    1939                 struct dump_data dd = {};
    1940 
    1941                 kernel_syms_load(&dd);
    1942                 dump_xlated_plain(&dd, (void *)gen.insns, gen.insns_sz, false, false);
    1943                 kernel_syms_destroy(&dd);
    1944         }
    1945         err = try_loader(&gen);
    1946 err_close_obj:
    1947         bpf_object__close(obj);
    1948         return err;
    1949 }

https://lore.kernel.org/bpf/[email protected]/t/#u

qmonnet avatar Sep 02 '24 21:09 qmonnet