Commit 4ab7ace4 authored by Alexander Potapenko's avatar Alexander Potapenko Committed by Linus Torvalds

lib/test_meminit.c: minor test fixes

Fix the following issues in test_meminit.c:
 - |size| in fill_with_garbage_skip() should be signed so that it
   doesn't overflow if it's not aligned on sizeof(*p);
 - fill_with_garbage_skip() should actually skip |skip| bytes;
 - do_kmem_cache_size() should deallocate memory in the RCU case.

Link: http://lkml.kernel.org/r/20190626133135.217355-1-glider@google.com
Fixes: 7e659650cbda ("lib: introduce test_meminit module")
Fixes: 94e8988d91c7 ("lib/test_meminit.c: fix -Wmaybe-uninitialized false positive")
Signed-off-by: default avatarAlexander Potapenko <glider@google.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d3a81161
...@@ -38,15 +38,14 @@ static int __init count_nonzero_bytes(void *ptr, size_t size) ...@@ -38,15 +38,14 @@ static int __init count_nonzero_bytes(void *ptr, size_t size)
} }
/* Fill a buffer with garbage, skipping |skip| first bytes. */ /* Fill a buffer with garbage, skipping |skip| first bytes. */
static void __init fill_with_garbage_skip(void *ptr, size_t size, size_t skip) static void __init fill_with_garbage_skip(void *ptr, int size, size_t skip)
{ {
unsigned int *p = (unsigned int *)ptr; unsigned int *p = (unsigned int *)((char *)ptr + skip);
int i = 0; int i = 0;
if (skip) {
WARN_ON(skip > size); WARN_ON(skip > size);
p += skip; size -= skip;
}
while (size >= sizeof(*p)) { while (size >= sizeof(*p)) {
p[i] = GARBAGE_INT; p[i] = GARBAGE_INT;
i++; i++;
...@@ -227,6 +226,7 @@ static int __init do_kmem_cache_size(size_t size, bool want_ctor, ...@@ -227,6 +226,7 @@ static int __init do_kmem_cache_size(size_t size, bool want_ctor,
if (buf_copy) if (buf_copy)
memcpy(buf_copy, buf, size); memcpy(buf_copy, buf, size);
kmem_cache_free(c, buf);
/* /*
* Check that |buf| is intact after kmem_cache_free(). * Check that |buf| is intact after kmem_cache_free().
* |want_zero| is false, because we wrote garbage to * |want_zero| is false, because we wrote garbage to
......
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