From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (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 A27563793AD for ; Wed, 8 Apr 2026 20:02:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775678559; cv=none; b=Ka2z/j0tu6kHmsmymmlo2r9QGzji5lJrgXeVe3q4FU4jVLd9kQfGL6Ggw+4LE1YbIED8wP//Us+tJcXUpT6UgkqEDvWYgTmgP1mt956KNy6++k2Nz0em1RBy4hgP1WstXTGsmMJ5JFJfHhRjOF1GMj6bs//sdWQBWMZgmVvK7uI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775678559; c=relaxed/simple; bh=S44qNaJnprSPGtSX9jhfIgwHHExOvS0QRFBglJsEsKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OaE0XsEc2K0lElxDgILi86api6li76qu/F9+TFruEIU/OQuIsOmf1O+bW3ckQIFYgKePaOiYulERNnuJtCcWjPoSwvfX6/eg3bD2gqx+GcsIV0G5s62NfMJYfP2xibszG/XKWdZ2nhwLcf6bVYNVKZkYhSUN5faU137Dp9SF6WI= 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=hf1xAs4n; arc=none smtp.client-ip=209.85.161.43 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="hf1xAs4n" Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-68481c9e067so60744eaf.0 for ; Wed, 08 Apr 2026 13:02:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775678554; x=1776283354; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=R72DzlYh9MokOK1r/XXtR9MDuFmHujj2u63MvUuPRVY=; b=hf1xAs4nfDCER+ewQRgvy+R6OpDDmaVouGvz5Bo8gu/2+gdq+g6Gcx21KxxZZgkjj2 DBp+ZIRNeC/chFbEg72XvuvQHnwGNhAvtuTgShDqAYtKyEJGQyT6/kudGTbOidLVBBV7 dbrIh/47EebINomJUPTkAupuIMngb2hwp/583p995zMrnFX2VAHPBt5AReH1Q2MeFq5U m+77Bw/iDZFw8YT0Kc1lXA8jvqlFSDeeGplpUPqKofoKmToRhNDLiFRRWGfwjHfC196/ mrl2/LqK/JOZu+8GRrgqzyRm87nHHM1dLmF+oAbV614iWOC0xsQI2nrOqSqevhlY50ry d7/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775678554; x=1776283354; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=R72DzlYh9MokOK1r/XXtR9MDuFmHujj2u63MvUuPRVY=; b=sgF2tQFxfZLNh33D7qls9TgZsQ15RRRgRWHXo64CBPa0obe9j0xspq0ylYPV7WnCIe uEW9O7gYhgRwccFfUYrKNNuNX0kgoEjmGjjgH4XEd3STJHaECxYjqyBCboIPiizEr30o mvc4p4os8bN+AmuKRWNqGf+3IVBOfVO37XQNeoazFXo8/7iM6GWeMZL2+gWCRAzYHnK1 7dJDTSn6hYAXxyVe/6fC0szy/CFGnj7Mks6S9qvJyuvmqjmf8DjJ/oTwAwUt2AH3cuzg uMRvzGaeMlnc18uvvTolCmWDGyCxu2FFpUCfx52Oygtx2qDj6/bB5Mf+NNnvwQsN+UaJ uV+A== X-Gm-Message-State: AOJu0Yx0zVADIm5UNYlx+HQPQee9+D2duZK8h+SV0XAfwvLphxGIWKnh BoJ8gryKSzJWhYkfaSYL+bGg/r7hxKN8sYAjBZwEpH8nnOtQl8sQ7vhcQ2ZpFA== X-Gm-Gg: AeBDievxwkZnagdBcVMwv/WOuXNjB44VbggKRYjw8QiCYsmqF/6M1Q9n/B/H+9xhtgT TmN42+vsj1+M/C85oTGpTSgCzViIoqWzs3H8/2vNv/ELxsTvY4a1loY9HMyuE7kJX9yy0cSzAJQ HYjj10DFBmBWUDqVkZ1BL57vVI90DAzZ1aGN7IKb1lwO/3M6c8cAF01SFT1u/Fu1a6kj9TB0tkj xhCI9ZnmK1akP4mZJoNTLbAQ5Hr9yrEiki5ev4x8mzD1yDc3bqh82IPvtOIpwdn+ChGBMqynzeF 4OEBpOTpQGgHpulRIfbgx2MLeOSVz9UXOqxc7JoOiWMbM7lsSIo7eRNBjsfYkVulrIzlRGFSlYn 6FD74Me9WHNJarNRnUEDbrUoF2YxWgZyJBOpkCA5hR8SAkAY6fJw9trElD25ag7on8YwGMqV+d4 S54djYJlsgvoig+P7JNwhu7P2yYKIJcM6ghTiQNZa00doIc1AMr6lMOq7pku9wPDXPLfc5tItcv ir1U4JQR9lTBQ== X-Received: by 2002:a05:6820:2908:b0:688:87fc:6dac with SMTP id 006d021491bc7-68a632c4cbfmr517678eaf.43.1775678554266; Wed, 08 Apr 2026 13:02:34 -0700 (PDT) Received: from frodo.raven-morpho.ts.net (c-98-38-17-99.hsd1.co.comcast.net. [98.38.17.99]) by smtp.googlemail.com with ESMTPSA id 006d021491bc7-680a63c7fd1sm12254208eaf.8.2026.04.08.13.02.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2026 13:02:33 -0700 (PDT) From: Jim Cromie To: linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, jbaron@akamai.com, louis.chauvet@bootlin.com, Jim Cromie Subject: [PATCH v13 18/36] dyndbg: macrofy a 2-index for-loop pattern Date: Wed, 8 Apr 2026 14:01:53 -0600 Message-ID: <20260408200211.43821-19-jim.cromie@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260408200211.43821-1-jim.cromie@gmail.com> References: <20260408200211.43821-1-jim.cromie@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. The macro needs a lot from its caller: it needs 2 local vars, 1 of which is a ref to a contained struct with named members. To support these requirements, add: 1. __ASSERT_IS_LVALUE(_X): ie: ((void)sizeof((void)0, &(x))) 2. __ASSERT_HAS_VEC_MEMBERS(_X, _Y): compile-time check that the _Y "vector" exists ie: _X->_Y and _X->num_##_Y are lvalues. The for_subvec() macro then invokes these in the initialization of the for-loop; they disappear at runtime. Reviewed-by: Louis Chauvet Signed-off-by: Jim Cromie --- lib/dynamic_debug.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 94a66c8537ab..8f614eba8ace 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -129,6 +129,28 @@ do { \ #define v3pr_info(fmt, ...) vnpr_info(3, fmt, ##__VA_ARGS__) #define v4pr_info(fmt, ...) vnpr_info(4, fmt, ##__VA_ARGS__) +/* + * 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 __ASSERT_IS_LVALUE(x) ((void)sizeof((void)0, &(x))) +#define __ASSERT_HAS_VEC_MEMBER(_box, _vec) \ + (void)sizeof((_box)->_vec + (_box)->num_##_vec) + +#define for_subvec(_i, _sp, _box, _vec) \ + for (__ASSERT_IS_LVALUE(_i), \ + __ASSERT_IS_LVALUE(_sp), \ + __ASSERT_HAS_VEC_MEMBER(_box, _vec), \ + (_i) = 0, \ + (_sp) = (_box)->_vec; \ + (_i) < (_box)->num_##_vec; \ + (_i)++, (_sp)++) /* { block } */ + static void vpr_info_dq(const struct ddebug_query *query, const char *msg) { /* trim any trailing newlines */ @@ -156,7 +178,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; @@ -1232,8 +1254,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.53.0