Commit ac914d08 authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by Linus Torvalds

slab: make size_index_elem() unsigned int

size_index_elem() always works with small sizes (kmalloc caches are
32-bit) and returns small indexes.

Link: http://lkml.kernel.org/r/20180305200730.15812-8-adobriyan@gmail.comSigned-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Acked-by: default avatarChristoph 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d5f86655
...@@ -998,7 +998,7 @@ static u8 size_index[24] __ro_after_init = { ...@@ -998,7 +998,7 @@ static u8 size_index[24] __ro_after_init = {
2 /* 192 */ 2 /* 192 */
}; };
static inline int size_index_elem(size_t bytes) static inline unsigned int size_index_elem(unsigned int bytes)
{ {
return (bytes - 1) / 8; return (bytes - 1) / 8;
} }
...@@ -1067,13 +1067,13 @@ const struct kmalloc_info_struct kmalloc_info[] __initconst = { ...@@ -1067,13 +1067,13 @@ const struct kmalloc_info_struct kmalloc_info[] __initconst = {
*/ */
void __init setup_kmalloc_cache_index_table(void) void __init setup_kmalloc_cache_index_table(void)
{ {
int i; unsigned int i;
BUILD_BUG_ON(KMALLOC_MIN_SIZE > 256 || BUILD_BUG_ON(KMALLOC_MIN_SIZE > 256 ||
(KMALLOC_MIN_SIZE & (KMALLOC_MIN_SIZE - 1))); (KMALLOC_MIN_SIZE & (KMALLOC_MIN_SIZE - 1)));
for (i = 8; i < KMALLOC_MIN_SIZE; i += 8) { for (i = 8; i < KMALLOC_MIN_SIZE; i += 8) {
int elem = size_index_elem(i); unsigned int elem = size_index_elem(i);
if (elem >= ARRAY_SIZE(size_index)) if (elem >= ARRAY_SIZE(size_index))
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment