From: Matthieu CASTET Date: Fri, 9 Nov 2012 03:04:19 +0000 (+1100) Subject: dmapool: make DMAPOOL_DEBUG detect corruption of free marker X-Git-Tag: next-20121112~5^2~190 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=ba748dc82bfbd1d8b6b3a70e8f41a7476a6eb993;p=karo-tx-linux.git dmapool: make DMAPOOL_DEBUG detect corruption of free marker This can help to catch the case where hardware is writing after dma free. Signed-off-by: Matthieu Castet Signed-off-by: Andrew Morton --- diff --git a/mm/dmapool.c b/mm/dmapool.c index c5ab33bca0a8..e10898a08ca3 100644 --- a/mm/dmapool.c +++ b/mm/dmapool.c @@ -346,6 +346,29 @@ void *dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags, retval = offset + page->vaddr; *handle = offset + page->dma; #ifdef DMAPOOL_DEBUG + { + int i; + u8 *data = retval; + /* page->offset is stored in first 4 bytes */ + for (i = sizeof(int); i < pool->size; i++) { + if (data[i] != POOL_POISON_FREED) { + if (pool->dev) + dev_err(pool->dev, + "dma_pool_alloc %s, %p (corruped)\n", + pool->name, retval); + else + printk(KERN_ERR + "dma_pool_alloc %s, %p (corruped)\n", + pool->name, retval); + + /* we dump the first 4 bytes even if there are not + POOL_POISON_FREED */ + print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, + data, pool->size, 1); + break; + } + } + } memset(retval, POOL_POISON_ALLOCATED, pool->size); #endif done: