From: Jim Cromie <jim.cromie@gmail.com>
To: Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Arnd Bergmann <arnd@arndb.de>, Jason Baron <jbaron@akamai.com>,
Luis Chamberlain <mcgrof@kernel.org>,
Petr Pavlu <petr.pavlu@suse.com>,
Daniel Gomez <da.gomez@kernel.org>,
Sami Tolvanen <samitolvanen@google.com>,
Aaron Tomlin <atomlin@atomlin.com>,
Andrew Morton <akpm@linux-foundation.org>,
Shuah Khan <shuah@kernel.org>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arch@vger.kernel.org, linux-modules@vger.kernel.org,
linux-kselftest@vger.kernel.org, dri-devel@lists.freedesktop.org,
Jim Cromie <jim.cromie@gmail.com>
Subject: [PATCH v4 24/25] lib/parser: add match_wildcard_hyphen() for agnostic matching
Date: Tue, 02 Jun 2026 22:48:21 +0000 [thread overview]
Message-ID: <20260602-dd-maint-2-v4-24-19a1445585a8@gmail.com> (raw)
In-Reply-To: <20260602-dd-maint-2-v4-0-19a1445585a8@gmail.com>
This commit introduces match_wildcard_hyphen() as a variant of the
existing match_wildcard() function. It treats hyphens and underscores
as identical characters during the matching process.
This is necessary for subsystems like dynamic_debug that need to match
module names provided by users (who often use underscores) against
names stored in the kernel (which may use hyphens, especially when
using KBUILD_MODFILE for built-ins).
To avoid code duplication, the core logic is refactored into a private
__match_wildcard() function marked as __always_inline. This allows the
compiler to generate optimized versions for both the strict and agnostic
callsites with zero runtime overhead.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
include/linux/parser.h | 1 +
lib/parser.c | 58 +++++++++++++++++++++++++++++++++++++-------------
2 files changed, 44 insertions(+), 15 deletions(-)
diff --git a/include/linux/parser.h b/include/linux/parser.h
index dd79f45a37b8..a3cc7bc5fb93 100644
--- a/include/linux/parser.h
+++ b/include/linux/parser.h
@@ -34,6 +34,7 @@ int match_u64(substring_t *, u64 *result);
int match_octal(substring_t *, int *result);
int match_hex(substring_t *, int *result);
bool match_wildcard(const char *pattern, const char *str);
+bool match_wildcard_hyphen(const char *pattern, const char *str);
size_t match_strlcpy(char *, const substring_t *, size_t);
char *match_strdup(const substring_t *);
diff --git a/lib/parser.c b/lib/parser.c
index 62da0ac0d438..d5be01fa9adf 100644
--- a/lib/parser.c
+++ b/lib/parser.c
@@ -268,20 +268,13 @@ int match_hex(substring_t *s, int *result)
}
EXPORT_SYMBOL(match_hex);
-/**
- * match_wildcard - parse if a string matches given wildcard pattern
- * @pattern: wildcard pattern
- * @str: the string to be parsed
- *
- * Description: Parse the string @str to check if matches wildcard
- * pattern @pattern. The pattern may contain two types of wildcards:
- *
- * * '*' - matches zero or more characters
- * * '?' - matches one character
- *
- * Return: If the @str matches the @pattern, return true, else return false.
- */
-bool match_wildcard(const char *pattern, const char *str)
+static inline char dash2underscore(char c)
+{
+ return (c == '-') ? '_' : c;
+}
+
+static __always_inline bool __match_wildcard(const char *pattern, const char *str,
+ bool hyphen_agnostic)
{
const char *s = str;
const char *p = pattern;
@@ -301,7 +294,9 @@ bool match_wildcard(const char *pattern, const char *str)
pattern = p;
break;
default:
- if (*s == *p) {
+ if (hyphen_agnostic ?
+ (dash2underscore(*s) == dash2underscore(*p)) :
+ (*s == *p)) {
s++;
p++;
} else {
@@ -319,8 +314,41 @@ bool match_wildcard(const char *pattern, const char *str)
++p;
return !*p;
}
+
+/**
+ * match_wildcard - parse if a string matches given wildcard pattern
+ * @pattern: wildcard pattern
+ * @str: the string to be parsed
+ *
+ * Description: Parse the string @str to check if matches wildcard
+ * pattern @pattern. The pattern may contain two types of wildcards:
+ *
+ * * '*' - matches zero or more characters
+ * * '?' - matches one character
+ *
+ * Return: If the @str matches the @pattern, return true, else return false.
+ */
+bool match_wildcard(const char *pattern, const char *str)
+{
+ return __match_wildcard(pattern, str, false);
+}
EXPORT_SYMBOL(match_wildcard);
+/**
+ * match_wildcard_hyphen - parse if a string matches given wildcard pattern
+ * @pattern: wildcard pattern
+ * @str: the string to be parsed
+ *
+ * Description: Same as match_wildcard, but treats '-' and '_' as identical.
+ *
+ * Return: If the @str matches the @pattern, return true, else return false.
+ */
+bool match_wildcard_hyphen(const char *pattern, const char *str)
+{
+ return __match_wildcard(pattern, str, true);
+}
+EXPORT_SYMBOL(match_wildcard_hyphen);
+
/**
* match_strlcpy - Copy the characters from a substring_t to a sized buffer
* @dest: where to copy to
--
2.54.0
next prev parent reply other threads:[~2026-06-02 22:49 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-02 22:47 [PATCH v4 00/25] dynamic-debug cleanups refactors maintenance + alignment fix Jim Cromie
2026-06-02 22:47 ` [PATCH v4 01/25] docs/dyndbg: update examples \012 to \n Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:47 ` [PATCH v4 02/25] docs/dyndbg: explain flags parse 1st Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 03/25] vmlinux.lds.h: refactor BOUNDED_SECTION_* macros into bounded_sections.lds.h Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 04/25] vmlinux.lds.h: drop unused HEADERED_SECTION* macros Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 05/25] vmlinux.lds.h: Fix ALIGN(8) omission causing NULL ptr on i386 Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 06/25] vmlinux.lds.h: remove redundant ALIGN(8) directives Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 07/25] dyndbg.lds.S: fix lost dyndbg sections in modules Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 08/25] dyndbg: factor ddebug_match_desc out from ddebug_change Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 09/25] dyndbg: add stub macro for DECLARE_DYNDBG_CLASSMAP Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 10/25] dyndbg: reword "class unknown," to "class:_UNKNOWN_" Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 11/25] dyndbg-API: remove DD_CLASS_TYPE_(DISJOINT|LEVEL)_NAMES and code Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 12/25] dyndbg: drop NUM_TYPE_ARGS Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 13/25] dyndbg: reduce verbose/debug clutter Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 14/25] dyndbg: refactor param_set_dyndbg_classes and below Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 15/25] dyndbg: tighten fn-sig of ddebug_apply_class_bitmap Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 16/25] dyndbg: replace classmap list with an array-slice Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 17/25] dyndbg: macrofy a 2-index for-loop pattern Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 18/25] dyndbg: Upgrade class param storage to u64 for 64-bit classmaps Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 19/25] dyndbg,module: make proper substructs in _ddebug_info Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 20/25] dyndbg: move mod_name down from struct ddebug_table to _ddebug_info Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 21/25] dyndbg: hoist classmap-filter-by-modname up to ddebug_add_module Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 22/25] selftests-dyndbg: add a dynamic_debug run_tests target Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 23/25] dyndbg: change __dynamic_func_call_cls* macros into expressions Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-02 22:48 ` Jim Cromie [this message]
2026-06-04 2:12 ` Claude review: lib/parser: add match_wildcard_hyphen() for agnostic matching Claude Code Review Bot
2026-06-02 22:48 ` [PATCH v4 25/25] dynamic_debug: use KBUILD_MODFILE for unique builtin module names Jim Cromie
2026-06-04 2:12 ` Claude review: " Claude Code Review Bot
2026-06-04 2:12 ` Claude review: dynamic-debug cleanups refactors maintenance + alignment fix Claude Code Review Bot
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=20260602-dd-maint-2-v4-24-19a1445585a8@gmail.com \
--to=jim.cromie@gmail.com \
--cc=airlied@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=atomlin@atomlin.com \
--cc=corbet@lwn.net \
--cc=da.gomez@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=jbaron@akamai.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mcgrof@kernel.org \
--cc=mripard@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=samitolvanen@google.com \
--cc=shuah@kernel.org \
--cc=simona@ffwll.ch \
--cc=skhan@linuxfoundation.org \
--cc=tzimmermann@suse.de \
/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