[PATCH] oprofile per-cpu buffer overrun

From: Philippe Elie
Date: Sun Jan 25 2004 - 20:23:15 EST


Hi Andrew,

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.

regards,
Phil

Index: drivers/oprofile/cpu_buffer.c
===================================================================
RCS file: /usr/local/cvsroot/linux-2.5/drivers/oprofile/cpu_buffer.c,v
retrieving revision 1.9
diff -u -p -r1.9 cpu_buffer.c
--- drivers/oprofile/cpu_buffer.c 26 May 2003 04:42:54 -0000 1.9
+++ drivers/oprofile/cpu_buffer.c 24 Jan 2004 21:07:03 -0000
@@ -86,9 +86,9 @@ static unsigned long nr_available_slots(
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;
}


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/