Commit c264487e authored by Hao Ge's avatar Hao Ge Committed by Alexei Starovoitov
Browse files

selftests/bpf: Fix incorrect parameters in NULL pointer checking



Smatch reported the following warning:
    ./tools/testing/selftests/bpf/testing_helpers.c:455 get_xlated_program()
    warn: variable dereferenced before check 'buf' (see line 454)

It seems correct,so let's modify it based on it's suggestion.

Actually,commit b23ed4d7 ("selftests/bpf: Fix invalid pointer
check in get_xlated_program()") fixed an issue in the test_verifier.c
once,but it was reverted this time.

Let's solve this issue with the minimal changes possible.

Reported-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/all/1eb3732f-605a-479d-ba64-cd14250cbf91@stanley.mountain/


Fixes: b4b7a409 ("selftests/bpf: Factor out get_xlated_program() helper")
Signed-off-by: default avatarHao Ge <gehao@kylinos.cn>
Link: https://lore.kernel.org/r/20240820023622.29190-1-hao.ge@linux.dev


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 4961d8f4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -452,7 +452,7 @@ int get_xlated_program(int fd_prog, struct bpf_insn **buf, __u32 *cnt)

	*cnt = xlated_prog_len / buf_element_size;
	*buf = calloc(*cnt, buf_element_size);
	if (!buf) {
	if (!*buf) {
		perror("can't allocate xlated program buffer");
		return -ENOMEM;
	}