aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
Diffstat (limited to 'mm')
-rw-r--r--mm/slub.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/mm/slub.c b/mm/slub.c
index 1832ae1ea536..5d425d7116e8 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2199,9 +2199,8 @@ EXPORT_SYMBOL(kmem_cache_shrink);
2199 */ 2199 */
2200void *krealloc(const void *p, size_t new_size, gfp_t flags) 2200void *krealloc(const void *p, size_t new_size, gfp_t flags)
2201{ 2201{
2202 struct kmem_cache *new_cache;
2203 void *ret; 2202 void *ret;
2204 struct page *page; 2203 size_t ks;
2205 2204
2206 if (unlikely(!p)) 2205 if (unlikely(!p))
2207 return kmalloc(new_size, flags); 2206 return kmalloc(new_size, flags);
@@ -2211,19 +2210,13 @@ void *krealloc(const void *p, size_t new_size, gfp_t flags)
2211 return NULL; 2210 return NULL;
2212 } 2211 }
2213 2212
2214 page = virt_to_head_page(p); 2213 ks = ksize(p);
2215 2214 if (ks >= new_size)
2216 new_cache = get_slab(new_size, flags);
2217
2218 /*
2219 * If new size fits in the current cache, bail out.
2220 */
2221 if (likely(page->slab == new_cache))
2222 return (void *)p; 2215 return (void *)p;
2223 2216
2224 ret = kmalloc(new_size, flags); 2217 ret = kmalloc(new_size, flags);
2225 if (ret) { 2218 if (ret) {
2226 memcpy(ret, p, min(new_size, ksize(p))); 2219 memcpy(ret, p, min(new_size, ks));
2227 kfree(p); 2220 kfree(p);
2228 } 2221 }
2229 return ret; 2222 return ret;