Commit dfe2a77fd243ac3bf204fd0624e4d0b2134aaa6d
Committed by
Linus Torvalds
1 parent
c759b35e64
Exists in
master
and in
20 other branches
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>
Showing 1 changed file with 2 additions and 4 deletions Side-by-side Diff
lib/kfifo.c
... | ... | @@ -42,8 +42,7 @@ |
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; |
... | ... | @@ -83,8 +82,7 @@ |
83 | 82 | { |
84 | 83 | size /= esize; |
85 | 84 | |
86 | - if (!is_power_of_2(size)) | |
87 | - size = rounddown_pow_of_two(size); | |
85 | + size = roundup_pow_of_two(size); | |
88 | 86 | |
89 | 87 | fifo->in = 0; |
90 | 88 | fifo->out = 0; |