Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kfifo: fix kfifo_alloc() and kfifo_init()

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>

authored by

Stefani Seibold and committed by
Linus Torvalds
dfe2a77f c759b35e

+2 -4
+2 -4
lib/kfifo.c
··· 42 42 * round down to the next power of 2, since our 'let the indices 43 43 * wrap' technique works only in this case. 44 44 */ 45 - if (!is_power_of_2(size)) 46 - size = rounddown_pow_of_two(size); 45 + size = roundup_pow_of_two(size); 47 46 48 47 fifo->in = 0; 49 48 fifo->out = 0; ··· 82 83 { 83 84 size /= esize; 84 85 85 - if (!is_power_of_2(size)) 86 - size = rounddown_pow_of_two(size); 86 + size = roundup_pow_of_two(size); 87 87 88 88 fifo->in = 0; 89 89 fifo->out = 0;