slub: make ->size unsigned int
authorAlexey Dobriyan <adobriyan@gmail.com>
Thu, 5 Apr 2018 23:21:20 +0000 (16:21 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 6 Apr 2018 04:36:24 +0000 (21:36 -0700)
Linux doesn't support negative length objects (including meta data).

Link: http://lkml.kernel.org/r/20180305200730.15812-18-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/slub_def.h
mm/slub.c

index 7d74f121ef4e46ce1e6fd0b0ecdb344c88368597..bc02fd3a8ccfcab0d14b09d625f331c6ca3d436e 100644 (file)
@@ -84,7 +84,7 @@ struct kmem_cache {
        /* Used for retriving partial slabs etc */
        slab_flags_t flags;
        unsigned long min_partial;
-       int size;               /* The size of an object including meta data */
+       unsigned int size;      /* The size of an object including meta data */
        unsigned int object_size;/* The size of an object without meta data */
        unsigned int offset;    /* Free pointer offset. */
 #ifdef CONFIG_SLUB_CPU_PARTIAL
index 7431cd548776c56fe6c460c5fac1064ed1ddb874..ee11896c2a13b24c106c606fbce0e9293e11900f 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2399,7 +2399,7 @@ slab_out_of_memory(struct kmem_cache *s, gfp_t gfpflags, int nid)
 
        pr_warn("SLUB: Unable to allocate memory on node %d, gfp=%#x(%pGg)\n",
                nid, gfpflags, &gfpflags);
-       pr_warn("  cache: %s, object size: %u, buffer size: %d, default order: %d, min order: %d\n",
+       pr_warn("  cache: %s, object size: %u, buffer size: %u, default order: %d, min order: %d\n",
                s->name, s->object_size, s->size, oo_order(s->oo),
                oo_order(s->min));
 
@@ -3633,8 +3633,8 @@ static int kmem_cache_open(struct kmem_cache *s, slab_flags_t flags)
        free_kmem_cache_nodes(s);
 error:
        if (flags & SLAB_PANIC)
-               panic("Cannot create slab %s size=%lu realsize=%u order=%u offset=%u flags=%lx\n",
-                     s->name, (unsigned long)s->size, s->size,
+               panic("Cannot create slab %s size=%u realsize=%u order=%u offset=%u flags=%lx\n",
+                     s->name, s->size, s->size,
                      oo_order(s->oo), s->offset, (unsigned long)flags);
        return -EINVAL;
 }
@@ -3825,7 +3825,7 @@ void __check_heap_object(const void *ptr, unsigned long n, struct page *page,
                         bool to_user)
 {
        struct kmem_cache *s;
-       unsigned long offset;
+       unsigned int offset;
        size_t object_size;
 
        /* Find object and usable object size. */
@@ -4889,7 +4889,7 @@ struct slab_attribute {
 
 static ssize_t slab_size_show(struct kmem_cache *s, char *buf)
 {
-       return sprintf(buf, "%d\n", s->size);
+       return sprintf(buf, "%u\n", s->size);
 }
 SLAB_ATTR_RO(slab_size);
 
@@ -5664,7 +5664,7 @@ static char *create_unique_id(struct kmem_cache *s)
                *p++ = 'A';
        if (p != name + 1)
                *p++ = '-';
-       p += sprintf(p, "%07d", s->size);
+       p += sprintf(p, "%07u", s->size);
 
        BUG_ON(p > name + ID_STR_LENGTH - 1);
        return name;