Skip to contentSkip to conversation

memdup_user: introduce, fix

PATCH In review Li Zefan 2 participants 2 messages Mar 10, 2009

Subsystems (3)
lore
Share & tools
lore

Li Zefan

author
#0 lore raw

PATCH 1/1 memdup_user: introduce, fix

Always use GFP_KERNEL in kmalloc(), since copy_from_user() can sleep and cause pagefault, thus it's pointless to use GFP_NOFS or GFP_ATOMIC here.

---

Against memdup_user-introduce.patch

---
 include/linux/string.h |    2 +-
 mm/util.c              |   10 +++++++---
 2 files changed, 8 insertions(+), 4 deletions(-)
include/linux/string.h +1 -1
index 79f30f3..0863885 100644
@@ -12,7 +12,7 @@
 #include <linux/stddef.h>	/* for NULL */
 
 extern char *strndup_user(const char __user *, long);
-extern void *memdup_user(const void __user *, size_t, gfp_t);
+extern void *memdup_user(const void __user *, size_t);
 
 /*
  * Include machine specific inline routines
mm/util.c +7 -3
index 3d21c21..7c122e4 100644
@@ -74,15 +74,19 @@ EXPORT_SYMBOL(kmemdup);
  *
  * @src: source address in user space
  * @len: number of bytes to copy
- * @gfp: GFP mask to use
  *
  * Returns an ERR_PTR() on failure.
  */
-void *memdup_user(const void __user *src, size_t len, gfp_t gfp)
+void *memdup_user(const void __user *src, size_t len)
 {
 	void *p;
 
-	p = kmalloc_track_caller(len, gfp);
+	/*
+	 * Always use GFP_KERNEL, since copy_from_user() can sleep and
+	 * cause pagefault, which makes it pointless to use GFP_NOFS
+	 * or GFP_ATOMIC.
+	 */
+	p = kmalloc_track_caller(len, GFP_KERNEL);
 	if (!p)
 		return ERR_PTR(-ENOMEM);
 
Signature · 7 lines
1.5.4.rc3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines

* Include machine specific inline routines

mm/util.c +1 -2
index 3d21c21..7c122e4 100644
@@ -74,15 +74,19 @@ EXPORT_SYMBOL(kmemdup);
  *
  * @src: source address in user space
  * @len: number of bytes to copy
- * @gfp: GFP mask to use
  *
  * Returns an ERR_PTR() on failure.
  */
-void *memdup_user(const void __user *src, size_t len, gfp_t gfp)
+void *memdup_user(const void __user *src, size_t len)
 {
 	void *p;

mm/util.c EXPORT_SYMBOL(kmemdup); · line 91

Quoted 10 lines
mm/util.c +6 -1
 
-	p = kmalloc_track_caller(len, gfp);
+	/*
+	 * Always use GFP_KERNEL, since copy_from_user() can sleep and
+	 * cause pagefault, which makes it pointless to use GFP_NOFS
+	 * or GFP_ATOMIC.
+	 */
+	p = kmalloc_track_caller(len, GFP_KERNEL);
 	if (!p)
 		return ERR_PTR(-ENOMEM);

ok. thanks.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>