mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matthieu CASTET <matthieu.castet@parrot.com>
To: linux-kernel@vger.kernel.org
Cc: cl@linux.com, akpm@linux-foundation.org,
	Matthieu CASTET <matthieu.castet@parrot.com>
Subject: [PATCH] dmapool : make DMAPOOL_DEBUG detect corruption of free marker
Date: Mon,  5 Nov 2012 14:40:05 +0100	[thread overview]
Message-ID: <1352122805-30099-1-git-send-email-matthieu.castet@parrot.com> (raw)

This can help to catch case where hardware is writting after dma free.

Signed-off-by: Matthieu Castet <matthieu.castet@parrot.com>
---
 mm/dmapool.c |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/mm/dmapool.c b/mm/dmapool.c
index c5ab33b..e10898a 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:
-- 
1.7.10.4


             reply	other threads:[~2012-11-05 13:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-05 13:40 Matthieu CASTET [this message]
2012-11-05 20:05 ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1352122805-30099-1-git-send-email-matthieu.castet@parrot.com \
    --to=matthieu.castet@parrot.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®