Commit e4f7c0b44a8ac8935f223195af9ea637d0c08091
1 parent
2587362eaf
Exists in
master
and in
7 other branches
kmemleak: Trace the kmalloc_large* functions in slub
The kmalloc_large() and kmalloc_large_node() functions were missed when adding the kmemleak hooks to the slub allocator. However, they should be traced to avoid false positives. Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> Cc: Christoph Lameter <cl@linux-foundation.org> Acked-by: Pekka Enberg <penberg@cs.helsinki.fi>
Showing 2 changed files with 8 additions and 4 deletions Side-by-side Diff
include/linux/slub_def.h
... | ... | @@ -11,6 +11,7 @@ |
11 | 11 | #include <linux/workqueue.h> |
12 | 12 | #include <linux/kobject.h> |
13 | 13 | #include <linux/kmemtrace.h> |
14 | +#include <linux/kmemleak.h> | |
14 | 15 | |
15 | 16 | enum stat_item { |
16 | 17 | ALLOC_FASTPATH, /* Allocation from cpu slab */ |
... | ... | @@ -233,6 +234,7 @@ |
233 | 234 | unsigned int order = get_order(size); |
234 | 235 | void *ret = (void *) __get_free_pages(flags | __GFP_COMP, order); |
235 | 236 | |
237 | + kmemleak_alloc(ret, size, 1, flags); | |
236 | 238 | trace_kmalloc(_THIS_IP_, ret, size, PAGE_SIZE << order, flags); |
237 | 239 | |
238 | 240 | return ret; |
mm/slub.c
... | ... | @@ -21,7 +21,6 @@ |
21 | 21 | #include <linux/kmemcheck.h> |
22 | 22 | #include <linux/cpu.h> |
23 | 23 | #include <linux/cpuset.h> |
24 | -#include <linux/kmemleak.h> | |
25 | 24 | #include <linux/mempolicy.h> |
26 | 25 | #include <linux/ctype.h> |
27 | 26 | #include <linux/debugobjects.h> |
28 | 27 | |
... | ... | @@ -2835,13 +2834,15 @@ |
2835 | 2834 | static void *kmalloc_large_node(size_t size, gfp_t flags, int node) |
2836 | 2835 | { |
2837 | 2836 | struct page *page; |
2837 | + void *ptr = NULL; | |
2838 | 2838 | |
2839 | 2839 | flags |= __GFP_COMP | __GFP_NOTRACK; |
2840 | 2840 | page = alloc_pages_node(node, flags, get_order(size)); |
2841 | 2841 | if (page) |
2842 | - return page_address(page); | |
2843 | - else | |
2844 | - return NULL; | |
2842 | + ptr = page_address(page); | |
2843 | + | |
2844 | + kmemleak_alloc(ptr, size, 1, flags); | |
2845 | + return ptr; | |
2845 | 2846 | } |
2846 | 2847 | |
2847 | 2848 | #ifdef CONFIG_NUMA |
... | ... | @@ -2926,6 +2927,7 @@ |
2926 | 2927 | page = virt_to_head_page(x); |
2927 | 2928 | if (unlikely(!PageSlab(page))) { |
2928 | 2929 | BUG_ON(!PageCompound(page)); |
2930 | + kmemleak_free(x); | |
2929 | 2931 | put_page(page); |
2930 | 2932 | return; |
2931 | 2933 | } |