Skip to content

Commit

Permalink
kfifo: fix kfifo_alloc() and kfifo_init()
Browse files Browse the repository at this point in the history
Fix kfifo_alloc() and kfifo_init() to alloc at least the requested number
of elements.  Since the kfifo operates on power of 2 the request size will
be rounded up to the next power of two.

Signed-off-by: Stefani Seibold <stefani@seibold.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
sstefani authored and torvalds committed Feb 28, 2013
1 parent c759b35 commit dfe2a77
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/kfifo.c
Expand Up @@ -42,8 +42,7 @@ int __kfifo_alloc(struct __kfifo *fifo, unsigned int size,
* round down to the next power of 2, since our 'let the indices * round down to the next power of 2, since our 'let the indices
* wrap' technique works only in this case. * wrap' technique works only in this case.
*/ */
if (!is_power_of_2(size)) size = roundup_pow_of_two(size);
size = rounddown_pow_of_two(size);


fifo->in = 0; fifo->in = 0;
fifo->out = 0; fifo->out = 0;
Expand Down Expand Up @@ -83,8 +82,7 @@ int __kfifo_init(struct __kfifo *fifo, void *buffer,
{ {
size /= esize; size /= esize;


if (!is_power_of_2(size)) size = roundup_pow_of_two(size);
size = rounddown_pow_of_two(size);


fifo->in = 0; fifo->in = 0;
fifo->out = 0; fifo->out = 0;
Expand Down

0 comments on commit dfe2a77

Please sign in to comment.