Skip to content

Commit e10e4ef

Browse files
WangNan0acmel
authored andcommitted
perf evlist: Check 'base' pointer before checking refcnt when put a mmap
evlist->mmap[i]->refcnt could be 0 if an evlist has no evsel or if all evsels don't match the evlist during mmap. For example, when all evsels are overwritable but the evlist itself is normal. To avoid crashing, perf should check 'base' pointer before checking refcnt, and raise bug only when base is not NULL. Signed-off-by: Wang Nan <[email protected]> Cc: He Kuang <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Zefan Li <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] [ Renamed 'mmap' variable, it is reserved in old distros such as Ubuntu 12.04, breaking the build ] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent f3058a1 commit e10e4ef

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tools/perf/util/evlist.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,11 @@ static void perf_evlist__mmap_get(struct perf_evlist *evlist, int idx)
856856

857857
static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx)
858858
{
859-
BUG_ON(atomic_read(&evlist->mmap[idx].refcnt) == 0);
859+
struct perf_mmap *md = &evlist->mmap[idx];
860+
861+
BUG_ON(md->base && atomic_read(&md->refcnt) == 0);
860862

861-
if (atomic_dec_and_test(&evlist->mmap[idx].refcnt))
863+
if (atomic_dec_and_test(&md->refcnt))
862864
__perf_evlist__munmap(evlist, idx);
863865
}
864866

0 commit comments

Comments
 (0)