From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 333B22E7397; Wed, 9 Sep 2026 00:55:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788915303; cv=none; b=eLbuRCPk2EO2NoPBXlcgpzTatgiJ7bgZNMQOi/SRbiTPF0giEHeZtpNulm6hQI+9nETqzuDJ6pGrAX3uq/BX+mvyP22Au/eLTyKVo7O58/z66zIqPZBjyhvlM50w00n4OQ2H0iN1MZY4AnWYVDUvQfSvfCZjTV3aYdwAwDwhi2Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788915303; c=relaxed/simple; bh=HYh+PdX1won8kuxbGPgkiI4LhAQJSu2ZmSyX44SU7ps=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=St0Q02cKRhpk+q/YeyPl/BhxpOibROYkJDKU5Yp5PbgTiVurYIpCg/scHz/3CliRxjIkG9F9VykDp0fXROwuX/fHti1qISisM6gZ6t+6XZ6NY3wyQBi0hTJL2fZVhr+5hRCHEb/b7S2MoEGvOshEtIIcpDOuZ6GxbIcC3vDkPYI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qzn5PN/b; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qzn5PN/b" Received: by smtp.kernel.org (Postfix) with ESMTPS id F12D6C4AF09; Wed, 9 Sep 2026 00:55:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1788915303; bh=HYh+PdX1won8kuxbGPgkiI4LhAQJSu2ZmSyX44SU7ps=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=qzn5PN/bHa8hKH1ABBeIVGINjVuVaddkEkY2RhF+ZKGka35peml0Gof+x6O1pG/XQ gtS9f9+EyIXyLTA4+SzcHnan9S5Xm/fF7ugWYt5wzZG8TI9wmoCOa/QmTFiHzD4pvU 983IIsRjhCyemKboQQ2Qmlhval/M0ixog1GTK/6oRQ2X7pXsLLhevXTQ+h1CWafbiC X9BBT4TgEz1vjAiSoqhVTAMq7k8f1/ICR/maHmahb1uZhhYl0TirxAVejWSkM8ttIg wP/zJ7/8wKGhfYx1bCpcTQyf9nMZe70P4bNLN0zVOZTSGB2rY6ue0atwCa5HhIekBH bmITtIFkcNklA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8E30C79FA1; Wed, 9 Sep 2026 00:55:02 +0000 (UTC) From: Jim Cromie via B4 Relay Date: Tue, 08 Sep 2026 18:55:10 -0600 Subject: [PATCH v9 14/39] lib/parser: add match_wildcard_hyphen() for agnostic matching Precedence: bulk X-Mailing-List: linux-arch@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260908-dd-cmap-part2-clean-v9-14-3a3f621f4a10@gmail.com> References: <20260908-dd-cmap-part2-clean-v9-0-3a3f621f4a10@gmail.com> In-Reply-To: <20260908-dd-cmap-part2-clean-v9-0-3a3f621f4a10@gmail.com> To: Jason Baron , Shuah Khan , Andrew Morton , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Arnd Bergmann , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Jonathan Corbet , Greg Kroah-Hartman , Nathan Chancellor , Nicolas Schier , Shuah Khan , Randy Dunlap , "Rafael J. Wysocki" , Pavel Machek , Len Brown Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arch@vger.kernel.org, linux-modules@vger.kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-pm@vger.kernel.org, Jim Cromie X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788915300; l=4874; i=jim.cromie@gmail.com; s=20260203; h=from:subject:message-id; bh=VVrWeKOkQRL4T3vAYCy0RnOLdaaMyLNU7Rl2KzQNToo=; b=y/h7Rk+KEYGl5ogdjaz3zjWgEnFpodf1D12RswnxFy6ORAAgYsOezesFG8ZhPloKtBI3jjf+C Yq0vG+YhjXjDXBRF+RfRsZ7mILpL5tRjGcBYtHTLw5Xu9Mbpnpf6kdv X-Developer-Key: i=jim.cromie@gmail.com; a=ed25519; pk=C6E5ODlPQo7ZBynATXH9wg7K6HxP0pIXyf4s38Qw0XE= X-Endpoint-Received: by B4 Relay for jim.cromie@gmail.com/20260203 with auth_id=958 X-Original-From: Jim Cromie Reply-To: jim.cromie@gmail.com From: Jim Cromie 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 --- 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 ++++++++++++++++------ .../selftests/dynamic_debug/dyndbg_selftest.sh | 2 +- 3 files changed, 45 insertions(+), 16 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 diff --git a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh index e9f9db35fb7f..69a1787a4302 100755 --- a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh +++ b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh @@ -591,7 +591,7 @@ builtin_tests=( FT_grammar_errs FT_basic_queries #FT_path_module_queries - #FT_hyphen_underscore + FT_hyphen_underscore ) # Modular Feature Tests (Require CONFIG_MODULES=y and test_dynamic_debug*.ko available) -- 2.55.0