Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smatch: missing error code in do_loader() #156

Open
qmonnet opened this issue Sep 2, 2024 · 0 comments
Open

Smatch: missing error code in do_loader() #156

qmonnet opened this issue Sep 2, 2024 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@qmonnet
Copy link
Member

qmonnet commented Sep 2, 2024

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/d3b5b4b4-19bb-4619-b4dd-86c958c4a367@stanley.mountain/t/#u

@qmonnet qmonnet added bug Something isn't working good first issue Good for newcomers labels Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant