tools headers UAPI: Sync linux/prctl.h with the kernel sources
[linux-2.6-microblaze.git] / mm / slab.h
index c30ed35..18c1927 100644 (file)
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -506,15 +506,24 @@ static inline struct kmem_cache *slab_pre_alloc_hook(struct kmem_cache *s,
 }
 
 static inline void slab_post_alloc_hook(struct kmem_cache *s,
-                                       struct obj_cgroup *objcg,
-                                       gfp_t flags, size_t size, void **p)
+                                       struct obj_cgroup *objcg, gfp_t flags,
+                                       size_t size, void **p, bool init)
 {
        size_t i;
 
        flags &= gfp_allowed_mask;
+
+       /*
+        * As memory initialization might be integrated into KASAN,
+        * kasan_slab_alloc and initialization memset must be
+        * kept together to avoid discrepancies in behavior.
+        *
+        * As p[i] might get tagged, memset and kmemleak hook come after KASAN.
+        */
        for (i = 0; i < size; i++) {
-               p[i] = kasan_slab_alloc(s, p[i], flags);
-               /* As p[i] might get tagged, call kmemleak hook after KASAN. */
+               p[i] = kasan_slab_alloc(s, p[i], flags, init);
+               if (p[i] && init && !kasan_has_integrated_init())
+                       memset(p[i], 0, s->object_size);
                kmemleak_alloc_recursive(p[i], s->object_size, 1,
                                         s->flags, flags);
        }