diff options
Diffstat (limited to 'mm/util.c')
-rw-r--r-- | mm/util.c | 111 |
1 files changed, 3 insertions, 108 deletions
@@ -16,9 +16,6 @@ | |||
16 | 16 | ||
17 | #include "internal.h" | 17 | #include "internal.h" |
18 | 18 | ||
19 | #define CREATE_TRACE_POINTS | ||
20 | #include <trace/events/kmem.h> | ||
21 | |||
22 | /** | 19 | /** |
23 | * kstrdup - allocate space for and copy an existing string | 20 | * kstrdup - allocate space for and copy an existing string |
24 | * @s: the string to duplicate | 21 | * @s: the string to duplicate |
@@ -112,97 +109,6 @@ void *memdup_user(const void __user *src, size_t len) | |||
112 | } | 109 | } |
113 | EXPORT_SYMBOL(memdup_user); | 110 | EXPORT_SYMBOL(memdup_user); |
114 | 111 | ||
115 | static __always_inline void *__do_krealloc(const void *p, size_t new_size, | ||
116 | gfp_t flags) | ||
117 | { | ||
118 | void *ret; | ||
119 | size_t ks = 0; | ||
120 | |||
121 | if (p) | ||
122 | ks = ksize(p); | ||
123 | |||
124 | if (ks >= new_size) | ||
125 | return (void *)p; | ||
126 | |||
127 | ret = kmalloc_track_caller(new_size, flags); | ||
128 | if (ret && p) | ||
129 | memcpy(ret, p, ks); | ||
130 | |||
131 | return ret; | ||
132 | } | ||
133 | |||
134 | /** | ||
135 | * __krealloc - like krealloc() but don't free @p. | ||
136 | * @p: object to reallocate memory for. | ||
137 | * @new_size: how many bytes of memory are required. | ||
138 | * @flags: the type of memory to allocate. | ||
139 | * | ||
140 | * This function is like krealloc() except it never frees the originally | ||
141 | * allocated buffer. Use this if you don't want to free the buffer immediately | ||
142 | * like, for example, with RCU. | ||
143 | */ | ||
144 | void *__krealloc(const void *p, size_t new_size, gfp_t flags) | ||
145 | { | ||
146 | if (unlikely(!new_size)) | ||
147 | return ZERO_SIZE_PTR; | ||
148 | |||
149 | return __do_krealloc(p, new_size, flags); | ||
150 | |||
151 | } | ||
152 | EXPORT_SYMBOL(__krealloc); | ||
153 | |||
154 | /** | ||
155 | * krealloc - reallocate memory. The contents will remain unchanged. | ||
156 | * @p: object to reallocate memory for. | ||
157 | * @new_size: how many bytes of memory are required. | ||
158 | * @flags: the type of memory to allocate. | ||
159 | * | ||
160 | * The contents of the object pointed to are preserved up to the | ||
161 | * lesser of the new and old sizes. If @p is %NULL, krealloc() | ||
162 | * behaves exactly like kmalloc(). If @new_size is 0 and @p is not a | ||
163 | * %NULL pointer, the object pointed to is freed. | ||
164 | */ | ||
165 | void *krealloc(const void *p, size_t new_size, gfp_t flags) | ||
166 | { | ||
167 | void *ret; | ||
168 | |||
169 | if (unlikely(!new_size)) { | ||
170 | kfree(p); | ||
171 | return ZERO_SIZE_PTR; | ||
172 | } | ||
173 | |||
174 | ret = __do_krealloc(p, new_size, flags); | ||
175 | if (ret && p != ret) | ||
176 | kfree(p); | ||
177 | |||
178 | return ret; | ||
179 | } | ||
180 | EXPORT_SYMBOL(krealloc); | ||
181 | |||
182 | /** | ||
183 | * kzfree - like kfree but zero memory | ||
184 | * @p: object to free memory of | ||
185 | * | ||
186 | * The memory of the object @p points to is zeroed before freed. | ||
187 | * If @p is %NULL, kzfree() does nothing. | ||
188 | * | ||
189 | * Note: this function zeroes the whole allocated buffer which can be a good | ||
190 | * deal bigger than the requested buffer size passed to kmalloc(). So be | ||
191 | * careful when using this function in performance sensitive code. | ||
192 | */ | ||
193 | void kzfree(const void *p) | ||
194 | { | ||
195 | size_t ks; | ||
196 | void *mem = (void *)p; | ||
197 | |||
198 | if (unlikely(ZERO_OR_NULL_PTR(mem))) | ||
199 | return; | ||
200 | ks = ksize(mem); | ||
201 | memset(mem, 0, ks); | ||
202 | kfree(mem); | ||
203 | } | ||
204 | EXPORT_SYMBOL(kzfree); | ||
205 | |||
206 | /* | 112 | /* |
207 | * strndup_user - duplicate an existing string from user space | 113 | * strndup_user - duplicate an existing string from user space |
208 | * @s: The string to duplicate | 114 | * @s: The string to duplicate |
@@ -277,17 +183,14 @@ pid_t vm_is_stack(struct task_struct *task, | |||
277 | 183 | ||
278 | if (in_group) { | 184 | if (in_group) { |
279 | struct task_struct *t; | 185 | struct task_struct *t; |
280 | rcu_read_lock(); | ||
281 | if (!pid_alive(task)) | ||
282 | goto done; | ||
283 | 186 | ||
284 | t = task; | 187 | rcu_read_lock(); |
285 | do { | 188 | for_each_thread(task, t) { |
286 | if (vm_is_stack_for_task(t, vma)) { | 189 | if (vm_is_stack_for_task(t, vma)) { |
287 | ret = t->pid; | 190 | ret = t->pid; |
288 | goto done; | 191 | goto done; |
289 | } | 192 | } |
290 | } while_each_thread(task, t); | 193 | } |
291 | done: | 194 | done: |
292 | rcu_read_unlock(); | 195 | rcu_read_unlock(); |
293 | } | 196 | } |
@@ -504,11 +407,3 @@ out_mm: | |||
504 | out: | 407 | out: |
505 | return res; | 408 | return res; |
506 | } | 409 | } |
507 | |||
508 | /* Tracepoints definitions. */ | ||
509 | EXPORT_TRACEPOINT_SYMBOL(kmalloc); | ||
510 | EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc); | ||
511 | EXPORT_TRACEPOINT_SYMBOL(kmalloc_node); | ||
512 | EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc_node); | ||
513 | EXPORT_TRACEPOINT_SYMBOL(kfree); | ||
514 | EXPORT_TRACEPOINT_SYMBOL(kmem_cache_free); | ||