X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fgenalloc.c;h=f6d276db2d58f97c80db2b0aececde84120893a9;hb=1adcd8bee37f494e22aee856467e994ae086ae45;hp=7d16ecabba9620cf0800802d35a4c62f02a62ba2;hpb=322acc96d4bd3debea11cd0160b18bd5d7ff0d73;p=linux-2.6 diff --git a/lib/genalloc.c b/lib/genalloc.c index 7d16ecabba..f6d276db2d 100644 --- a/lib/genalloc.c +++ b/lib/genalloc.c @@ -14,11 +14,13 @@ #include -/* - * Create a new special memory pool. - * +/** + * gen_pool_create - create a new special memory pool * @min_alloc_order: log base 2 of number of bytes each bitmap bit represents * @nid: node id of the node the pool structure should be allocated on, or -1 + * + * Create a new special memory pool that can be used to manage special purpose + * memory not managed by the regular kmalloc/kfree interface. */ struct gen_pool *gen_pool_create(int min_alloc_order, int nid) { @@ -34,15 +36,15 @@ struct gen_pool *gen_pool_create(int min_alloc_order, int nid) } EXPORT_SYMBOL(gen_pool_create); - -/* - * Add a new chunk of memory to the specified pool. - * +/** + * gen_pool_add - add a new chunk of special memory to the pool * @pool: pool to add new memory chunk to * @addr: starting address of memory chunk to add to pool * @size: size in bytes of the memory chunk to add to pool * @nid: node id of the node the chunk structure and bitmap should be * allocated on, or -1 + * + * Add a new chunk of special memory to the specified pool. */ int gen_pool_add(struct gen_pool *pool, unsigned long addr, size_t size, int nid) @@ -52,11 +54,10 @@ int gen_pool_add(struct gen_pool *pool, unsigned long addr, size_t size, int nbytes = sizeof(struct gen_pool_chunk) + (nbits + BITS_PER_BYTE - 1) / BITS_PER_BYTE; - chunk = kmalloc_node(nbytes, GFP_KERNEL, nid); + chunk = kmalloc_node(nbytes, GFP_KERNEL | __GFP_ZERO, nid); if (unlikely(chunk == NULL)) return -1; - memset(chunk, 0, nbytes); spin_lock_init(&chunk->lock); chunk->start_addr = addr; chunk->end_addr = addr + size; @@ -69,11 +70,12 @@ int gen_pool_add(struct gen_pool *pool, unsigned long addr, size_t size, } EXPORT_SYMBOL(gen_pool_add); - -/* - * Destroy a memory pool. Verifies that there are no outstanding allocations. - * +/** + * gen_pool_destroy - destroy a special memory pool * @pool: pool to destroy + * + * Destroy the specified special memory pool. Verifies that there are no + * outstanding allocations. */ void gen_pool_destroy(struct gen_pool *pool) { @@ -99,13 +101,13 @@ void gen_pool_destroy(struct gen_pool *pool) } EXPORT_SYMBOL(gen_pool_destroy); - -/* - * Allocate the requested number of bytes from the specified pool. - * Uses a first-fit algorithm. - * +/** + * gen_pool_alloc - allocate special memory from the pool * @pool: pool to allocate from * @size: number of bytes to allocate from the pool + * + * Allocate the requested number of bytes from the specified pool. + * Uses a first-fit algorithm. */ unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size) { @@ -145,7 +147,7 @@ unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size) addr = chunk->start_addr + ((unsigned long)start_bit << order); while (nbits--) - __set_bit(start_bit++, &chunk->bits); + __set_bit(start_bit++, chunk->bits); spin_unlock_irqrestore(&chunk->lock, flags); read_unlock(&pool->lock); return addr; @@ -157,13 +159,13 @@ unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size) } EXPORT_SYMBOL(gen_pool_alloc); - -/* - * Free the specified memory back to the specified pool. - * +/** + * gen_pool_free - free allocated special memory back to the pool * @pool: pool to free to * @addr: starting address of memory to free back to pool * @size: size in bytes of memory to free + * + * Free previously allocated special memory back to the specified pool. */ void gen_pool_free(struct gen_pool *pool, unsigned long addr, size_t size) { @@ -184,7 +186,7 @@ void gen_pool_free(struct gen_pool *pool, unsigned long addr, size_t size) spin_lock_irqsave(&chunk->lock, flags); bit = (addr - chunk->start_addr) >> order; while (nbits--) - __clear_bit(bit++, &chunk->bits); + __clear_bit(bit++, chunk->bits); spin_unlock_irqrestore(&chunk->lock, flags); break; }