diff mbox

mm: cma: WARN if freed memory is still in use

Message ID 1352718446-32313-1-git-send-email-m.szyprowski@samsung.com
State Accepted
Commit bcc2b02f4c1b36bc67272df7119b75bac78525ab
Headers show

Commit Message

Marek Szyprowski Nov. 12, 2012, 11:07 a.m. UTC
Memory return to free_contig_range() must have no other references. Let
kernel to complain loudly if page reference count is not equal to 1.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Reviewed-by: Kyungmin Park <kyungmin.park@samsung.com>
CC: Michal Nazarewicz <mina86@mina86.com>
---
 mm/page_alloc.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 022e4ed..290c2eb 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5888,8 +5888,13 @@  done:
 
 void free_contig_range(unsigned long pfn, unsigned nr_pages)
 {
-	for (; nr_pages--; ++pfn)
-		__free_page(pfn_to_page(pfn));
+	struct page *page = pfn_to_page(pfn);
+	int refcount = nr_pages;
+	for (; nr_pages--; page++) {
+		refcount -= page_count(page) == 1;
+		__free_page(page);
+	}
+	WARN(refcount != 0, "some pages are still in use!\n");
 }
 #endif