aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorArnd Bergmann2019-07-16 16:27:39 -0700
committerLinus Torvalds2019-07-16 19:23:22 -0700
commitd3a811617ae629d7c0c5b7f0b7b0a72715ae3407 (patch)
tree2e9b27f772146fee8a0202333a2cee8b250f9ced /lib
parentb4658cdd8cab49c978334dc5db9070d0d881e3dd (diff)
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: Arnd Bergmann <arnd@arndb.de> Acked-by: Alexander Potapenko <glider@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/test_meminit.c50
1 files changed, 26 insertions, 24 deletions
diff --git a/lib/test_meminit.c b/lib/test_meminit.c
index ed7efec1387b..7ae2183ff1f4 100644
--- a/lib/test_meminit.c
+++ b/lib/test_meminit.c
@@ -208,35 +208,37 @@ static int __init do_kmem_cache_size(size_t size, bool want_ctor,
/* Check that buf is zeroed, if it must be. */
fail = check_buf(buf, size, want_ctor, want_rcu, want_zero);
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
* can touch objects after they're freed.
*/
- if (want_rcu) {
- rcu_read_lock();
- /*
- * Copy the buffer to check that it's not wiped on
- * free().
- */
- buf_copy = kmalloc(size, GFP_KERNEL);
- if (buf_copy)
- memcpy(buf_copy, buf, size);
- }
- kmem_cache_free(c, buf);
- if (want_rcu) {
- /*
- * Check that |buf| is intact after kmem_cache_free().
- * |want_zero| is false, because we wrote garbage to
- * the buffer already.
- */
- fail |= check_buf(buf, size, want_ctor, want_rcu,
- false);
- if (buf_copy) {
- fail |= (bool)memcmp(buf, buf_copy, size);
- kfree(buf_copy);
- }
- rcu_read_unlock();
+ rcu_read_lock();
+ /*
+ * Copy the buffer to check that it's not wiped on
+ * free().
+ */
+ buf_copy = kmalloc(size, GFP_KERNEL);
+ if (buf_copy)
+ memcpy(buf_copy, buf, size);
+
+ /*
+ * Check that |buf| is intact after kmem_cache_free().
+ * |want_zero| is false, because we wrote garbage to
+ * the buffer already.
+ */
+ fail |= check_buf(buf, size, want_ctor, want_rcu,
+ false);
+ if (buf_copy) {
+ fail |= (bool)memcmp(buf, buf_copy, size);
+ kfree(buf_copy);
}
+ rcu_read_unlock();
}
kmem_cache_destroy(c);