diff options
Diffstat (limited to 'mm/slob.c')
-rw-r--r-- | mm/slob.c | 35 |
1 files changed, 34 insertions, 1 deletions
@@ -190,6 +190,39 @@ void *__kmalloc(size_t size, gfp_t gfp) | |||
190 | } | 190 | } |
191 | EXPORT_SYMBOL(__kmalloc); | 191 | EXPORT_SYMBOL(__kmalloc); |
192 | 192 | ||
193 | /** | ||
194 | * krealloc - reallocate memory. The contents will remain unchanged. | ||
195 | * | ||
196 | * @p: object to reallocate memory for. | ||
197 | * @new_size: how many bytes of memory are required. | ||
198 | * @flags: the type of memory to allocate. | ||
199 | * | ||
200 | * The contents of the object pointed to are preserved up to the | ||
201 | * lesser of the new and old sizes. If @p is %NULL, krealloc() | ||
202 | * behaves exactly like kmalloc(). If @size is 0 and @p is not a | ||
203 | * %NULL pointer, the object pointed to is freed. | ||
204 | */ | ||
205 | void *krealloc(const void *p, size_t new_size, gfp_t flags) | ||
206 | { | ||
207 | void *ret; | ||
208 | |||
209 | if (unlikely(!p)) | ||
210 | return kmalloc_track_caller(new_size, flags); | ||
211 | |||
212 | if (unlikely(!new_size)) { | ||
213 | kfree(p); | ||
214 | return NULL; | ||
215 | } | ||
216 | |||
217 | ret = kmalloc_track_caller(new_size, flags); | ||
218 | if (ret) { | ||
219 | memcpy(ret, p, min(new_size, ksize(p))); | ||
220 | kfree(p); | ||
221 | } | ||
222 | return ret; | ||
223 | } | ||
224 | EXPORT_SYMBOL(krealloc); | ||
225 | |||
193 | void kfree(const void *block) | 226 | void kfree(const void *block) |
194 | { | 227 | { |
195 | bigblock_t *bb, **last = &bigblocks; | 228 | bigblock_t *bb, **last = &bigblocks; |
@@ -219,7 +252,7 @@ void kfree(const void *block) | |||
219 | 252 | ||
220 | EXPORT_SYMBOL(kfree); | 253 | EXPORT_SYMBOL(kfree); |
221 | 254 | ||
222 | unsigned int ksize(const void *block) | 255 | size_t ksize(const void *block) |
223 | { | 256 | { |
224 | bigblock_t *bb; | 257 | bigblock_t *bb; |
225 | unsigned long flags; | 258 | unsigned long flags; |