Skip to content

Commit

Permalink
dmapool: make DMAPOOL_DEBUG detect corruption of free marker
Browse files Browse the repository at this point in the history
This can help to catch the case where hardware is writing after dma free.

[[email protected]: tidy code, fix comment, use sizeof(page->offset), use pr_err()]
Signed-off-by: Matthieu Castet <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Matthieu CASTET authored and torvalds committed Dec 12, 2012
1 parent 9ff4868 commit 5de55b2
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions mm/dmapool.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,30 @@ 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(page->offset); i < pool->size; i++) {
if (data[i] == POOL_POISON_FREED)
continue;
if (pool->dev)
dev_err(pool->dev,
"dma_pool_alloc %s, %p (corruped)\n",
pool->name, retval);
else
pr_err("dma_pool_alloc %s, %p (corruped)\n",
pool->name, retval);

/*
* Dump the first 4 bytes even if they 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);
Expand Down

0 comments on commit 5de55b2

Please sign in to comment.