From: Johannes Weiner <hannes@cmpxchg.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Matt Mackall <mpm@selenic.com>,
Christoph Lameter <cl@linux-foundation.org>,
Nick Piggin <npiggin@suse.de>
Subject: [patch 1/8] slab: introduce kzfree()
Date: Mon, 16 Feb 2009 15:29:27 +0100 [thread overview]
Message-ID: <20090216144725.572446535@cmpxchg.org> (raw)
In-Reply-To: 20090216142926.440561506@cmpxchg.org
[-- Attachment #1: slab-introduce-kzfree.patch --]
[-- Type: text/plain, Size: 1393 bytes --]
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
WARNING: multiple messages have this Message-ID (diff)
From: Johannes Weiner <hannes@cmpxchg.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Matt Mackall <mpm@selenic.com>,
Christoph Lameter <cl@linux-foundation.org>,
Nick Piggin <npiggin@suse.de>
Subject: [patch 1/8] slab: introduce kzfree()
Date: Mon, 16 Feb 2009 15:29:27 +0100 [thread overview]
Message-ID: <20090216144725.572446535@cmpxchg.org> (raw)
In-Reply-To: 20090216142926.440561506@cmpxchg.org
[-- Attachment #1: slab-introduce-kzfree.patch --]
[-- Type: text/plain, Size: 1618 bytes --]
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
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2009-02-16 15:05 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-16 14:29 [patch 0/8] kzfree() Johannes Weiner
2009-02-16 14:29 ` Johannes Weiner
2009-02-16 14:29 ` Johannes Weiner [this message]
2009-02-16 14:29 ` [patch 1/8] slab: introduce kzfree() Johannes Weiner
2009-02-16 15:27 ` Johannes Weiner
2009-02-16 15:27 ` Johannes Weiner
2009-02-17 15:08 ` Christoph Lameter
2009-02-17 15:08 ` Christoph Lameter
2009-02-17 15:51 ` Pekka Enberg
2009-02-17 15:51 ` Pekka Enberg
2009-02-17 16:01 ` Christoph Lameter
2009-02-17 16:01 ` Christoph Lameter
2009-02-16 14:29 ` [patch 2/8] crypto: use kzfree() Johannes Weiner
2009-02-16 14:29 ` Johannes Weiner
2009-02-16 14:29 ` [patch 3/8] s390: " Johannes Weiner
2009-02-16 14:29 ` Johannes Weiner
2009-02-16 14:29 ` [patch 4/8] md: " Johannes Weiner
2009-02-16 14:29 ` Johannes Weiner
2009-02-16 14:29 ` [patch 5/8] usb: " Johannes Weiner
2009-02-16 14:29 ` Johannes Weiner
2009-02-16 14:29 ` [patch 6/8] cifs: " Johannes Weiner
2009-02-16 14:29 ` Johannes Weiner
2009-02-16 15:13 ` Pekka Enberg
2009-02-16 15:13 ` Pekka Enberg
2009-02-16 15:33 ` Johannes Weiner
2009-02-16 15:33 ` Johannes Weiner
2009-02-16 18:17 ` Pekka Enberg
2009-02-16 18:17 ` Pekka Enberg
2009-02-16 19:01 ` Steve French
2009-02-16 19:02 ` Steve French
2009-02-16 19:02 ` Steve French
2009-02-16 14:29 ` [patch 7/8] ecryptfs: " Johannes Weiner
2009-02-16 14:29 ` Johannes Weiner
2009-02-16 20:02 ` Andrew Morton
2009-02-16 20:02 ` Andrew Morton
2009-02-16 20:28 ` Johannes Weiner
2009-02-16 20:28 ` Johannes Weiner
2009-02-17 7:51 ` Tyler Hicks
2009-02-16 14:29 ` [patch 8/8] atm: " Johannes Weiner
2009-02-16 14:29 ` Johannes Weiner
2009-02-16 19:59 ` [patch 0/8] kzfree() Andrew Morton
2009-02-16 19:59 ` Andrew Morton
2009-02-16 19:58 ` Pekka Enberg
2009-02-16 19:58 ` Pekka Enberg
2009-02-16 20:19 ` Andrew Morton
2009-02-16 20:19 ` Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090216144725.572446535@cmpxchg.org \
--to=hannes@cmpxchg.org \
--cc=akpm@linux-foundation.org \
--cc=cl@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mpm@selenic.com \
--cc=npiggin@suse.de \
--cc=penberg@cs.helsinki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.