Commit d23a6dbc authored by Peter Zijlstra's avatar Peter Zijlstra
Browse files

perf: Use scoped_guard() for mmap_mutex in perf_mmap()

parent 5d299897
Loading
Loading
Loading
Loading
+14 −21
Original line number Diff line number Diff line
@@ -7146,29 +7146,22 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
	if (vma_size != PAGE_SIZE * nr_pages)
		return -EINVAL;

	mutex_lock(&event->mmap_mutex);
	ret = -EINVAL;

	scoped_guard (mutex, &event->mmap_mutex) {
		/*
		 * This relies on __pmu_detach_event() taking mmap_mutex after marking
		 * the event REVOKED. Either we observe the state, or __pmu_detach_event()
		 * will detach the rb created here.
		 */
	if (event->state <= PERF_EVENT_STATE_REVOKED) {
		ret = -ENODEV;
		goto unlock;
	}
		if (event->state <= PERF_EVENT_STATE_REVOKED)
			return -ENODEV;

		if (vma->vm_pgoff == 0)
			ret = perf_mmap_rb(vma, event, nr_pages);
		else
			ret = perf_mmap_aux(vma, event, nr_pages);

unlock:
	mutex_unlock(&event->mmap_mutex);

		if (ret)
			return ret;
	}

	/*
	 * Since pinned accounting is per vm we cannot allow fork() to copy our