Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 176762
b: refs/heads/master
c: 243797f
h: refs/heads/master
v: v3
  • Loading branch information
Akinobu Mita authored and Linus Torvalds committed Dec 16, 2009
1 parent 2e4d189 commit 4477d63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 81f6527bd322ef1f3a58c2c438b9ded3bd8f606a
refs/heads/master: 243797f59b748f679ab88d456fcc4f92236d724b
33 changes: 12 additions & 21 deletions trunk/lib/genalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

#include <linux/module.h>
#include <linux/bitmap.h>
#include <linux/genalloc.h>


Expand Down Expand Up @@ -114,7 +115,7 @@ unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size)
struct gen_pool_chunk *chunk;
unsigned long addr, flags;
int order = pool->min_alloc_order;
int nbits, bit, start_bit, end_bit;
int nbits, start_bit, end_bit;

if (size == 0)
return 0;
Expand All @@ -129,29 +130,19 @@ unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size)
end_bit -= nbits + 1;

spin_lock_irqsave(&chunk->lock, flags);
bit = -1;
while (bit + 1 < end_bit) {
bit = find_next_zero_bit(chunk->bits, end_bit, bit + 1);
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);
start_bit = bitmap_find_next_zero_area(chunk->bits, end_bit, 0,
nbits, 0);
if (start_bit >= end_bit) {
spin_unlock_irqrestore(&chunk->lock, flags);
read_unlock(&pool->lock);
return addr;
continue;
}

addr = chunk->start_addr + ((unsigned long)start_bit << order);

bitmap_set(chunk->bits, start_bit, nbits);
spin_unlock_irqrestore(&chunk->lock, flags);
read_unlock(&pool->lock);
return addr;
}
read_unlock(&pool->lock);
return 0;
Expand Down

0 comments on commit 4477d63

Please sign in to comment.