[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20090216152751.GA27520@cmpxchg.org>
Date: Mon, 16 Feb 2009 16:27:51 +0100
From: Johannes Weiner <hannes@...xchg.org>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: Pekka Enberg <penberg@...helsinki.fi>, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, Matt Mackall <mpm@...enic.com>,
Christoph Lameter <cl@...ux-foundation.org>,
Nick Piggin <npiggin@...e.de>
Subject: Re: [patch 1/8] slab: introduce kzfree()
On Mon, Feb 16, 2009 at 03:29:27PM +0100, Johannes Weiner wrote:
> 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@...xchg.org>
> Acked-by: Pekka Enberg <penberg@...helsinki.fi>
> Cc: Matt Mackall <mpm@...enic.com>
> Cc: Christoph Lameter <cl@...ux-foundation.org>
> Cc: Nick Piggin <npiggin@...e.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);
> +}
Sorry, please fold this delta:
--- a/mm/util.c
+++ b/mm/util.c
@@ -147,6 +147,7 @@ void kzfree(const void *p)
memset(mem, 0, ks);
kfree(mem);
}
+EXPORT_SYMBOL(kzfree);
/*
* strndup_user - duplicate an existing string from user space
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists