X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fbase%2Fdmapool.c;h=f95d502772740d9fa653379f185e002742d9abf4;hb=97bf2856c6014879bd04983a3e9dfcdac1e7fe85;hp=bbbf06643be8541bfbe3c23e932dab7256d0df6e;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/drivers/base/dmapool.c b/drivers/base/dmapool.c index bbbf06643..f95d50277 100644 --- a/drivers/base/dmapool.c +++ b/drivers/base/dmapool.c @@ -7,6 +7,7 @@ #include #include #include +#include /* * Pool allocator ... wraps the dma_alloc_coherent page allocator, so @@ -35,13 +36,11 @@ struct dma_page { /* cacheable header for 'allocation' bytes */ }; #define POOL_TIMEOUT_JIFFIES ((100 /* msec */ * HZ) / 1000) -#define POOL_POISON_FREED 0xa7 /* !inuse */ -#define POOL_POISON_ALLOCATED 0xa9 /* !initted */ static DECLARE_MUTEX (pools_lock); static ssize_t -show_pools (struct device *dev, char *buf) +show_pools (struct device *dev, struct device_attribute *attr, char *buf) { unsigned temp; unsigned size; @@ -110,7 +109,7 @@ dma_pool_create (const char *name, struct device *dev, if (align == 0) align = 1; if (size == 0) - return 0; + return NULL; else if (size < align) size = align; else if ((size % align) != 0) { @@ -125,9 +124,9 @@ dma_pool_create (const char *name, struct device *dev, allocation = PAGE_SIZE; // FIXME: round up for less fragmentation } else if (allocation < size) - return 0; + return NULL; - if (!(retval = kmalloc (sizeof *retval, SLAB_KERNEL))) + if (!(retval = kmalloc (sizeof *retval, GFP_KERNEL))) return retval; strlcpy (retval->name, name, sizeof retval->name); @@ -142,11 +141,20 @@ dma_pool_create (const char *name, struct device *dev, init_waitqueue_head (&retval->waitq); if (dev) { + int ret; + down (&pools_lock); if (list_empty (&dev->dma_pools)) - device_create_file (dev, &dev_attr_pools); + ret = device_create_file (dev, &dev_attr_pools); + else + ret = 0; /* note: not currently insisting "name" be unique */ - list_add (&retval->pools, &dev->dma_pools); + if (!ret) + list_add (&retval->pools, &dev->dma_pools); + else { + kfree(retval); + retval = NULL; + } up (&pools_lock); } else INIT_LIST_HEAD (&retval->pools); @@ -156,7 +164,7 @@ dma_pool_create (const char *name, struct device *dev, static struct dma_page * -pool_alloc_page (struct dma_pool *pool, int mem_flags) +pool_alloc_page (struct dma_pool *pool, gfp_t mem_flags) { struct dma_page *page; int mapsize; @@ -165,9 +173,9 @@ pool_alloc_page (struct dma_pool *pool, int mem_flags) mapsize = (mapsize + BITS_PER_LONG - 1) / BITS_PER_LONG; mapsize *= sizeof (long); - page = (struct dma_page *) kmalloc (mapsize + sizeof *page, mem_flags); + page = kmalloc(mapsize + sizeof *page, mem_flags); if (!page) - return 0; + return NULL; page->vaddr = dma_alloc_coherent (pool->dev, pool->allocation, &page->dma, @@ -181,7 +189,7 @@ pool_alloc_page (struct dma_pool *pool, int mem_flags) page->in_use = 0; } else { kfree (page); - page = 0; + page = NULL; } return page; } @@ -262,7 +270,7 @@ dma_pool_destroy (struct dma_pool *pool) * If such a memory block can't be allocated, null is returned. */ void * -dma_pool_alloc (struct dma_pool *pool, int mem_flags, dma_addr_t *handle) +dma_pool_alloc (struct dma_pool *pool, gfp_t mem_flags, dma_addr_t *handle) { unsigned long flags; struct dma_page *page; @@ -289,7 +297,7 @@ restart: } } } - if (!(page = pool_alloc_page (pool, SLAB_ATOMIC))) { + if (!(page = pool_alloc_page (pool, GFP_ATOMIC))) { if (mem_flags & __GFP_WAIT) { DECLARE_WAITQUEUE (wait, current); @@ -302,7 +310,7 @@ restart: remove_wait_queue (&pool->waitq, &wait); goto restart; } - retval = 0; + retval = NULL; goto done; } @@ -334,7 +342,7 @@ pool_find_page (struct dma_pool *pool, dma_addr_t dma) if (dma < (page->dma + pool->allocation)) goto done; } - page = 0; + page = NULL; done: spin_unlock_irqrestore (&pool->lock, flags); return page;