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 25C234F7967; Sat, 5 Sep 2026 18:13:41 +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=1788632021; cv=none; b=FO/sJpsFXDYHqYrAN2pSW05ruedp97jFvi2EOgkh16Xi5aPyrip1zXQbCv05RDt/iC6f8fjjgfKYAbKiG6CcjZZVOzUd2391IslipwZW06SPDkZZC3eU65qv9fpBJuTyjcUP5o9rInC+ipCruld+n+51SS6ebCEHAwIe6ALZVFs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788632021; c=relaxed/simple; bh=KHYyKCY/o2ucBdRre+GIwYV+OybylCVX1QE1D3owH2c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KQWwPrGSbJvQPkLTLA3dH1u6PwHraFJeH6FH7PYscpayzkekUKN/9G/XQOf6PI7H3SjzXvEhKxZyxxeoJdj9aUu2lG/dsUv2jI2oZTM+5PtIZ0lCRQPdc0Y/nH3e7vD2U5uRkEknXJKHyFCH8RgTYJLbmedf3a2S+qG3caouh00= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jIycwSsH; 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="jIycwSsH" Received: by smtp.kernel.org (Postfix) with ESMTPS id 03DB5C2BCF4; Sat, 5 Sep 2026 18:13:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1788632021; bh=KHYyKCY/o2ucBdRre+GIwYV+OybylCVX1QE1D3owH2c=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=jIycwSsHUQkBCrM1kOr9TQPpGWIhr0RTE+dRL4XeTIvrw1PkFeeVfhSEchz8glcbD k7c22MIYzUm2vge6tNC2/z9o7FsMTItofu5h2iII1hXwl6BTInrBW0lFp0TQ+ynoR5 /TX1P78Gl2J88j1ur+nLk714kB1xzEqaTgFD7BtkC6+c8UVMnScfEP97goDGsgaxlO oIfAa+JCJC9fKq2KL4oIBp8iiN9/+m854Oj2gbRft0jusNgblSiUtRaO47pMOGmVLZ 1r46XW8qh+0K1YQ7GC+25YF9sqn3Fci9qpjmxZmx2lkPTYgaCNIY8f691DN4gxF283 YixN/SYQqMhAA== 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 E564BC624D6; Sat, 5 Sep 2026 18:13:40 +0000 (UTC) From: Jim Cromie via B4 Relay Date: Sat, 05 Sep 2026 12:13:36 -0600 Subject: [PATCH v8 22/43] dyndbg: macrofy a 2-index for-loop pattern 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-22-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=2812; i=jim.cromie@gmail.com; s=20260203; h=from:subject:message-id; bh=sL5jOuN4FaubTxOxUsnjoGZpS1Nyd8TM1PfZEvk+BmI=; b=X0oh6TyKwBfQyeQbpPxDx9YDPt835rUL/72dleNHz4RzXC746QYr/0RqjHd1n69273hIyTwSc RvJphmoI/EmD8OjnxsckuXD1ZPUApicrPeIdhpQlt63kZmmV8QdgoPK 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 dynamic-debug currently has 2 __sections (__dyndbg, __dyndb_classes), struct _ddebug_info keeps track of them both, with 2 members each: _vec and _vec#_len. We need to loop over these sections, with index and record pointer, making ref to both _vec and _vec_len. This is already fiddly and error-prone, and will get worse as we add a 3rd section. Lets instead embed/abstract the fiddly-ness in the `for_subvec()` macro, and avoid repeating it going forward. This is a for-loop macro expander, so it syntactically expects to precede either a single statement or a { block } of them, and the usual typeof or do-while-0 tricks are unavailable to fix the multiple-expansion warning. Signed-off-by: Jim Cromie Reviewed-by: Louis Chauvet --- v2: move RvB after SoB --- lib/dynamic_debug.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 470314e4810e..2cbac60569c7 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -149,6 +149,20 @@ static void v3pr_info_dq(const struct ddebug_query *query, const char *msg) query->first_lineno, query->last_lineno, query->class_string); } +/* + * simplify a repeated for-loop pattern walking N steps in a T _vec + * member inside a struct _box. It expects int i and T *_sp to be + * declared in the caller. + * @_i: caller provided counter. + * @_sp: cursor into _vec, to examine each item. + * @_box: ptr to a struct containing @_vec member + * @_vec: name of a member in @_box + */ +#define for_subvec(_i, _sp, _box, _vec) \ + for ((_i) = 0, (_sp) = (_box)->_vec; \ + (_i) < (_box)->num_##_vec; \ + (_i)++, (_sp)++) /* { block } */ + static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table const *dt, const char *class_string, int *class_id) @@ -156,7 +170,7 @@ static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table cons struct ddebug_class_map *map; int i, idx; - for (map = dt->classes, i = 0; i < dt->num_classes; i++, map++) { + for_subvec(i, map, dt, classes) { idx = match_string(map->class_names, map->length, class_string); if (idx >= 0) { *class_id = idx + map->base; @@ -1165,8 +1179,7 @@ static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug * the builtin/modular classmap vector/section. Save the start * and length of the subrange at its edges. */ - for (cm = di->classes, i = 0; i < di->num_classes; i++, cm++) { - + for_subvec(i, cm, di, classes) { if (!strcmp(cm->mod_name, dt->mod_name)) { if (!nc) { v2pr_info("start subrange, class[%d]: module:%s base:%d len:%d ty:%d\n", -- 2.55.0