From: Miao Tianzhong <3514767322@qq.com>
To: brendan.higgins@linux.dev, david@davidgow.net
Cc: raemoar63@gmail.com, linux-kselftest@vger.kernel.org,
kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org,
Miao Tianzhong <3514767322@qq.com>,
stable@vger.kernel.org
Subject: [PATCH 1/3] kunit: fix filter attribute list parsing with a trailing comma
Date: Fri, 4 Dec 2026 10:57:20 +0800 [thread overview]
Message-ID: <tencent_5C7E208CED5F5B5205B8CBB14C4DD113F805@qq.com> (raw)
In-Reply-To: <cover.1796351229.git.3514767322@qq.com>
kunit.filter_attr= takes a comma separated list of attribute filters.
When the list ends with a comma (e.g. "kunit.filter_attr=speed=slow,")
kunit_get_filter_count() counts the empty trailing segment as an extra
filter, and kunit_next_attr_filter() then leaves the cursor pointing at
the beginning of the string instead of terminating the list, so the same
filter is parsed and applied twice.
Only count segments that contain a filter, and terminate the list in
kunit_next_attr_filter() when nothing but whitespace follows the last
comma.
Fixes: 529534e8cba3 ("kunit: Add ability to filter attributes")
Cc: stable@vger.kernel.org
Signed-off-by: Miao Tianzhong <3514767322@qq.com>
---
lib/kunit/attributes.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/lib/kunit/attributes.c b/lib/kunit/attributes.c
index 6d7a53af94a9..9d368a2844d8 100644
--- a/lib/kunit/attributes.c
+++ b/lib/kunit/attributes.c
@@ -319,17 +319,21 @@ void kunit_print_attr(void *test_or_suite, bool is_test, unsigned int test_level
int kunit_get_filter_count(char *input)
{
- int i, comma_index = 0, count = 0;
+ int i, count = 0;
+ bool has_content = false;
for (i = 0; input[i]; i++) {
if (input[i] == ',') {
- if ((i - comma_index) > 1)
+ if (has_content)
count++;
- comma_index = i;
+ has_content = false;
+ } else if (input[i] != ' ') {
+ has_content = true;
}
}
- if ((i - comma_index) > 0)
+ if (has_content)
count++;
+
return count;
}
@@ -383,7 +387,14 @@ struct kunit_attr_filter kunit_next_attr_filter(char **filters, int *err)
if (comma_index > 0) {
input[comma_index] = '\0';
filter.input = input + op_index;
- input = input + new_start_index;
+ /*
+ * Nothing but whitespace after the last comma: the filter
+ * list ends here.
+ */
+ if (new_start_index > comma_index)
+ input = input + new_start_index;
+ else
+ input = NULL;
} else {
filter.input = input + op_index;
input = NULL;
--
2.56.1
next parent reply other threads:[~2026-12-04 2:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1796351229.git.3514767322@qq.com>
2026-12-04 2:57 ` Miao Tianzhong [this message]
2026-12-04 5:27 ` Aveline Noir
2026-12-04 2:57 ` [PATCH 2/3] kunit: fix NULL pointer dereference when filtering on module Miao Tianzhong
2026-12-04 5:22 ` Aveline Noir
2026-12-04 2:57 ` [PATCH 3/3] kunit: add tests for the test attribute API Miao Tianzhong
2026-12-04 5:32 ` Aveline Noir
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_5C7E208CED5F5B5205B8CBB14C4DD113F805@qq.com \
--to=3514767322@qq.com \
--cc=brendan.higgins@linux.dev \
--cc=david@davidgow.net \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=raemoar63@gmail.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®