From: Pan Xinhui <xinhuix.pan@intel.com>
To: linux-kernel@vger.kernel.org, linux-mm@kvack.org
Cc: akpm@linux-foundation.org, oleg@redhat.com,
bill.c.roberts@gmail.com, rientjes@google.com,
yanmin_zhang@linux.intel.com
Subject: [PATCH] mm/util.c: add a none zero check of "len"
Date: Tue, 20 Jan 2015 16:20:03 +0800 [thread overview]
Message-ID: <54BE0FB3.1030008@intel.com> (raw)
Although this check should have been done by caller. But as it's exported to others,
It's better to add a none zero check of "len" like other functions.
Signed-off-by: xinhuix.pan <xinhuix.pan@intel.com>
---
mm/util.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/mm/util.c b/mm/util.c
index fec39d4..3dc2873 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -72,6 +72,9 @@ void *kmemdup(const void *src, size_t len, gfp_t gfp)
{
void *p;
+ if (unlikely(!len))
+ return ERR_PTR(-EINVAL);
+
p = kmalloc_track_caller(len, gfp);
if (p)
memcpy(p, src, len);
@@ -91,6 +94,8 @@ void *memdup_user(const void __user *src, size_t len)
{
void *p;
+ if (unlikely(!len))
+ return ERR_PTR(-EINVAL);
/*
* Always use GFP_KERNEL, since copy_from_user() can sleep and
* cause pagefault, which makes it pointless to use GFP_NOFS
--
1.9.1
--
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>
WARNING: multiple messages have this Message-ID (diff)
From: Pan Xinhui <xinhuix.pan@intel.com>
To: linux-kernel@vger.kernel.org, linux-mm@kvack.org
Cc: akpm@linux-foundation.org, oleg@redhat.com,
bill.c.roberts@gmail.com, rientjes@google.com,
yanmin_zhang@linux.intel.com
Subject: [PATCH] mm/util.c: add a none zero check of "len"
Date: Tue, 20 Jan 2015 16:20:03 +0800 [thread overview]
Message-ID: <54BE0FB3.1030008@intel.com> (raw)
Although this check should have been done by caller. But as it's exported to others,
It's better to add a none zero check of "len" like other functions.
Signed-off-by: xinhuix.pan <xinhuix.pan@intel.com>
---
mm/util.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/mm/util.c b/mm/util.c
index fec39d4..3dc2873 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -72,6 +72,9 @@ void *kmemdup(const void *src, size_t len, gfp_t gfp)
{
void *p;
+ if (unlikely(!len))
+ return ERR_PTR(-EINVAL);
+
p = kmalloc_track_caller(len, gfp);
if (p)
memcpy(p, src, len);
@@ -91,6 +94,8 @@ void *memdup_user(const void __user *src, size_t len)
{
void *p;
+ if (unlikely(!len))
+ return ERR_PTR(-EINVAL);
/*
* Always use GFP_KERNEL, since copy_from_user() can sleep and
* cause pagefault, which makes it pointless to use GFP_NOFS
--
1.9.1
next reply other threads:[~2015-01-19 8:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-20 8:20 Pan Xinhui [this message]
2015-01-20 8:20 ` [PATCH] mm/util.c: add a none zero check of "len" Pan Xinhui
2015-01-21 23:09 ` David Rientjes
2015-01-21 23:09 ` David Rientjes
2015-01-23 2:28 ` Pan Xinhui
2015-01-23 2:28 ` Pan Xinhui
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=54BE0FB3.1030008@intel.com \
--to=xinhuix.pan@intel.com \
--cc=akpm@linux-foundation.org \
--cc=bill.c.roberts@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=oleg@redhat.com \
--cc=rientjes@google.com \
--cc=yanmin_zhang@linux.intel.com \
/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.