Skip to content

Commit

Permalink
slub: kunit catch kmem_cache_alloc failed
Browse files Browse the repository at this point in the history
Catch kmem_cache_alloc failed on slub kunit test.

Signed-off-by: Paran Lee <p4ranlee@gmail.com>
  • Loading branch information
paranlee authored and intel-lab-lkp committed May 6, 2022
1 parent fe27d18 commit 4827e15
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/slub_kunit.c
Expand Up @@ -32,6 +32,11 @@ static void test_next_pointer(struct kunit *test)
struct kmem_cache *s = kmem_cache_create("TestSlub_next_ptr_free", 64, 0,
SLAB_POISON, NULL);
u8 *p = kmem_cache_alloc(s, GFP_KERNEL);
if (!p) {
kunit_err(test, "Allocation failed: %s\n", __func__);
kmem_cache_destroy(s);
return;
}
unsigned long tmp;
unsigned long *ptr_addr;

Expand Down Expand Up @@ -77,6 +82,11 @@ static void test_first_word(struct kunit *test)
struct kmem_cache *s = kmem_cache_create("TestSlub_1th_word_free", 64, 0,
SLAB_POISON, NULL);
u8 *p = kmem_cache_alloc(s, GFP_KERNEL);
if (!p) {
kunit_err(test, "Allocation failed: %s\n", __func__);
kmem_cache_destroy(s);
return;
}

kmem_cache_free(s, p);
*p = 0x78;
Expand All @@ -92,6 +102,11 @@ static void test_clobber_50th_byte(struct kunit *test)
struct kmem_cache *s = kmem_cache_create("TestSlub_50th_word_free", 64, 0,
SLAB_POISON, NULL);
u8 *p = kmem_cache_alloc(s, GFP_KERNEL);
if (!p) {
kunit_err(test, "Allocation failed: %s\n", __func__);
kmem_cache_destroy(s);
return;
}

kmem_cache_free(s, p);
p[50] = 0x9a;
Expand All @@ -108,6 +123,11 @@ static void test_clobber_redzone_free(struct kunit *test)
struct kmem_cache *s = kmem_cache_create("TestSlub_RZ_free", 64, 0,
SLAB_RED_ZONE, NULL);
u8 *p = kmem_cache_alloc(s, GFP_KERNEL);
if (!p) {
kunit_err(test, "Allocation failed: %s\n", __func__);
kmem_cache_destroy(s);
return;
}

kasan_disable_current();
kmem_cache_free(s, p);
Expand Down

0 comments on commit 4827e15

Please sign in to comment.