Skip to content

Commit

Permalink
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/git/cmarinas/linux-2.6-cm

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/cmarinas/linux-2.6-cm:
  kmemleak: Allow kmemleak metadata allocations to fail
  kmemleak: remove memset by using kzalloc
  • Loading branch information
Linus Torvalds committed Jan 31, 2011
2 parents 52cea8a + 6ae4bd1 commit 4fda116
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 2 additions & 4 deletions mm/kmemleak-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,11 @@ static int __init kmemleak_test_init(void)
* after the module is removed.
*/
for (i = 0; i < 10; i++) {
elem = kmalloc(sizeof(*elem), GFP_KERNEL);
pr_info("kmemleak: kmalloc(sizeof(*elem)) = %p\n", elem);
elem = kzalloc(sizeof(*elem), GFP_KERNEL);
pr_info("kmemleak: kzalloc(sizeof(*elem)) = %p\n", elem);
if (!elem)
return -ENOMEM;
memset(elem, 0, sizeof(*elem));
INIT_LIST_HEAD(&elem->list);

list_add_tail(&elem->list, &test_list);
}

Expand Down
13 changes: 8 additions & 5 deletions mm/kmemleak.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@
#define BYTES_PER_POINTER sizeof(void *)

/* GFP bitmask for kmemleak internal allocations */
#define GFP_KMEMLEAK_MASK (GFP_KERNEL | GFP_ATOMIC)
#define gfp_kmemleak_mask(gfp) (((gfp) & (GFP_KERNEL | GFP_ATOMIC)) | \
__GFP_NORETRY | __GFP_NOMEMALLOC | \
__GFP_NOWARN)

/* scanning area inside a memory block */
struct kmemleak_scan_area {
Expand Down Expand Up @@ -511,9 +513,10 @@ static struct kmemleak_object *create_object(unsigned long ptr, size_t size,
struct kmemleak_object *object;
struct prio_tree_node *node;

object = kmem_cache_alloc(object_cache, gfp & GFP_KMEMLEAK_MASK);
object = kmem_cache_alloc(object_cache, gfp_kmemleak_mask(gfp));
if (!object) {
kmemleak_stop("Cannot allocate a kmemleak_object structure\n");
pr_warning("Cannot allocate a kmemleak_object structure\n");
kmemleak_disable();
return NULL;
}

Expand Down Expand Up @@ -734,9 +737,9 @@ static void add_scan_area(unsigned long ptr, size_t size, gfp_t gfp)
return;
}

area = kmem_cache_alloc(scan_area_cache, gfp & GFP_KMEMLEAK_MASK);
area = kmem_cache_alloc(scan_area_cache, gfp_kmemleak_mask(gfp));
if (!area) {
kmemleak_warn("Cannot allocate a scan area\n");
pr_warning("Cannot allocate a scan area\n");
goto out;
}

Expand Down

0 comments on commit 4fda116

Please sign in to comment.