aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiaoke Wang <[email protected]>2022-04-29 14:38:00 -0700
committerakpm <[email protected]>2022-04-29 14:38:00 -0700
commitd4557fae77079f4e53f06712395c7a28e3734eb7 (patch)
tree71aa8977c3720914a67869e23723b06291891506
parent11fb48961e5250768767612da4a303fa2f5ea504 (diff)
lib/test_meminit: optimize do_kmem_cache_rcu_persistent() test
To make the test more robust, there are the following changes: 1. add a check for the return value of kmem_cache_alloc(). 2. properly release the object `buf` on several error paths. 3. release the objects of `used_objects` if we never hit `saved_ptr`. 4. destroy the created cache by default. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Xiaoke Wang <[email protected]> Reviewed-by: Andrew Morton <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Andrey Konovalov <[email protected]> Cc: Marco Elver <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Xiaoke Wang <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
-rw-r--r--lib/test_meminit.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/test_meminit.c b/lib/test_meminit.c
index 3ca717f11397..c95db11a6906 100644
--- a/lib/test_meminit.c
+++ b/lib/test_meminit.c
@@ -279,13 +279,18 @@ static int __init do_kmem_cache_rcu_persistent(int size, int *total_failures)
c = kmem_cache_create("test_cache", size, size, SLAB_TYPESAFE_BY_RCU,
NULL);
buf = kmem_cache_alloc(c, GFP_KERNEL);
+ if (!buf)
+ goto out;
saved_ptr = buf;
fill_with_garbage(buf, size);
buf_contents = kmalloc(size, GFP_KERNEL);
- if (!buf_contents)
+ if (!buf_contents) {
+ kmem_cache_free(c, buf);
goto out;
+ }
used_objects = kmalloc_array(maxiter, sizeof(void *), GFP_KERNEL);
if (!used_objects) {
+ kmem_cache_free(c, buf);
kfree(buf_contents);
goto out;
}
@@ -306,11 +311,14 @@ static int __init do_kmem_cache_rcu_persistent(int size, int *total_failures)
}
}
+ for (iter = 0; iter < maxiter; iter++)
+ kmem_cache_free(c, used_objects[iter]);
+
free_out:
- kmem_cache_destroy(c);
kfree(buf_contents);
kfree(used_objects);
out:
+ kmem_cache_destroy(c);
*total_failures += fail;
return 1;
}