Skip to content

Commit

Permalink
kmemtrace: trace kfree() calls with NULL or zero-length objects
Browse files Browse the repository at this point in the history
Impact: also output kfree(NULL) entries

This patch moves the trace_kfree() calls before the ZERO_OR_NULL_PTR
check so that we can trace call-sites that call kfree() with NULL many
times which might be an indication of a bug.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
LKML-Reference: <1237971957.30175.18.camel@penberg-laptop>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Pekka Enberg authored and Ingo Molnar committed Apr 3, 2009
1 parent c826e3c commit 2121db7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions mm/slab.c
Original file line number Diff line number Diff line change
Expand Up @@ -3773,6 +3773,8 @@ void kfree(const void *objp)
struct kmem_cache *c;
unsigned long flags;

trace_kfree(_RET_IP_, objp);

if (unlikely(ZERO_OR_NULL_PTR(objp)))
return;
local_irq_save(flags);
Expand All @@ -3782,8 +3784,6 @@ void kfree(const void *objp)
debug_check_no_obj_freed(objp, obj_size(c));
__cache_free(c, (void *)objp);
local_irq_restore(flags);

trace_kfree(_RET_IP_, objp);
}
EXPORT_SYMBOL(kfree);

Expand Down
4 changes: 2 additions & 2 deletions mm/slob.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ void kfree(const void *block)
{
struct slob_page *sp;

trace_kfree(_RET_IP_, block);

if (unlikely(ZERO_OR_NULL_PTR(block)))
return;

Expand All @@ -524,8 +526,6 @@ void kfree(const void *block)
slob_free(m, *m + align);
} else
put_page(&sp->page);

trace_kfree(_RET_IP_, block);
}
EXPORT_SYMBOL(kfree);

Expand Down
4 changes: 2 additions & 2 deletions mm/slub.c
Original file line number Diff line number Diff line change
Expand Up @@ -2792,6 +2792,8 @@ void kfree(const void *x)
struct page *page;
void *object = (void *)x;

trace_kfree(_RET_IP_, x);

if (unlikely(ZERO_OR_NULL_PTR(x)))
return;

Expand All @@ -2802,8 +2804,6 @@ void kfree(const void *x)
return;
}
slab_free(page->slab, page, object, _RET_IP_);

trace_kfree(_RET_IP_, x);
}
EXPORT_SYMBOL(kfree);

Expand Down

0 comments on commit 2121db7

Please sign in to comment.