Skip to content

Commit 07091aa

Browse files
committed
perf/core: Exit early on perf_mmap() fail
When perf_mmap() fails to allocate a buffer, it still invokes the event_mapped() callback of the related event. On X86 this might increase the perf_rdpmc_allowed reference counter. But nothing undoes this as perf_mmap_close() is never called in this case, which causes another reference count leak. Return early on failure to prevent that. Fixes: 1e0fb9e ("perf: Add pmu callbacks to track event mapping and unmapping") Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Lorenzo Stoakes <[email protected]> Cc: [email protected]
1 parent 5468c0f commit 07091aa

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

kernel/events/core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7138,15 +7138,17 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
71387138
mutex_unlock(aux_mutex);
71397139
mutex_unlock(&event->mmap_mutex);
71407140

7141+
if (ret)
7142+
return ret;
7143+
71417144
/*
71427145
* Since pinned accounting is per vm we cannot allow fork() to copy our
71437146
* vma.
71447147
*/
71457148
vm_flags_set(vma, VM_DONTCOPY | VM_DONTEXPAND | VM_DONTDUMP);
71467149
vma->vm_ops = &perf_mmap_vmops;
71477150

7148-
if (!ret)
7149-
ret = map_range(rb, vma);
7151+
ret = map_range(rb, vma);
71507152

71517153
mapped = get_mapped(event, event_mapped);
71527154
if (mapped)

0 commit comments

Comments
 (0)