summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorHao Ge <gehao@kylinos.cn>2024-08-20 10:36:22 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-10-04 16:32:56 +0200
commita700b2390bfafd79b7f7b115e8808ba95ebae32f (patch)
tree7c5f1bbb4817a7e31d49a7d3439b54099635913b /tools
parent584cd3ff792e1edbea20b2a7df55897159b0be3e (diff)
downloadlinux-a700b2390bfafd79b7f7b115e8808ba95ebae32f.tar.gz
linux-a700b2390bfafd79b7f7b115e8808ba95ebae32f.tar.bz2
linux-a700b2390bfafd79b7f7b115e8808ba95ebae32f.zip
selftests/bpf: Fix incorrect parameters in NULL pointer checking
[ Upstream commit c264487e5410e5a72db8a414566ab7d144223e6c ] 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 b23ed4d74c4d ("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 <dan.carpenter@linaro.org> Closes: https://lore.kernel.org/all/1eb3732f-605a-479d-ba64-cd14250cbf91@stanley.mountain/ Fixes: b4b7a4099b8c ("selftests/bpf: Factor out get_xlated_program() helper") Signed-off-by: Hao Ge <gehao@kylinos.cn> Link: https://lore.kernel.org/r/20240820023622.29190-1-hao.ge@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/bpf/testing_helpers.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/testing/selftests/bpf/testing_helpers.c b/tools/testing/selftests/bpf/testing_helpers.c
index 4230420ef294..680e452583a7 100644
--- a/tools/testing/selftests/bpf/testing_helpers.c
+++ b/tools/testing/selftests/bpf/testing_helpers.c
@@ -451,7 +451,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;
}