lkml.org 
[lkml]   [2009]   [Feb]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[patch 1/8] slab: introduce kzfree()
    kzfree() is a wrapper for kfree() that additionally zeroes the
    underlying memory before releasing it to the slab allocator.

    Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
    Acked-by: Pekka Enberg <penberg@cs.helsinki.fi>
    Cc: Matt Mackall <mpm@selenic.com>
    Cc: Christoph Lameter <cl@linux-foundation.org>
    Cc: Nick Piggin <npiggin@suse.de>
    ---
    include/linux/slab.h | 1 +
    mm/util.c | 19 +++++++++++++++++++
    2 files changed, 20 insertions(+)

    --- a/include/linux/slab.h
    +++ b/include/linux/slab.h
    @@ -127,6 +127,7 @@ int kmem_ptr_validate(struct kmem_cache
    void * __must_check __krealloc(const void *, size_t, gfp_t);
    void * __must_check krealloc(const void *, size_t, gfp_t);
    void kfree(const void *);
    +void kzfree(const void *);
    size_t ksize(const void *);

    /*
    --- a/mm/util.c
    +++ b/mm/util.c
    @@ -129,6 +129,25 @@ void *krealloc(const void *p, size_t new
    }
    EXPORT_SYMBOL(krealloc);

    +/**
    + * kzfree - like kfree but zero memory
    + * @p: object to free memory of
    + *
    + * The memory of the object @p points to is zeroed before freed.
    + * If @p is %NULL, kzfree() does nothing.
    + */
    +void kzfree(const void *p)
    +{
    + size_t ks;
    + void *mem = (void *)p;
    +
    + if (unlikely(ZERO_OR_NULL_PTR(mem)))
    + return;
    + ks = ksize(mem);
    + memset(mem, 0, ks);
    + kfree(mem);
    +}
    +
    /*
    * strndup_user - duplicate an existing string from user space
    * @s: The string to duplicate



    \
     
     \ /
      Last update: 2009-02-18 12:23    [W:3.852 / U:0.004 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site