slab: make kmalloc_size() return "unsigned int"
authorAlexey Dobriyan <adobriyan@gmail.com>
Thu, 5 Apr 2018 23:20:26 +0000 (16:20 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 6 Apr 2018 04:36:23 +0000 (21:36 -0700)
kmalloc_size() derives size of kmalloc cache from internal index, which
can't be negative.

Propagate unsignedness a bit.

Link: http://lkml.kernel.org/r/20180305200730.15812-3-adobriyan@gmail.com
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Acked-by: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/slab.h
mm/slab_common.c

index 296f33a512eb424ccf4b71f8ede11b60e57332c5..ad157fbf38869d7a36e08647c29ceb29c01f7762 100644 (file)
@@ -522,11 +522,11 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
  * return size or 0 if a kmalloc cache for that
  * size does not exist
  */
-static __always_inline int kmalloc_size(int n)
+static __always_inline unsigned int kmalloc_size(unsigned int n)
 {
 #ifndef CONFIG_SLOB
        if (n > 2)
-               return 1 << n;
+               return 1U << n;
 
        if (n == 1 && KMALLOC_MIN_SIZE <= 32)
                return 96;
index 7626a64b8f14e1db4bd042e6f7080f39dfa262a5..d3f4209c297ddb7656a8a0328a622556193299e5 100644 (file)
@@ -1138,9 +1138,9 @@ void __init create_kmalloc_caches(slab_flags_t flags)
                struct kmem_cache *s = kmalloc_caches[i];
 
                if (s) {
-                       int size = kmalloc_size(i);
+                       unsigned int size = kmalloc_size(i);
                        char *n = kasprintf(GFP_NOWAIT,
-                                "dma-kmalloc-%d", size);
+                                "dma-kmalloc-%u", size);
 
                        BUG_ON(!n);
                        kmalloc_dma_caches[i] = create_kmalloc_cache(n,