summaryrefslogtreecommitdiffstats
path: root/mm/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/util.c')
-rw-r--r--mm/util.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/mm/util.c b/mm/util.c
index 379319b1bcfd..d559bde497a9 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -36,6 +36,8 @@ EXPORT_SYMBOL(kfree_const);
36 * kstrdup - allocate space for and copy an existing string 36 * kstrdup - allocate space for and copy an existing string
37 * @s: the string to duplicate 37 * @s: the string to duplicate
38 * @gfp: the GFP mask used in the kmalloc() call when allocating memory 38 * @gfp: the GFP mask used in the kmalloc() call when allocating memory
39 *
40 * Return: newly allocated copy of @s or %NULL in case of error
39 */ 41 */
40char *kstrdup(const char *s, gfp_t gfp) 42char *kstrdup(const char *s, gfp_t gfp)
41{ 43{
@@ -58,9 +60,10 @@ EXPORT_SYMBOL(kstrdup);
58 * @s: the string to duplicate 60 * @s: the string to duplicate
59 * @gfp: the GFP mask used in the kmalloc() call when allocating memory 61 * @gfp: the GFP mask used in the kmalloc() call when allocating memory
60 * 62 *
61 * Function returns source string if it is in .rodata section otherwise it 63 * Note: Strings allocated by kstrdup_const should be freed by kfree_const.
62 * fallbacks to kstrdup. 64 *
63 * Strings allocated by kstrdup_const should be freed by kfree_const. 65 * Return: source string if it is in .rodata section otherwise
66 * fallback to kstrdup.
64 */ 67 */
65const char *kstrdup_const(const char *s, gfp_t gfp) 68const char *kstrdup_const(const char *s, gfp_t gfp)
66{ 69{
@@ -78,6 +81,8 @@ EXPORT_SYMBOL(kstrdup_const);
78 * @gfp: the GFP mask used in the kmalloc() call when allocating memory 81 * @gfp: the GFP mask used in the kmalloc() call when allocating memory
79 * 82 *
80 * Note: Use kmemdup_nul() instead if the size is known exactly. 83 * Note: Use kmemdup_nul() instead if the size is known exactly.
84 *
85 * Return: newly allocated copy of @s or %NULL in case of error
81 */ 86 */
82char *kstrndup(const char *s, size_t max, gfp_t gfp) 87char *kstrndup(const char *s, size_t max, gfp_t gfp)
83{ 88{
@@ -103,6 +108,8 @@ EXPORT_SYMBOL(kstrndup);
103 * @src: memory region to duplicate 108 * @src: memory region to duplicate
104 * @len: memory region length 109 * @len: memory region length
105 * @gfp: GFP mask to use 110 * @gfp: GFP mask to use
111 *
112 * Return: newly allocated copy of @src or %NULL in case of error
106 */ 113 */
107void *kmemdup(const void *src, size_t len, gfp_t gfp) 114void *kmemdup(const void *src, size_t len, gfp_t gfp)
108{ 115{
@@ -120,6 +127,9 @@ EXPORT_SYMBOL(kmemdup);
120 * @s: The data to stringify 127 * @s: The data to stringify
121 * @len: The size of the data 128 * @len: The size of the data
122 * @gfp: the GFP mask used in the kmalloc() call when allocating memory 129 * @gfp: the GFP mask used in the kmalloc() call when allocating memory
130 *
131 * Return: newly allocated copy of @s with NUL-termination or %NULL in
132 * case of error
123 */ 133 */
124char *kmemdup_nul(const char *s, size_t len, gfp_t gfp) 134char *kmemdup_nul(const char *s, size_t len, gfp_t gfp)
125{ 135{
@@ -143,7 +153,7 @@ EXPORT_SYMBOL(kmemdup_nul);
143 * @src: source address in user space 153 * @src: source address in user space
144 * @len: number of bytes to copy 154 * @len: number of bytes to copy
145 * 155 *
146 * Returns an ERR_PTR() on failure. Result is physically 156 * Return: an ERR_PTR() on failure. Result is physically
147 * contiguous, to be freed by kfree(). 157 * contiguous, to be freed by kfree().
148 */ 158 */
149void *memdup_user(const void __user *src, size_t len) 159void *memdup_user(const void __user *src, size_t len)
@@ -169,7 +179,7 @@ EXPORT_SYMBOL(memdup_user);
169 * @src: source address in user space 179 * @src: source address in user space
170 * @len: number of bytes to copy 180 * @len: number of bytes to copy
171 * 181 *
172 * Returns an ERR_PTR() on failure. Result may be not 182 * Return: an ERR_PTR() on failure. Result may be not
173 * physically contiguous. Use kvfree() to free. 183 * physically contiguous. Use kvfree() to free.
174 */ 184 */
175void *vmemdup_user(const void __user *src, size_t len) 185void *vmemdup_user(const void __user *src, size_t len)
@@ -193,6 +203,8 @@ EXPORT_SYMBOL(vmemdup_user);
193 * strndup_user - duplicate an existing string from user space 203 * strndup_user - duplicate an existing string from user space
194 * @s: The string to duplicate 204 * @s: The string to duplicate
195 * @n: Maximum number of bytes to copy, including the trailing NUL. 205 * @n: Maximum number of bytes to copy, including the trailing NUL.
206 *
207 * Return: newly allocated copy of @s or %NULL in case of error
196 */ 208 */
197char *strndup_user(const char __user *s, long n) 209char *strndup_user(const char __user *s, long n)
198{ 210{
@@ -224,7 +236,7 @@ EXPORT_SYMBOL(strndup_user);
224 * @src: source address in user space 236 * @src: source address in user space
225 * @len: number of bytes to copy 237 * @len: number of bytes to copy
226 * 238 *
227 * Returns an ERR_PTR() on failure. 239 * Return: an ERR_PTR() on failure.
228 */ 240 */
229void *memdup_user_nul(const void __user *src, size_t len) 241void *memdup_user_nul(const void __user *src, size_t len)
230{ 242{
@@ -310,10 +322,6 @@ EXPORT_SYMBOL_GPL(__get_user_pages_fast);
310 * @pages: array that receives pointers to the pages pinned. 322 * @pages: array that receives pointers to the pages pinned.
311 * Should be at least nr_pages long. 323 * Should be at least nr_pages long.
312 * 324 *
313 * Returns number of pages pinned. This may be fewer than the number
314 * requested. If nr_pages is 0 or negative, returns 0. If no pages
315 * were pinned, returns -errno.
316 *
317 * get_user_pages_fast provides equivalent functionality to get_user_pages, 325 * get_user_pages_fast provides equivalent functionality to get_user_pages,
318 * operating on current and current->mm, with force=0 and vma=NULL. However 326 * operating on current and current->mm, with force=0 and vma=NULL. However
319 * unlike get_user_pages, it must be called without mmap_sem held. 327 * unlike get_user_pages, it must be called without mmap_sem held.
@@ -325,6 +333,10 @@ EXPORT_SYMBOL_GPL(__get_user_pages_fast);
325 * pages have to be faulted in, it may turn out to be slightly slower so 333 * pages have to be faulted in, it may turn out to be slightly slower so
326 * callers need to carefully consider what to use. On many architectures, 334 * callers need to carefully consider what to use. On many architectures,
327 * get_user_pages_fast simply falls back to get_user_pages. 335 * get_user_pages_fast simply falls back to get_user_pages.
336 *
337 * Return: number of pages pinned. This may be fewer than the number
338 * requested. If nr_pages is 0 or negative, returns 0. If no pages
339 * were pinned, returns -errno.
328 */ 340 */
329int __weak get_user_pages_fast(unsigned long start, 341int __weak get_user_pages_fast(unsigned long start,
330 int nr_pages, int write, struct page **pages) 342 int nr_pages, int write, struct page **pages)
@@ -386,6 +398,8 @@ EXPORT_SYMBOL(vm_mmap);
386 * 398 *
387 * Please note that any use of gfp flags outside of GFP_KERNEL is careful to not 399 * Please note that any use of gfp flags outside of GFP_KERNEL is careful to not
388 * fall back to vmalloc. 400 * fall back to vmalloc.
401 *
402 * Return: pointer to the allocated memory of %NULL in case of failure
389 */ 403 */
390void *kvmalloc_node(size_t size, gfp_t flags, int node) 404void *kvmalloc_node(size_t size, gfp_t flags, int node)
391{ 405{
@@ -729,7 +743,8 @@ error:
729 * @buffer: the buffer to copy to. 743 * @buffer: the buffer to copy to.
730 * @buflen: the length of the buffer. Larger cmdline values are truncated 744 * @buflen: the length of the buffer. Larger cmdline values are truncated
731 * to this length. 745 * to this length.
732 * Returns the size of the cmdline field copied. Note that the copy does 746 *
747 * Return: the size of the cmdline field copied. Note that the copy does
733 * not guarantee an ending NULL byte. 748 * not guarantee an ending NULL byte.
734 */ 749 */
735int get_cmdline(struct task_struct *task, char *buffer, int buflen) 750int get_cmdline(struct task_struct *task, char *buffer, int buflen)