diff options
Diffstat (limited to 'mm/util.c')
-rw-r--r-- | mm/util.c | 35 |
1 files changed, 21 insertions, 14 deletions
@@ -105,6 +105,25 @@ void *memdup_user(const void __user *src, size_t len) | |||
105 | } | 105 | } |
106 | EXPORT_SYMBOL(memdup_user); | 106 | EXPORT_SYMBOL(memdup_user); |
107 | 107 | ||
108 | static __always_inline void *__do_krealloc(const void *p, size_t new_size, | ||
109 | gfp_t flags) | ||
110 | { | ||
111 | void *ret; | ||
112 | size_t ks = 0; | ||
113 | |||
114 | if (p) | ||
115 | ks = ksize(p); | ||
116 | |||
117 | if (ks >= new_size) | ||
118 | return (void *)p; | ||
119 | |||
120 | ret = kmalloc_track_caller(new_size, flags); | ||
121 | if (ret && p) | ||
122 | memcpy(ret, p, ks); | ||
123 | |||
124 | return ret; | ||
125 | } | ||
126 | |||
108 | /** | 127 | /** |
109 | * __krealloc - like krealloc() but don't free @p. | 128 | * __krealloc - like krealloc() but don't free @p. |
110 | * @p: object to reallocate memory for. | 129 | * @p: object to reallocate memory for. |
@@ -117,23 +136,11 @@ EXPORT_SYMBOL(memdup_user); | |||
117 | */ | 136 | */ |
118 | void *__krealloc(const void *p, size_t new_size, gfp_t flags) | 137 | void *__krealloc(const void *p, size_t new_size, gfp_t flags) |
119 | { | 138 | { |
120 | void *ret; | ||
121 | size_t ks = 0; | ||
122 | |||
123 | if (unlikely(!new_size)) | 139 | if (unlikely(!new_size)) |
124 | return ZERO_SIZE_PTR; | 140 | return ZERO_SIZE_PTR; |
125 | 141 | ||
126 | if (p) | 142 | return __do_krealloc(p, new_size, flags); |
127 | ks = ksize(p); | ||
128 | 143 | ||
129 | if (ks >= new_size) | ||
130 | return (void *)p; | ||
131 | |||
132 | ret = kmalloc_track_caller(new_size, flags); | ||
133 | if (ret && p) | ||
134 | memcpy(ret, p, ks); | ||
135 | |||
136 | return ret; | ||
137 | } | 144 | } |
138 | EXPORT_SYMBOL(__krealloc); | 145 | EXPORT_SYMBOL(__krealloc); |
139 | 146 | ||
@@ -157,7 +164,7 @@ void *krealloc(const void *p, size_t new_size, gfp_t flags) | |||
157 | return ZERO_SIZE_PTR; | 164 | return ZERO_SIZE_PTR; |
158 | } | 165 | } |
159 | 166 | ||
160 | ret = __krealloc(p, new_size, flags); | 167 | ret = __do_krealloc(p, new_size, flags); |
161 | if (ret && p != ret) | 168 | if (ret && p != ret) |
162 | kfree(p); | 169 | kfree(p); |
163 | 170 | ||