Skip to content

Commit 3ca83e3

Browse files
GeHao01994gregkh
authored andcommitted
selftests/bpf: Fix incorrect parameters in NULL pointer checking
[ Upstream commit c264487 ] 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 b23ed4d ("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: Dan Carpenter <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Fixes: b4b7a40 ("selftests/bpf: Factor out get_xlated_program() helper") Signed-off-by: Hao Ge <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent e7e9c5b commit 3ca83e3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/testing/selftests/bpf/testing_helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ int get_xlated_program(int fd_prog, struct bpf_insn **buf, __u32 *cnt)
451451

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

0 commit comments

Comments
 (0)