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 40DEB4EC661; Sat, 5 Sep 2026 18:13:40 +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=1788632020; cv=none; b=ho19tLA3ah5zSl9lY1K78zuAOpNMOs6hKwO041kTl4guRgLY/qbH+ygfEwOgVBE+9kseInYNw0zjPmH3hCRQjnB2vn2qCEmx9ql8Psn5ifHeK0d29jGZ7zyXyBF84bYZyuSS+vC2Rzd2M1P5U7lTALZ8ORxdlZV4Dd8OkLMXrms= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788632020; c=relaxed/simple; bh=iC8id8XvjVwuPMpZhnYdB/l0KkP4a6frt7tNI5NIjUM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Va2F5qOEl6roO2yNwZ8p9zxMmHY4SeG2jEi9izeOejfY821/8bJq0FOMJjTCf7O1gEcjV9f+ynEIsBz1vb7loXzBx8FNrjU/rHBVAe8sYEM8bepSd66HK+RpsigKp0YbV7I3lEbHG5HpowRnzsYlUP++SWrLN0b+mk4594o65/U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VP0/3Gqr; 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="VP0/3Gqr" Received: by smtp.kernel.org (Postfix) with ESMTPS id 1240CC2BCB3; Sat, 5 Sep 2026 18:13:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1788632020; bh=iC8id8XvjVwuPMpZhnYdB/l0KkP4a6frt7tNI5NIjUM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=VP0/3GqroW21GIy8gzoBR/Li4MJm42erBiw9nwTJxFmkbbTXyrFftV7hf6DkSuTQs NYxSP1B7sE+k9iD07Jahh7907doEANzPxV3j0jAb0t0FE1pIIjf3gX3n1ZoEPqIFrg YNtX1bUtyk2Hf8R28gWDeTPdYrg0EzQnYpq5gNbGZN/GETWjwTnOoAAKGKwUIGgi/n GPSi09KXhcwrwG/EktYvOYbAbKxDg9TXg9cFSu42WLrzb1StLnMdi9pg7dhoPFStRn hyO4sSRGWpZaICgbaGgKgeD0/r6a+rqnV1/dg7fQ7j4Jl7vfW0YpuBi/IqFWNYMs8U knJ63tPYGKMWA== 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 F3AA3C624DB; Sat, 5 Sep 2026 18:13:39 +0000 (UTC) From: Jim Cromie via B4 Relay Date: Sat, 05 Sep 2026 12:13:24 -0600 Subject: [PATCH v8 10/43] dyndbg: factor ddebug_match_desc out from ddebug_change Precedence: bulk X-Mailing-List: linux-kernel@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: <20260905-dd-cmap-part2-clean-v8-10-a4cc0674f6fd@gmail.com> References: <20260905-dd-cmap-part2-clean-v8-0-a4cc0674f6fd@gmail.com> In-Reply-To: <20260905-dd-cmap-part2-clean-v8-0-a4cc0674f6fd@gmail.com> To: Jason Baron , Shuah Khan , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Arnd Bergmann , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Andrew Morton , Jonathan Corbet , Shuah Khan , Greg Kroah-Hartman , Nathan Chancellor , Nicolas Schier 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, Jim Cromie , Louis Chauvet X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788632017; l=4735; i=jim.cromie@gmail.com; s=20260203; h=from:subject:message-id; bh=MGgO+TgvS39o/SEYXr5LobK7bvtNF6U3Aa3LKlNQQGU=; b=f9G533cNjFxRN7xikFynp6fi1a8pepHTutFBYn4pps7Vf5wZqSm4kJso5DVn1J9IJmeEWGug8 mMiC0A+LQc9CWVpTD0cHMCvfIddXc8NmesBjgohDz/PWagFVzANyykI 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 ddebug_change() is a big (~100 lines) function with a nested for loop. The outer loop walks the per-module ddebug_tables list, and does module stuff: it filters on a query's "module FOO*" and "class BAR", failures here skip the entire inner loop. The inner loop (60 lines) scans a module's descriptors. It starts with a long block of filters on function, line, format, and the validated "BAR" class (or the legacy/_DPRINTK_CLASS_DFLT). These filters "continue" past pr_debugs that don't match the query criteria, before it falls through the code below that counts matches, then adjusts the flags and static-keys. This is unnecessarily hard to think about. So move the per-descriptor filter-block into a boolean function: ddebug_match_desc(desc), and change each "continue" to "return false". This puts a clear interface in place, so any future changes are either inside, outside, or across this interface. also fix checkpatch complaints about spaces and braces. Signed-off-by: Jim Cromie Reviewed-by: Louis Chauvet --- v5: check for null format in callsite. shouldnt happen, but pr_debug() isnt illegal v7: elevate null format to pr_err adding filename, function, lineno. --- lib/dynamic_debug.c | 90 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 36 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 18a71a9108d3..e23723ef7ddd 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -172,6 +172,59 @@ static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table cons * callsites, normally the same as number of changes. If verbose, * logs the changes. Takes ddebug_lock. */ +static bool ddebug_match_desc(const struct ddebug_query *query, + struct _ddebug *dp, + int valid_class) +{ + /* match site against query-class */ + if (dp->class_id != valid_class) + return false; + + /* match against the source filename */ + if (query->filename && + !match_wildcard(query->filename, dp->filename) && + !match_wildcard(query->filename, + kbasename(dp->filename)) && + !match_wildcard(query->filename, + trim_prefix(dp->filename))) + return false; + + /* match against the function */ + if (query->function && + !match_wildcard(query->function, dp->function)) + return false; + + /* match against the format */ + if (query->format) { + if (!dp->format) { + pr_err_ratelimited("ddebug: NULL format string at %s:%s:%u\n", + dp->filename ? dp->filename : "?", + dp->function ? dp->function : "?", + dp->lineno); + return false; + } + if (*query->format == '^') { + char *p; + /* anchored search. match must be at beginning */ + p = strstr(dp->format, query->format + 1); + if (p != dp->format) + return false; + } else if (!strstr(dp->format, query->format)) { + return false; + } + } + + /* match against the line number range */ + if (query->first_lineno && + dp->lineno < query->first_lineno) + return false; + if (query->last_lineno && + dp->lineno > query->last_lineno) + return false; + + return true; +} + static int ddebug_change(const struct ddebug_query *query, struct flag_settings *modifiers) { @@ -204,42 +257,7 @@ static int ddebug_change(const struct ddebug_query *query, for (i = 0; i < dt->num_ddebugs; i++) { struct _ddebug *dp = &dt->ddebugs[i]; - /* match site against query-class */ - if (dp->class_id != valid_class) - continue; - - /* match against the source filename */ - if (query->filename && - !match_wildcard(query->filename, dp->filename) && - !match_wildcard(query->filename, - kbasename(dp->filename)) && - !match_wildcard(query->filename, - trim_prefix(dp->filename))) - continue; - - /* match against the function */ - if (query->function && - !match_wildcard(query->function, dp->function)) - continue; - - /* match against the format */ - if (query->format) { - if (*query->format == '^') { - char *p; - /* anchored search. match must be at beginning */ - p = strstr(dp->format, query->format+1); - if (p != dp->format) - continue; - } else if (!strstr(dp->format, query->format)) - continue; - } - - /* match against the line number range */ - if (query->first_lineno && - dp->lineno < query->first_lineno) - continue; - if (query->last_lineno && - dp->lineno > query->last_lineno) + if (!ddebug_match_desc(query, dp, valid_class)) continue; nfound++; -- 2.55.0