From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oa2-f35.google.com (mail-oa2-f35.google.com [74.125.231.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5EE1057EDA5 for ; Wed, 23 Sep 2026 22:34:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.231.99 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790202898; cv=none; b=rJ8pitPx6IFnjKkyEXGwhszXKsgvzTndRsfp9p0F0PpD3QW+6apKTLBS2sN3VATHZg4CZuQBLjdCRhAWGDzyzp4nMolHDYxrk15q8o7RdEbN6zTwHhSc5ev59u1c1elZ65XVrgangYrCvRFJPo7nCy8j098dejgrNppwKYYxps4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790202898; c=relaxed/simple; bh=Ea2Lf2NOIb4xfOxyj7JKgPRMz10QHHz8z+1IIkR3nVY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HXv4VAn72gJ1H8ySDtWFgw2K9CAuIgy3uAIBvlI/q0XapKOFxJbBwspD/1FrQQNrCP4q74sXO8J6gw/9o6uUuTtRcbDh3dztfIqtEzQr6iY/1GrukAy025oaZ1NolJBaP2WPQDr3VSktudz6BHcyRYWN143m6h9A8VGj27pI3l0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=e2mDLzjP; arc=none smtp.client-ip=74.125.231.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="e2mDLzjP" Received: by mail-oa2-f35.google.com with SMTP id 586e51a60fabf-491c13d63d9so284294fac.0 for ; Wed, 23 Sep 2026 15:34:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790202894; x=1790807694; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=pY/j1ww3Y8UnMsGPx7zQGy6NPa6GEKgP8JCREIbwugg=; b=e2mDLzjPO4nfot00leAVLmf+ToxEEEPQ0fCS3eS5UVbxgLzr6fOFhwBYy60qsclKd9 305pKhgv/WXwkwI9BdWbQfXBOqm+PqRzJ1m0SaK7DkIAkiZgqKF5pv3sjDzmOVcIVwQT V/pCjgKEIvhjIj+/MVLncff+FqwxdWnyJOgToHYI9C1cAey3KmftM0i4awpqq6vMaw3D aborQi79n6YHb/8K8e+Q/DVtSRs61jNAlR0hK7XGVK5vl9GFkHolldq48PpoB5AjDeH8 wnOslq3tIUIYKcUzhH1DQGwB+vr71CJN1y5F4tjjKA8i/T5yqxN79Zpnywozbm7yHMI6 +Jew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790202894; x=1790807694; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=pY/j1ww3Y8UnMsGPx7zQGy6NPa6GEKgP8JCREIbwugg=; b=vxfkYGMeviXnJwvKtF/J4FqSdR7Sc8RRI8F8KXopCDE0REFXDLY2D/Shr2xeoES2cZ oEA/MekVfUcMVEn8QsE+0mzgkFndFKIezcjdCd7O4c5l9oM8FYRZc5OjmGOunUOtko87 IdJp3TifWtj+BQyop/0WD2bR9m9I+FI0GMo+BkVTWyP/YQZAWXrKVrAk9hSJOmcmlQkY la690fo3GuY6bc5SGU04cHvwFcQxHQI+l3W9rfx3fcea6uTpa5I9HcKFenOc0HeQ7sLj YlbaUzCOA+wR5DZ40wXxZVkHC9LpVcNtpUkaIogp1CjTI74OQv8bxxWD4X3UBNnfruFp bEeA== X-Forwarded-Encrypted: i=1; AKwUvByS2Ok6tNu0XnreY03njiqwrZFxLK9uy+e8ZV4MXjv6mHQYVskNgbnLgc9hv9DuK3zqH/bgIIGMKDcituA6blI=@vger.kernel.org X-Gm-Message-State: AFuF++m7DMVHOgxS+z4fr0vXZCxy05o51/fAlps5eZ4z+l5RXKoWvYDS 5YvTk+N+xh5WZ1NZTa5OEXo405fcjrra58PK3tNcRx3WAGdOkwuUh514 X-Gm-Gg: AYBFou35uCpux7hRc6Hi40FI4uOJKIhrzpwPU7z4Xt+7iPR/yfnsrZ9kKMXEEhTr2/l 4Is92Mv4aFf1odDoUHpOfx4n1PkyXgI7jlE8imRrkKV99qU+gCXtUSnM8wzAyVQfZa1RK+RtM6S Xdm7JesMc90khSaVchmQdx+t7kMQO/mUvCFZdnDcoPB+/jjiAk6F6xiARerU7SZ/2riINI2T7JG v6fNQI0W8ty0de7YxVRnH+Z4tAI1JzM1PdReN+bgi9jvMv/ZIXuk5bKtBUlz2mJusqLy02xttke /pYhpelDzaRfcwEr4hiSRlC4pFSSMpJHZ0WatSCZSOWfAFBB/RIyaR/ZyBJGXGK9CnakcomW9By +uGD4zl0ezISCD0fCZ+mC0Q4oAdHv82ZeFIsL9XyNcCK3L4FRLo6jPnu1NIVffKZvKOdAYJ4uFf ZT1uMPkFKfQaSJXAQJGiXPB/08fY+inXw7Crs4vBcTL6XlvPTGncOcSb8XU91xyxHyYiqBXdYI9 crs6Bbw7RHjmaczuPoGMn1G/p3W6jNkZJ176IOcqUt4BR0exvjGAm7dVvcML7TzzxNOimcmBa6l CWzQN2D/kej8qq3N31U= X-Received: by 2002:a05:6870:6783:b0:487:31c8:f341 with SMTP id 586e51a60fabf-491e549eaecmr721076fac.19.1790202893734; Wed, 23 Sep 2026 15:34:53 -0700 (PDT) Received: from [100.82.231.29] (c-98-38-17-99.hsd1.co.comcast.net. [98.38.17.99]) by smtp.googlemail.com with ESMTPSA id 586e51a60fabf-491ee1ac486sm559401fac.16.2026.09.23.15.34.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2026 15:34:53 -0700 (PDT) From: Jim Cromie Date: Wed, 23 Sep 2026 16:34:31 -0600 Subject: [PATCH v11 07/38] dyndbg: factor ddebug_match_desc out from ddebug_change Precedence: bulk X-Mailing-List: linux-kselftest@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: <20260923-dd-cmap-part2-clean-v11-7-9b6c217fdf2f@gmail.com> References: <20260923-dd-cmap-part2-clean-v11-0-9b6c217fdf2f@gmail.com> In-Reply-To: <20260923-dd-cmap-part2-clean-v11-0-9b6c217fdf2f@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 , Jonathan Corbet , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky 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 , Louis Chauvet X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1790202874; l=5231; i=jim.cromie@gmail.com; s=20260203; h=from:subject:message-id; bh=Ea2Lf2NOIb4xfOxyj7JKgPRMz10QHHz8z+1IIkR3nVY=; b=Wq1j33LYlnk4/v38X95dwW7rLmRMFQGkcjeMowlE5C9vXaIuKAiQNHIStsK0SHxoEw2YOGQ1U kgs4mu9en9+D9zx428a2j2DNgycLXIGQgxm08Up1gD3jLuugn9wl68e X-Developer-Key: i=jim.cromie@gmail.com; a=ed25519; pk=C6E5ODlPQo7ZBynATXH9wg7K6HxP0pIXyf4s38Qw0XE= 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 --- v11: . move doc comment block down to precede ddebug_change(). Sashiko review complaint (patch 7): "Does this placement separate the block comment from its intended target? The comment describes a function that returns the number of matching callsites and takes ddebug_lock, which accurately describes ddebug_change(). However, by inserting ddebug_match_desc() immediately after this comment, does it leave ddebug_change() undocumented and make the comment falsely apply to ddebug_match_desc()..." 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 | 91 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 36 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 49334d1aa4b3..8682c23b5fe7 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -166,6 +166,60 @@ static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table cons } #define __outvar /* filled by callee */ +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; + + 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; + } + + /* 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 (*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; +} + /* * Search the tables for _ddebug's which match the given `query' and * apply the `flags' and `mask' to them. Returns number of matching @@ -204,42 +258,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