Skip to content

Commit

Permalink
lib/test_meminit.c: minor test fixes
Browse files Browse the repository at this point in the history
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/[email protected]
Fixes: 7e65965 ("lib: introduce test_meminit module")
Fixes: 94e8988 ("lib/test_meminit.c: fix -Wmaybe-uninitialized false positive")
Signed-off-by: Alexander Potapenko <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Kees Cook <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
ramosian-glider authored and torvalds committed Jul 17, 2019
1 parent d3a8116 commit 4ab7ace
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/test_meminit.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ static int __init count_nonzero_bytes(void *ptr, size_t size)
}

/* 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;

if (skip) {
WARN_ON(skip > size);
p += skip;
}
WARN_ON(skip > size);
size -= skip;

while (size >= sizeof(*p)) {
p[i] = GARBAGE_INT;
i++;
Expand Down Expand Up @@ -227,6 +226,7 @@ static int __init do_kmem_cache_size(size_t size, bool want_ctor,
if (buf_copy)
memcpy(buf_copy, buf, size);

kmem_cache_free(c, buf);
/*
* Check that |buf| is intact after kmem_cache_free().
* |want_zero| is false, because we wrote garbage to
Expand Down

0 comments on commit 4ab7ace

Please sign in to comment.