selftests: bpf: initialize bpf_object pointers where needed

There are a few tests which call bpf_object__close on uninitialized
bpf_object*, which may segfault. Explicitly zero-initialise these pointers
to avoid this.

Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Lorenz Bauer 2019-05-08 17:49:32 +01:00 committed by Alexei Starovoitov
parent 494bc1d281
commit 07b619919d
3 changed files with 5 additions and 2 deletions

View File

@ -15,7 +15,7 @@ static int libbpf_debug_print(enum libbpf_print_level level,
static int check_load(const char *file) static int check_load(const char *file)
{ {
struct bpf_prog_load_attr attr; struct bpf_prog_load_attr attr;
struct bpf_object *obj; struct bpf_object *obj = NULL;
int err, prog_fd; int err, prog_fd;
memset(&attr, 0, sizeof(struct bpf_prog_load_attr)); memset(&attr, 0, sizeof(struct bpf_prog_load_attr));

View File

@ -9,7 +9,7 @@ static void test_task_fd_query_tp_core(const char *probe_name,
struct perf_event_attr attr = {}; struct perf_event_attr attr = {};
__u64 probe_offset, probe_addr; __u64 probe_offset, probe_addr;
__u32 len, prog_id, fd_type; __u32 len, prog_id, fd_type;
struct bpf_object *obj; struct bpf_object *obj = NULL;
__u32 duration = 0; __u32 duration = 0;
char buf[256]; char buf[256];

View File

@ -13,6 +13,9 @@ void test_tp_attach_query(void)
struct bpf_prog_info prog_info; struct bpf_prog_info prog_info;
char buf[256]; char buf[256];
for (i = 0; i < num_progs; i++)
obj[i] = NULL;
snprintf(buf, sizeof(buf), snprintf(buf, sizeof(buf),
"/sys/kernel/debug/tracing/events/sched/sched_switch/id"); "/sys/kernel/debug/tracing/events/sched/sched_switch/id");
efd = open(buf, O_RDONLY, 0); efd = open(buf, O_RDONLY, 0);