mirror of
https://github.com/FEX-Emu/linux.git
synced 2025-01-30 15:43:30 +00:00
genalloc: use bitmap_find_next_zero_area
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
81f6527bd3
commit
243797f59b
@ -11,6 +11,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
|
#include <linux/bitmap.h>
|
||||||
#include <linux/genalloc.h>
|
#include <linux/genalloc.h>
|
||||||
|
|
||||||
|
|
||||||
@ -114,7 +115,7 @@ unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size)
|
|||||||
struct gen_pool_chunk *chunk;
|
struct gen_pool_chunk *chunk;
|
||||||
unsigned long addr, flags;
|
unsigned long addr, flags;
|
||||||
int order = pool->min_alloc_order;
|
int order = pool->min_alloc_order;
|
||||||
int nbits, bit, start_bit, end_bit;
|
int nbits, start_bit, end_bit;
|
||||||
|
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return 0;
|
return 0;
|
||||||
@ -129,29 +130,19 @@ unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size)
|
|||||||
end_bit -= nbits + 1;
|
end_bit -= nbits + 1;
|
||||||
|
|
||||||
spin_lock_irqsave(&chunk->lock, flags);
|
spin_lock_irqsave(&chunk->lock, flags);
|
||||||
bit = -1;
|
start_bit = bitmap_find_next_zero_area(chunk->bits, end_bit, 0,
|
||||||
while (bit + 1 < end_bit) {
|
nbits, 0);
|
||||||
bit = find_next_zero_bit(chunk->bits, end_bit, bit + 1);
|
if (start_bit >= end_bit) {
|
||||||
if (bit >= end_bit)
|
|
||||||
break;
|
|
||||||
|
|
||||||
start_bit = bit;
|
|
||||||
if (nbits > 1) {
|
|
||||||
bit = find_next_bit(chunk->bits, bit + nbits,
|
|
||||||
bit + 1);
|
|
||||||
if (bit - start_bit < nbits)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
addr = chunk->start_addr +
|
|
||||||
((unsigned long)start_bit << order);
|
|
||||||
while (nbits--)
|
|
||||||
__set_bit(start_bit++, chunk->bits);
|
|
||||||
spin_unlock_irqrestore(&chunk->lock, flags);
|
spin_unlock_irqrestore(&chunk->lock, flags);
|
||||||
read_unlock(&pool->lock);
|
continue;
|
||||||
return addr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addr = chunk->start_addr + ((unsigned long)start_bit << order);
|
||||||
|
|
||||||
|
bitmap_set(chunk->bits, start_bit, nbits);
|
||||||
spin_unlock_irqrestore(&chunk->lock, flags);
|
spin_unlock_irqrestore(&chunk->lock, flags);
|
||||||
|
read_unlock(&pool->lock);
|
||||||
|
return addr;
|
||||||
}
|
}
|
||||||
read_unlock(&pool->lock);
|
read_unlock(&pool->lock);
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user