lkml.org 
[lkml]   [2008]   [Dec]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH 06/14] kmemleak: Add the vmalloc memory allocation/freeing hooks
From
Date
This patch adds the callbacks to kmemleak_(alloc|free) functions from
vmalloc/vfree.

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
---
mm/vmalloc.c | 28 +++++++++++++++++++++++++---
1 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 1ddb77b..ad0a0af 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -23,6 +23,7 @@
#include <linux/rbtree.h>
#include <linux/radix-tree.h>
#include <linux/rcupdate.h>
+#include <linux/kmemleak.h>

#include <asm/atomic.h>
#include <asm/uaccess.h>
@@ -1196,6 +1197,9 @@ static void __vunmap(const void *addr, int deallocate_pages)
void vfree(const void *addr)
{
BUG_ON(in_interrupt());
+
+ kmemleak_free(addr);
+
__vunmap(addr, 1);
}
EXPORT_SYMBOL(vfree);
@@ -1305,8 +1309,16 @@ fail:

void *__vmalloc_area(struct vm_struct *area, gfp_t gfp_mask, pgprot_t prot)
{
- return __vmalloc_area_node(area, gfp_mask, prot, -1,
- __builtin_return_address(0));
+ void *addr = __vmalloc_area_node(area, gfp_mask, prot, -1,
+ __builtin_return_address(0));
+
+ /*
+ * This needs ref_count = 2 since vm_struct also contains a pointer to
+ * this address. The guard page is subtracted from the size.
+ */
+ kmemleak_alloc(addr, area->size - PAGE_SIZE, 2, gfp_mask);
+
+ return addr;
}

/**
@@ -1325,6 +1337,8 @@ static void *__vmalloc_node(unsigned long size, gfp_t gfp_mask, pgprot_t prot,
int node, void *caller)
{
struct vm_struct *area;
+ void *addr;
+ unsigned long real_size = size;

size = PAGE_ALIGN(size);
if (!size || (size >> PAGE_SHIFT) > num_physpages)
@@ -1336,7 +1350,15 @@ static void *__vmalloc_node(unsigned long size, gfp_t gfp_mask, pgprot_t prot,
if (!area)
return NULL;

- return __vmalloc_area_node(area, gfp_mask, prot, node, caller);
+ addr = __vmalloc_area_node(area, gfp_mask, prot, node, caller);
+
+ /*
+ * This needs ref_count = 2 since the vm_struct also contains a
+ * pointer to this address.
+ */
+ kmemleak_alloc(addr, real_size, 2, gfp_mask);
+
+ return addr;
}

void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)


\
 
 \ /
  Last update: 2008-12-19 19:17    [W:0.154 / U:1.248 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site