diff options
-rw-r--r-- | include/linux/slab.h | 30 | ||||
-rw-r--r-- | mm/util.c | 6 |
2 files changed, 30 insertions, 6 deletions
diff --git a/include/linux/slab.h b/include/linux/slab.h index 1216b09e07b1..15e1d9736b1b 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h | |||
@@ -110,7 +110,30 @@ found: | |||
110 | return __kmalloc(size, flags); | 110 | return __kmalloc(size, flags); |
111 | } | 111 | } |
112 | 112 | ||
113 | extern void *kzalloc(size_t, gfp_t); | 113 | extern void *__kzalloc(size_t, gfp_t); |
114 | |||
115 | static inline void *kzalloc(size_t size, gfp_t flags) | ||
116 | { | ||
117 | if (__builtin_constant_p(size)) { | ||
118 | int i = 0; | ||
119 | #define CACHE(x) \ | ||
120 | if (size <= x) \ | ||
121 | goto found; \ | ||
122 | else \ | ||
123 | i++; | ||
124 | #include "kmalloc_sizes.h" | ||
125 | #undef CACHE | ||
126 | { | ||
127 | extern void __you_cannot_kzalloc_that_much(void); | ||
128 | __you_cannot_kzalloc_that_much(); | ||
129 | } | ||
130 | found: | ||
131 | return kmem_cache_zalloc((flags & GFP_DMA) ? | ||
132 | malloc_sizes[i].cs_dmacachep : | ||
133 | malloc_sizes[i].cs_cachep, flags); | ||
134 | } | ||
135 | return __kzalloc(size, flags); | ||
136 | } | ||
114 | 137 | ||
115 | /** | 138 | /** |
116 | * kcalloc - allocate memory for an array. The memory is set to zero. | 139 | * kcalloc - allocate memory for an array. The memory is set to zero. |
@@ -161,14 +184,14 @@ void *kmem_cache_zalloc(struct kmem_cache *, gfp_t); | |||
161 | void kmem_cache_free(struct kmem_cache *c, void *b); | 184 | void kmem_cache_free(struct kmem_cache *c, void *b); |
162 | const char *kmem_cache_name(struct kmem_cache *); | 185 | const char *kmem_cache_name(struct kmem_cache *); |
163 | void *kmalloc(size_t size, gfp_t flags); | 186 | void *kmalloc(size_t size, gfp_t flags); |
164 | void *kzalloc(size_t size, gfp_t flags); | 187 | void *__kzalloc(size_t size, gfp_t flags); |
165 | void kfree(const void *m); | 188 | void kfree(const void *m); |
166 | unsigned int ksize(const void *m); | 189 | unsigned int ksize(const void *m); |
167 | unsigned int kmem_cache_size(struct kmem_cache *c); | 190 | unsigned int kmem_cache_size(struct kmem_cache *c); |
168 | 191 | ||
169 | static inline void *kcalloc(size_t n, size_t size, gfp_t flags) | 192 | static inline void *kcalloc(size_t n, size_t size, gfp_t flags) |
170 | { | 193 | { |
171 | return kzalloc(n * size, flags); | 194 | return __kzalloc(n * size, flags); |
172 | } | 195 | } |
173 | 196 | ||
174 | #define kmem_cache_shrink(d) (0) | 197 | #define kmem_cache_shrink(d) (0) |
@@ -176,6 +199,7 @@ static inline void *kcalloc(size_t n, size_t size, gfp_t flags) | |||
176 | #define kmem_ptr_validate(a, b) (0) | 199 | #define kmem_ptr_validate(a, b) (0) |
177 | #define kmem_cache_alloc_node(c, f, n) kmem_cache_alloc(c, f) | 200 | #define kmem_cache_alloc_node(c, f, n) kmem_cache_alloc(c, f) |
178 | #define kmalloc_node(s, f, n) kmalloc(s, f) | 201 | #define kmalloc_node(s, f, n) kmalloc(s, f) |
202 | #define kzalloc(s, f) __kzalloc(s, f) | ||
179 | #define ____kmalloc kmalloc | 203 | #define ____kmalloc kmalloc |
180 | 204 | ||
181 | #endif /* CONFIG_SLOB */ | 205 | #endif /* CONFIG_SLOB */ |
@@ -5,18 +5,18 @@ | |||
5 | #include <asm/uaccess.h> | 5 | #include <asm/uaccess.h> |
6 | 6 | ||
7 | /** | 7 | /** |
8 | * kzalloc - allocate memory. The memory is set to zero. | 8 | * __kzalloc - allocate memory. The memory is set to zero. |
9 | * @size: how many bytes of memory are required. | 9 | * @size: how many bytes of memory are required. |
10 | * @flags: the type of memory to allocate. | 10 | * @flags: the type of memory to allocate. |
11 | */ | 11 | */ |
12 | void *kzalloc(size_t size, gfp_t flags) | 12 | void *__kzalloc(size_t size, gfp_t flags) |
13 | { | 13 | { |
14 | void *ret = ____kmalloc(size, flags); | 14 | void *ret = ____kmalloc(size, flags); |
15 | if (ret) | 15 | if (ret) |
16 | memset(ret, 0, size); | 16 | memset(ret, 0, size); |
17 | return ret; | 17 | return ret; |
18 | } | 18 | } |
19 | EXPORT_SYMBOL(kzalloc); | 19 | EXPORT_SYMBOL(__kzalloc); |
20 | 20 | ||
21 | /* | 21 | /* |
22 | * kstrdup - allocate space for and copy an existing string | 22 | * kstrdup - allocate space for and copy an existing string |