Skip to content

Commit 85c894a

Browse files
tlfalconacmel
authored andcommitted
perf header: Write bpf_prog (infos|btfs)_cnt to data file
With commit f0d0f97 ("perf header: Don't write empty BPF/BTF info"), the write_bpf_( prog_info() | btf() ) functions exit without writing anything if env->bpf_prog.(infos| btfs)_cnt is zero. process_bpf_( prog_info() | btf() ), however, still expect a "count" value to exist in the data file. If btf information is empty, for example, process_bpf_btf will read garbage or some other data as the number of btf nodes in the data file. As a result, the data file will not be processed correctly. Instead, write the count to the data file and exit if it is zero. Fixes: f0d0f97 ("perf header: Don't write empty BPF/BTF info") Reviewed-by: Ian Rogers <irogers@google.com> Signed-off-by: Thomas Falcon <thomas.falcon@intel.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 9b9e437 commit 85c894a

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

tools/perf/util/header.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,12 +1022,9 @@ static int write_bpf_prog_info(struct feat_fd *ff,
10221022

10231023
down_read(&env->bpf_progs.lock);
10241024

1025-
if (env->bpf_progs.infos_cnt == 0)
1026-
goto out;
1027-
10281025
ret = do_write(ff, &env->bpf_progs.infos_cnt,
10291026
sizeof(env->bpf_progs.infos_cnt));
1030-
if (ret < 0)
1027+
if (ret < 0 || env->bpf_progs.infos_cnt == 0)
10311028
goto out;
10321029

10331030
root = &env->bpf_progs.infos;
@@ -1067,13 +1064,10 @@ static int write_bpf_btf(struct feat_fd *ff,
10671064

10681065
down_read(&env->bpf_progs.lock);
10691066

1070-
if (env->bpf_progs.btfs_cnt == 0)
1071-
goto out;
1072-
10731067
ret = do_write(ff, &env->bpf_progs.btfs_cnt,
10741068
sizeof(env->bpf_progs.btfs_cnt));
10751069

1076-
if (ret < 0)
1070+
if (ret < 0 || env->bpf_progs.btfs_cnt == 0)
10771071
goto out;
10781072

10791073
root = &env->bpf_progs.btfs;

0 commit comments

Comments
 (0)