Skip to content

Commit

Permalink
perf_counter: sanity check on the output API
Browse files Browse the repository at this point in the history
Ensure we never write more than we said we would.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Arjan van de Ven <arjan@infradead.org>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Orig-LKML-Reference: <20090325113316.921433024@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Apr 6, 2009
1 parent 5c14819 commit 63e35b2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions kernel/perf_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,7 @@ struct perf_output_handle {
struct perf_counter *counter;
struct perf_mmap_data *data;
unsigned int offset;
unsigned int head;
int wakeup;
};

Expand All @@ -1447,6 +1448,7 @@ static int perf_output_begin(struct perf_output_handle *handle,
handle->counter = counter;
handle->data = data;
handle->offset = offset;
handle->head = head;
handle->wakeup = (offset >> PAGE_SHIFT) != (head >> PAGE_SHIFT);

return 0;
Expand Down Expand Up @@ -1485,6 +1487,8 @@ static void perf_output_copy(struct perf_output_handle *handle,
} while (len);

handle->offset = offset;

WARN_ON_ONCE(handle->offset > handle->head);
}

#define perf_output_put(handle, x) \
Expand Down

0 comments on commit 63e35b2

Please sign in to comment.