aboutsummaryrefslogtreecommitdiffstats
path: root/mm/util.c
diff options
context:
space:
mode:
authorEzequiel Garcia <elezegarcia@gmail.com>2012-08-14 08:55:21 -0400
committerPekka Enberg <penberg@kernel.org>2012-09-04 03:22:58 -0400
commite21827aadd77e33833eeb393de2e8675e9b399e2 (patch)
treecce83f2c211fd657a37fc7adc3e0718eb4175882 /mm/util.c
parent5b74beb425e0eb009d16d4b9a0f55847a5f342fa (diff)
mm: Use __do_krealloc to do the krealloc job
Without this patch we can get (many) kmem trace events with call site at krealloc(). This happens because krealloc is calling __krealloc, which performs the allocation through kmalloc_track_caller. Since neither krealloc nor __krealloc are marked inline explicitly, the caller can be traced as being krealloc, which clearly is not the intended behavior. This patch allows to get the real caller of krealloc, by creating an always inlined function __do_krealloc, thus tracing the call site accurately. Acked-by: Christoph Lameter <cl@linux.com> Cc: Glauber Costa <glommer@parallels.com> Signed-off-by: Ezequiel Garcia <elezegarcia@gmail.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Diffstat (limited to 'mm/util.c')
-rw-r--r--mm/util.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/mm/util.c b/mm/util.c
index 8c7265afa29f..dc3036cdcc6a 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -105,6 +105,25 @@ void *memdup_user(const void __user *src, size_t len)
105} 105}
106EXPORT_SYMBOL(memdup_user); 106EXPORT_SYMBOL(memdup_user);
107 107
108static __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 */
118void *__krealloc(const void *p, size_t new_size, gfp_t flags) 137void *__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}
138EXPORT_SYMBOL(__krealloc); 145EXPORT_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