[PATCH] kunit: minor cleanups in attribute filtering

From: Jiangshan Yi

Date: Thu Nov 19 2026 - 20:51:11 EST


kunit_filter_attr_tests() calls get_attr() twice for each test case;
reuse test_val for the filter() call.

In attr_enum_filter(), stop scanning str_list once the input value is
matched.

Signed-off-by: Jiangshan Yi <yijiangshan@xxxxxxxxxx>
---
lib/kunit/attributes.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/kunit/attributes.c b/lib/kunit/attributes.c
index 6d7a53af94a9..9ff04d2985f1 100644
--- a/lib/kunit/attributes.c
+++ b/lib/kunit/attributes.c
@@ -132,8 +132,10 @@ static int attr_enum_filter(void *attr, const char *input, int *err,
}

for (j = 0; j <= max; j++) {
- if (!strcmp(input_val, str_list[j]))
+ if (!strcmp(input_val, str_list[j])) {
input_int = j;
+ break;
+ }
}

if (input_int < 0) {
@@ -432,8 +434,7 @@ struct kunit_suite *kunit_filter_attr_tests(const struct kunit_suite *const suit
/* For each test case, save test case if passes filtering. */
kunit_suite_for_each_test_case(suite, test_case) {
test_val = filter.attr->get_attr((void *) test_case, true);
- test_result = filter.attr->filter(filter.attr->get_attr(test_case, true),
- filter.input, err);
+ test_result = filter.attr->filter(test_val, filter.input, err);
if (*err)
goto err;

--
2.25.1