diff options
author | Matthieu CASTET <matthieu.castet@parrot.com> | 2012-12-11 19:01:31 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-12-11 20:22:24 -0500 |
commit | 5de55b265a13bc263c823bbe05d87d2c5e785f6f (patch) | |
tree | 69082ec836d553c98b99e6a0f3aebe2649b4fad2 /mm/dmapool.c | |
parent | 9ff4868e3051d9128a24dd330bed32011a11421d (diff) |
dmapool: make DMAPOOL_DEBUG detect corruption of free marker
This can help to catch the case where hardware is writing after dma free.
[akpm@linux-foundation.org: tidy code, fix comment, use sizeof(page->offset), use pr_err()]
Signed-off-by: Matthieu Castet <matthieu.castet@parrot.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/dmapool.c')
-rw-r--r-- | mm/dmapool.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/mm/dmapool.c b/mm/dmapool.c index da1b0f0b8709..c69781e97cf9 100644 --- a/mm/dmapool.c +++ b/mm/dmapool.c | |||
@@ -332,6 +332,30 @@ void *dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags, | |||
332 | retval = offset + page->vaddr; | 332 | retval = offset + page->vaddr; |
333 | *handle = offset + page->dma; | 333 | *handle = offset + page->dma; |
334 | #ifdef DMAPOOL_DEBUG | 334 | #ifdef DMAPOOL_DEBUG |
335 | { | ||
336 | int i; | ||
337 | u8 *data = retval; | ||
338 | /* page->offset is stored in first 4 bytes */ | ||
339 | for (i = sizeof(page->offset); i < pool->size; i++) { | ||
340 | if (data[i] == POOL_POISON_FREED) | ||
341 | continue; | ||
342 | if (pool->dev) | ||
343 | dev_err(pool->dev, | ||
344 | "dma_pool_alloc %s, %p (corruped)\n", | ||
345 | pool->name, retval); | ||
346 | else | ||
347 | pr_err("dma_pool_alloc %s, %p (corruped)\n", | ||
348 | pool->name, retval); | ||
349 | |||
350 | /* | ||
351 | * Dump the first 4 bytes even if they are not | ||
352 | * POOL_POISON_FREED | ||
353 | */ | ||
354 | print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, | ||
355 | data, pool->size, 1); | ||
356 | break; | ||
357 | } | ||
358 | } | ||
335 | memset(retval, POOL_POISON_ALLOCATED, pool->size); | 359 | memset(retval, POOL_POISON_ALLOCATED, pool->size); |
336 | #endif | 360 | #endif |
337 | spin_unlock_irqrestore(&pool->lock, flags); | 361 | spin_unlock_irqrestore(&pool->lock, flags); |