From 26c8fae22f543c2efc616c04722032d63695dabf Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Tue, 3 Feb 2004 18:46:33 -0800 Subject: [PATCH] [PATCH] oprofile per-cpu buffer overrun From: Philippe Elie In a ring buffer controlled by a read and write positions we can't use buffer_size but only buffer_size - 1 entry, the last free entry act as a guard to avoid write pos overrun. This bug was hidden because the writer, oprofile_add_sample(), request one more entry than really needed. --- drivers/oprofile/cpu_buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/oprofile/cpu_buffer.c b/drivers/oprofile/cpu_buffer.c index 1a57df385996d..23979d38dde76 100644 --- a/drivers/oprofile/cpu_buffer.c +++ b/drivers/oprofile/cpu_buffer.c @@ -86,9 +86,9 @@ static unsigned long nr_available_slots(struct oprofile_cpu_buffer const * b) unsigned long tail = b->tail_pos; if (tail > head) - return tail - head; + return (tail - head) - 1; - return tail + (b->buffer_size - head); + return tail + (b->buffer_size - head) - 1; } -- 2.53.0