Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: Add malloc failure checks in bpf_iter

Since some malloc calls in bpf_iter may at times fail,
this patch adds the appropriate fail checks, and ensures that
any previously allocated resource is appropriately destroyed
before returning the function.

Signed-off-by: Yuran Pereira <yuran.pereira@hotmail.com>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Acked-by: Kui-Feng Lee <thinker.li@gmail.com>
Link: https://lore.kernel.org/r/DB3PR10MB6835F0ECA792265FA41FC39BE8A3A@DB3PR10MB6835.EURPRD10.PROD.OUTLOOK.COM
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Yuran Pereira and committed by
Alexei Starovoitov
bf4a64b9 fac85c29

+5 -1
+5 -1
tools/testing/selftests/bpf/prog_tests/bpf_iter.c
··· 698 698 goto free_link; 699 699 700 700 buf = malloc(expected_read_len); 701 - if (!buf) 701 + if (!ASSERT_OK_PTR(buf, "malloc")) 702 702 goto close_iter; 703 703 704 704 /* do read */ ··· 868 868 869 869 skel->rodata->num_cpus = bpf_num_possible_cpus(); 870 870 val = malloc(8 * bpf_num_possible_cpus()); 871 + if (!ASSERT_OK_PTR(val, "malloc")) 872 + goto out; 871 873 872 874 err = bpf_iter_bpf_percpu_hash_map__load(skel); 873 875 if (!ASSERT_OK_PTR(skel, "bpf_iter_bpf_percpu_hash_map__load")) ··· 1046 1044 1047 1045 skel->rodata->num_cpus = bpf_num_possible_cpus(); 1048 1046 val = malloc(8 * bpf_num_possible_cpus()); 1047 + if (!ASSERT_OK_PTR(val, "malloc")) 1048 + goto out; 1049 1049 1050 1050 err = bpf_iter_bpf_percpu_array_map__load(skel); 1051 1051 if (!ASSERT_OK_PTR(skel, "bpf_iter_bpf_percpu_array_map__load"))