From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oa1-f54.google.com (mail-oa1-f54.google.com [209.85.160.54]) (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 37E6A3ACF18 for ; Thu, 2 Jul 2026 16:41:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783010504; cv=none; b=lXIBH3lfUraKPbJdemYi2eruCWViA8s0JHsVt8VStbOTJXQDE6I41amMh8sjd/bWdLornIPWtOf2ovOAqVjTlBeUulesvFnICekGTOyTeXPBK/3nvtanp212+oGUizRyuFcWtLcGcir8Bor0fejSSA4fq8Fck3d9sgKB0vbTl9k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783010504; c=relaxed/simple; bh=P7lO9A8LPVkryGsY8RIV4ZKJga8IqX0oHHS7prrgxeo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ps0fTBhdPC/C2KdW5nqYws363aSpv8hcdiztF0Db5V4T5NzU/ux9/53qtbSERSF5ZwKClmZFT7UlKDq9AYyR4dOe1CTZsL5V0ixd8Qqk1FlZQo1p69KHhI7Tlnftgksn9atoS07XEuMrjjWrjmGfwdXP/iYSu1rlyLh92hODcgw= 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=dyA9u7Fl; arc=none smtp.client-ip=209.85.160.54 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="dyA9u7Fl" Received: by mail-oa1-f54.google.com with SMTP id 586e51a60fabf-43cce8288c7so881970fac.3 for ; Thu, 02 Jul 2026 09:41:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783010494; x=1783615294; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=y22IAHS2DQHIuwdJSUGvICtgOAsEzbta+k4+G2yELGI=; b=dyA9u7Fl38DO8OiOhVffsqfJQaDn6FYlnv8zxwn/NWUxs0yA/gkZG7hKj3jK90CKEP Hn/am9vyNk20rTJAFdhxoefl8Y4X499VNH5TmQjcD5Qezw/UwVT7pnj6gQPxoparuW56 DkTnzDsWid+gs1TJbV6gAyf0eyyrwdohhFwA17Ka9kiL9qDDeK2nJQeqW8B3ExmGt43W TYss2yr0TjyKSXUOS+vUE0p4/n4TGOvRUGvGDUqMUquXB5rgQoZ2DQcWC9gmzKVAuEuj 44cIN3k17B/Y7gmNXG1RL/vG6iCiLmsE5UCpibmmEYSJ8N8ALpLfAB/fZeoc0VT7aOMt lOtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783010494; x=1783615294; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=y22IAHS2DQHIuwdJSUGvICtgOAsEzbta+k4+G2yELGI=; b=aoo9fc/dkj9Gd42sjQd3zWvYK0zP7e2GAhshyCTOCPP9t74IBMXMBCXCrKovsH8+Gn TkOyC+FRV5/wkTpKMKyex3CDV3vKVLxONzOBwderQOrPfbkt672n3CIGQC2Kl76NtPSg UBV0+jc/JM+EpNOSHlRJKTlc9+Jwp/xf5UEWKx519hcZgxypvGzi9LCvrJHvEHAWxoc6 o99qnIUtaSciXEAodpocHs9o8zkDtGpH392xwmMqgQ3up9yRHFP6bMvsCT5ZVhAfdvvz C3m+adlcCkZYWq5gZoHH2ACeqTiN0vujnReoC0ZlKGUQK6mygqI3I9kxqbD+9qKTGAN8 3pGg== X-Gm-Message-State: AOJu0Yzq85r6XqWmqVRyA5QftDmgD7QovYkPqeDVVyIDwFB/bjP5/YCl 0o5BnafyU/tl1TJqlDHHVxD6O1QJD9EVbe6Pu3M0hD3K3hDiFBV58IDQ X-Gm-Gg: AfdE7ckhJ6fAVXcPxd3pta3j+K5mIDB0btLooe735XgM+S1RlflGslJd+ocrd16L4P4 nvhKL90ebLtSFqLtob/XWSLPgHXR3NDNVjnrlF4m3lnxd0fBYnBwop0cz6vwde9eC4VfqRnMNkV 9ImKQhoHjyWkers4066DGQWtnTKs1u+p0FUhSmVN54LEPuGdA68DIPmClTD92f0Huwh44Z7AMhz VaZKRBCELryXECT+9LxE3R779ikRP/yUyxSMz37vYSzI0eISlC6w/X3ZP3O4Ca8ToEYZ/r7XeEo QIPqZx9vc/iu7gVm+yY3q1wMO+KNX5jbRKjhDg2nqmBWagbzQ016bRmnnclx7VUtb0k/PUILUWB /WOSLXg+fRjuszLonEYVH/cbYt+thpvGDkwSF4swzopI6nw7PyX/SUumDu2eTJbhyvrjqhZF+Ct sShjeTOKc2qmSGMkVx2xm6buAiMMliE1x/QEjjFc7t6Bjxgyl/rV4= X-Received: by 2002:a05:6870:a24a:b0:447:534c:8a85 with SMTP id 586e51a60fabf-44cab72dbf7mr4223853fac.18.1783010493890; Thu, 02 Jul 2026 09:41:33 -0700 (PDT) Received: from [192.168.0.245] (c-98-38-17-99.hsd1.co.comcast.net. [98.38.17.99]) by smtp.googlemail.com with ESMTPSA id 586e51a60fabf-44cbec93702sm3189652fac.12.2026.07.02.09.41.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jul 2026 09:41:33 -0700 (PDT) From: Jim Cromie Date: Thu, 02 Jul 2026 10:41:05 -0600 Subject: [PATCH v5 13/18] 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: <20260702-dd-maint-2-v5-13-24f22b052bf2@gmail.com> References: <20260702-dd-maint-2-v5-0-24f22b052bf2@gmail.com> In-Reply-To: <20260702-dd-maint-2-v5-0-24f22b052bf2@gmail.com> To: Andrew Morton , Jason Baron , Jim Cromie , Jonathan Corbet , Shuah Khan , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Arnd Bergmann , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin 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, Louis Chauvet X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1783010473; l=2812; i=jim.cromie@gmail.com; s=20260203; h=from:subject:message-id; bh=P7lO9A8LPVkryGsY8RIV4ZKJga8IqX0oHHS7prrgxeo=; b=ZiFRjEQiBoPzgQl6ZTTsrHxeLEogZj8ZTL25G5df3P3s4Sjm5hzaZ+RcbiN9KKPPzRnwz2kQ0 YGjKn7AsmcgBmT4HfFcylcgtMeY+kn8FVpTH3iojpRO7wDqkeTltnqP X-Developer-Key: i=jim.cromie@gmail.com; a=ed25519; pk=C6E5ODlPQo7ZBynATXH9wg7K6HxP0pIXyf4s38Qw0XE= 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 6b699ed23d26..d99c69b9ad12 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; @@ -1167,8 +1181,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.54.0