Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 139154
b: refs/heads/master
c: 610a77e
h: refs/heads/master
v: v3
  • Loading branch information
Li Zefan authored and Linus Torvalds committed Apr 1, 2009
1 parent dd9a4a9 commit 050145f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e2f17d9459aeccf4e013e31cbd741d6b1858eec4
refs/heads/master: 610a77e04a8d9fe8764dc484e2182fa251ce1cc2
1 change: 1 addition & 0 deletions trunk/include/linux/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +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);

/*
* Include machine specific inline routines
Expand Down
30 changes: 30 additions & 0 deletions trunk/mm/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,36 @@ void *kmemdup(const void *src, size_t len, gfp_t gfp)
}
EXPORT_SYMBOL(kmemdup);

/**
* memdup_user - duplicate memory region from user space
*
* @src: source address in user space
* @len: number of bytes to copy
*
* Returns an ERR_PTR() on failure.
*/
void *memdup_user(const void __user *src, size_t len)
{
void *p;

/*
* 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);

if (copy_from_user(p, src, len)) {
kfree(p);
return ERR_PTR(-EFAULT);
}

return p;
}
EXPORT_SYMBOL(memdup_user);

/**
* __krealloc - like krealloc() but don't free @p.
* @p: object to reallocate memory for.
Expand Down

0 comments on commit 050145f

Please sign in to comment.