Commit d3a81161 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Linus Torvalds

lib/test_meminit.c: fix -Wmaybe-uninitialized false positive

The conditional logic is too complicated for the compiler to fully
comprehend:

  lib/test_meminit.c: In function 'test_meminit_init':
  lib/test_meminit.c:236:5: error: 'buf_copy' may be used uninitialized in this function [-Werror=maybe-uninitialized]
       kfree(buf_copy);
       ^~~~~~~~~~~~~~~
  lib/test_meminit.c:201:14: note: 'buf_copy' was declared here

Simplify it by splitting out the non-rcu section.

Link: http://lkml.kernel.org/r/20190617131210.2190280-1-arnd@arndb.de
Fixes: af734ee6ec85 ("lib: introduce test_meminit module")
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Acked-by: default avatarAlexander Potapenko <glider@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b4658cdd
...@@ -208,11 +208,16 @@ static int __init do_kmem_cache_size(size_t size, bool want_ctor, ...@@ -208,11 +208,16 @@ static int __init do_kmem_cache_size(size_t size, bool want_ctor,
/* Check that buf is zeroed, if it must be. */ /* Check that buf is zeroed, if it must be. */
fail = check_buf(buf, size, want_ctor, want_rcu, want_zero); fail = check_buf(buf, size, want_ctor, want_rcu, want_zero);
fill_with_garbage_skip(buf, size, want_ctor ? CTOR_BYTES : 0); fill_with_garbage_skip(buf, size, want_ctor ? CTOR_BYTES : 0);
if (!want_rcu) {
kmem_cache_free(c, buf);
continue;
}
/* /*
* If this is an RCU cache, use a critical section to ensure we * If this is an RCU cache, use a critical section to ensure we
* can touch objects after they're freed. * can touch objects after they're freed.
*/ */
if (want_rcu) {
rcu_read_lock(); rcu_read_lock();
/* /*
* Copy the buffer to check that it's not wiped on * Copy the buffer to check that it's not wiped on
...@@ -221,9 +226,7 @@ static int __init do_kmem_cache_size(size_t size, bool want_ctor, ...@@ -221,9 +226,7 @@ static int __init do_kmem_cache_size(size_t size, bool want_ctor,
buf_copy = kmalloc(size, GFP_KERNEL); buf_copy = kmalloc(size, GFP_KERNEL);
if (buf_copy) if (buf_copy)
memcpy(buf_copy, buf, size); memcpy(buf_copy, buf, size);
}
kmem_cache_free(c, buf);
if (want_rcu) {
/* /*
* 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
...@@ -237,7 +240,6 @@ static int __init do_kmem_cache_size(size_t size, bool want_ctor, ...@@ -237,7 +240,6 @@ static int __init do_kmem_cache_size(size_t size, bool want_ctor,
} }
rcu_read_unlock(); rcu_read_unlock();
} }
}
kmem_cache_destroy(c); kmem_cache_destroy(c);
*total_failures += fail; *total_failures += fail;
......
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