diff --git a/lib/kfifo.c b/lib/kfifo.c index 307dae1..fa22feb 100644 --- a/lib/kfifo.c +++ b/lib/kfifo.c @@ -18,6 +18,7 @@ #include #include #include +#include /** * kfifo_init - allocates a new FIFO using a preallocated buffer @@ -49,6 +50,15 @@ unsigned char *buffer; struct kfifo *fifo; + /* + * round up to the next power of 2, since our 'let the indices + * wrap' tachnique works only in this case. + */ + if (size & (size - 1)) { + BUG_ON(size > 0x80000000); + size = roundup_pow_of_two(size); + } + buffer = malloc(size); if (!buffer) return NULL;