Merge tag 'docs-5.0' of git://git.lwn.net/linux
[sfrench/cifs-2.6.git] / include / linux / slab.h
index 11bb14a7c069c9bf8e6c29f8c091d4ea6b8c3d7c..11b45f7ae4057c3b70105974b8f527dd6f30d8ba 100644 (file)
@@ -314,22 +314,22 @@ kmalloc_caches[NR_KMALLOC_TYPES][KMALLOC_SHIFT_HIGH + 1];
 
 static __always_inline enum kmalloc_cache_type kmalloc_type(gfp_t flags)
 {
-       int is_dma = 0;
-       int type_dma = 0;
-       int is_reclaimable;
-
 #ifdef CONFIG_ZONE_DMA
-       is_dma = !!(flags & __GFP_DMA);
-       type_dma = is_dma * KMALLOC_DMA;
-#endif
-
-       is_reclaimable = !!(flags & __GFP_RECLAIMABLE);
+       /*
+        * The most common case is KMALLOC_NORMAL, so test for it
+        * with a single branch for both flags.
+        */
+       if (likely((flags & (__GFP_DMA | __GFP_RECLAIMABLE)) == 0))
+               return KMALLOC_NORMAL;
 
        /*
-        * If an allocation is both __GFP_DMA and __GFP_RECLAIMABLE, return
-        * KMALLOC_DMA and effectively ignore __GFP_RECLAIMABLE
+        * At least one of the flags has to be set. If both are, __GFP_DMA
+        * is more important.
         */
-       return type_dma + (is_reclaimable & !is_dma) * KMALLOC_RECLAIM;
+       return flags & __GFP_DMA ? KMALLOC_DMA : KMALLOC_RECLAIM;
+#else
+       return flags & __GFP_RECLAIMABLE ? KMALLOC_RECLAIM : KMALLOC_NORMAL;
+#endif
 }
 
 /*
@@ -444,7 +444,7 @@ static __always_inline void *kmem_cache_alloc_trace(struct kmem_cache *s,
 {
        void *ret = kmem_cache_alloc(s, flags);
 
-       kasan_kmalloc(s, ret, size, flags);
+       ret = kasan_kmalloc(s, ret, size, flags);
        return ret;
 }
 
@@ -455,7 +455,7 @@ kmem_cache_alloc_node_trace(struct kmem_cache *s,
 {
        void *ret = kmem_cache_alloc_node(s, gfpflags, node);
 
-       kasan_kmalloc(s, ret, size, gfpflags);
+       ret = kasan_kmalloc(s, ret, size, gfpflags);
        return ret;
 }
 #endif /* CONFIG_TRACING */