]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
dmapool: make DMAPOOL_DEBUG detect corruption of free marker
authorMatthieu CASTET <matthieu.castet@parrot.com>
Thu, 15 Nov 2012 02:37:36 +0000 (13:37 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 15 Nov 2012 06:25:40 +0000 (17:25 +1100)
This can help to catch the case where hardware is writing after dma free.

Signed-off-by: Matthieu Castet <matthieu.castet@parrot.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/dmapool.c

index 86de9b2ac3e1ca828e4ba68eec0c553897060980..c2741da05a05eaa09378d2d5a64204526c77e2dd 100644 (file)
@@ -334,6 +334,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
        spin_unlock_irqrestore(&pool->lock, flags);