[PATCH 2/7] kfence: kunit: skip when no pool is available

From: Jia He

Date: Thu May 14 2026 - 01:08:49 EST


When KFENCE is compiled in but disabled at boot (KFENCE_SAMPLE_INTERVAL=0)
or __kfence_pool is not allocated, every kfence kunit case fails with
-EINVAL.

Use kunit_skip() so they are reported as skipped instead.

To: Alexander Potapenko <glider@xxxxxxxxxx>
To: Marco Elver <elver@xxxxxxxxxx>
To: Dmitry Vyukov <dvyukov@xxxxxxxxxx>
To: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: kasan-dev@xxxxxxxxxxxxxxxx
Cc: linux-mm@xxxxxxxxx

Signed-off-by: Jia He <justin.he@xxxxxxx>
---
mm/kfence/kfence_test.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/mm/kfence/kfence_test.c b/mm/kfence/kfence_test.c
index 5725a367246d..e376329dd621 100644
--- a/mm/kfence/kfence_test.c
+++ b/mm/kfence/kfence_test.c
@@ -822,8 +822,10 @@ static int test_init(struct kunit *test)
unsigned long flags;
int i;

- if (!__kfence_pool)
- return -EINVAL;
+ if (!__kfence_pool) {
+ kunit_skip(test, "kfence pool not allocated or kfence not enabled");
+ return 0;
+ }

spin_lock_irqsave(&observed.lock, flags);
for (i = 0; i < ARRAY_SIZE(observed.lines); i++)
--
2.34.1