From: Jim Cromie <jim.cromie@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Jason Baron <jbaron@akamai.com>,
Jim Cromie <jim.cromie@gmail.com>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.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>, Arnd Bergmann <arnd@arndb.de>,
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>
Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
dri-devel@lists.freedesktop.org, linux-arch@vger.kernel.org,
linux-modules@vger.kernel.org
Subject: [PATCH v5 08/18] lib/parser: add match_wildcard_hyphen() for agnostic matching
Date: Thu, 02 Jul 2026 10:41:00 -0600 [thread overview]
Message-ID: <20260702-dd-maint-2-v5-8-24f22b052bf2@gmail.com> (raw)
In-Reply-To: <20260702-dd-maint-2-v5-0-24f22b052bf2@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>
---
v5: move ahead of array-slice patch to silence sashiko complaint about it
v4: initial version
---
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-07-02 16:41 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 16:40 [PATCH v5 00/18] dyndbg: cleanups, refactors in prep for API fix Jim Cromie
2026-07-02 16:40 ` [PATCH v5 01/18] dyndbg: factor ddebug_match_desc out from ddebug_change Jim Cromie
2026-07-02 16:40 ` [PATCH v5 02/18] dyndbg: add stub macro for DECLARE_DYNDBG_CLASSMAP Jim Cromie
2026-07-02 16:40 ` [PATCH v5 03/18] dyndbg: reword "class unknown," to "class:_UNKNOWN_" Jim Cromie
2026-07-02 16:40 ` [PATCH v5 04/18] dyndbg-API: remove DD_CLASS_TYPE_(DISJOINT|LEVEL)_NAMES and code Jim Cromie
2026-07-02 16:40 ` [PATCH v5 05/18] dyndbg: drop NUM_TYPE_ARGS Jim Cromie
2026-07-02 16:40 ` [PATCH v5 06/18] dyndbg: bump num-tokens in a query-cmd from 9 to 15 Jim Cromie
2026-07-02 16:40 ` [PATCH v5 07/18] dyndbg: reduce verbose/debug clutter Jim Cromie
2026-07-02 16:41 ` Jim Cromie [this message]
2026-07-02 16:41 ` [PATCH v5 09/18] dyndbg: use KBUILD_MODFILE for unique builtin module names Jim Cromie
2026-07-02 16:41 ` [PATCH v5 10/18] dyndbg: refactor param_set_dyndbg_classes and below Jim Cromie
2026-07-02 16:41 ` [PATCH v5 11/18] dyndbg: tighten fn-sig of ddebug_apply_class_bitmap Jim Cromie
2026-07-02 16:41 ` [PATCH v5 12/18] dyndbg: replace classmap list with an array-slice Jim Cromie
2026-07-02 16:41 ` [PATCH v5 13/18] dyndbg: macrofy a 2-index for-loop pattern Jim Cromie
2026-07-02 16:41 ` [PATCH v5 14/18] dyndbg: pin class param storage to u32 Jim Cromie
2026-07-02 16:41 ` [PATCH v5 15/18] dyndbg,module: make proper substructs in _ddebug_info Jim Cromie
2026-07-02 16:41 ` [PATCH v5 16/18] dyndbg: move mod_name down from struct ddebug_table to _ddebug_info Jim Cromie
2026-07-02 16:41 ` [PATCH v5 17/18] dyndbg: hoist classmap-filter-by-modname up to ddebug_add_module Jim Cromie
2026-07-02 16:41 ` [PATCH v5 18/18] dyndbg: change __dynamic_func_call_cls* macros into expressions Jim Cromie
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=20260702-dd-maint-2-v5-8-24f22b052bf2@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-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=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