From nobody Thu Apr 2 20:20:45 2026 Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) (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 52D0E3A5E82 for ; Thu, 26 Mar 2026 18:54:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774551299; cv=none; b=Zvna8EuCL6KQz67WmLyck0+8v2sC0+2v68fShAsrMRE3wquua7FA0UTJggARud3zoy1SFaxhMdC16v5YEXCgHkbqvtSjGRE0KUU0trH7jZmxuCwgt5HwLPV3Of28n7pK37FsXGIddQImgE1dmBNcTiVqzTO4MJiRZaNKLnSJL/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774551299; c=relaxed/simple; bh=S44qNaJnprSPGtSX9jhfIgwHHExOvS0QRFBglJsEsKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oEM6BjrrkDOeZYh8wp80k/iPhmenzhqchPIFqJAdF7g6Q0l2l9AhQIFR248LZ4oX+pVTq64w1C7738Bg0BD8ukdnGSBsJgZzcJ6uAId49P3O87cyDxrUIyQcgSUswIBRe5utTKLkW66UUVfA8Yhj51+8X1Zxl59JzQLjXyZy7QI= 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=dVsUmWRj; arc=none smtp.client-ip=209.85.167.180 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="dVsUmWRj" Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-467161c4b89so726110b6e.3 for ; Thu, 26 Mar 2026 11:54:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774551297; x=1775156097; 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=dVsUmWRjHJku0zMjKNiCYY0MXuGYKX0fd5o4nt8VuVYZWGZmbLK1BR5eAgesUwPaj8 aV+zO/oZTawGft9QQIyVOzWMuLp+zeQx32HL3vJ9N2iH54tIQU1alGc3Gh1sRmsaQv93 mUiF4uzntMmpsXkjYUoiDevUshUHO5L10s3qn/ANK+XgWRONjkRB4iuoDdZt8+DQKbSI MMpg7Qsa26gM2D8UyPErlEkEWWL25oIy+/R+jggLbZ/p0RBsajuHf5LXagX9tmygaidx LUxEfR39Kt4BeP/1a6iKwCie7sP5zPD4+AiLzUqH1ViI5gjvWpnDSaPytEMJqZsIkGZ9 vBZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774551297; x=1775156097; 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=AU1CfYFWn3zU3/uiHOYbdwMKsyAfKgINX+7s+8NZBjxMUwVqNXNcoKx6WVMNsk4qBg aevjETCBbSeDN3F/kWhd03bg7o7jVcspAwV+zgz104DjOoT8N9E1bzS12dZiQyxKuas0 cIBSljeWRCEXn8d0VqZ9E3B5gIowJUQbfOb74W2oGBTODgy5FXt1PZ30lKGF0WDlBEXF cG8BVQz9eBtRm8HbXw/8jgoCVsl6IuO6hcFXf35uiRNW01RvTNPVousJJ3kHK8GkSiR/ CeTW0tjvA+JCCsYuMSqPo3GTsKGuoZJC3ZKHucsAlx8TkMvnxTU+5L9GlvO3wUQOGXSR Zvcg== X-Gm-Message-State: AOJu0YxNDgO3o4LaaxvKzA3GkeQSqsivOI80BhEQHvlh9TKpv7Tj3tpB Y9AnfmKTIsdD/S5n8i6MWwvOwYRYR9gQaBmCtcqoKsVxkOeFkbirG8PaBZ7y7g== X-Gm-Gg: ATEYQzzPeIpx2zA+LW4RQCkqqSnxvcTkUtkVk6+waqyLrLFR6ljDEzBRkcJmS0uKiPe 5uYMdN5L/sDjrnVFPM9KxtduysZqr0Qy6hRkzU4/vasO0JsjtV1clnRBwlUkHncU1yaN39qThMx OqeeTe8zohu80vS3jGinNcSoxogxF+ecX4TGyYlDnq3gC5DqcWBEKfp5L8DLZm+Ftct+aJVrA7Y BzPUjiUJNvCyBUGBCBRs9bZ2Y4rBJJjNCsehRR0iBHxamx/IoM9AQfQYSa807ZD9Xyp2pbRKurN 5ihIB13Ao4v09+OJf6d2NyTGrsJ6k7MLs1xsnKo3MXxQEfRfQ36tfcbmO34HfHJ1VfUSK7/RjZr oUuqJyFGtUjY5Z+lXK9kKllnTVvh02gBefhklBA9RgFst+/13igRyu1gYngjuQBg9T2OlXnZjJc gvpxPHthqm+CSmN7yPql4eGovnCgSvjQtCc/Edi/dJdLfc/o6D X-Received: by 2002:a05:6808:c299:b0:467:14c7:a8ae with SMTP id 5614622812f47-46a5c5f7c5cmr3888707b6e.21.1774551297062; Thu, 26 Mar 2026 11:54:57 -0700 (PDT) Received: from frodo (c-98-38-17-99.hsd1.co.comcast.net. [98.38.17.99]) by smtp.googlemail.com with ESMTPSA id 586e51a60fabf-41cc7760c08sm3075171fac.4.2026.03.26.11.54.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 11:54:56 -0700 (PDT) From: Jim Cromie To: linux-kernel@vger.kernel.org, airlied@gmail.com, simona@ffwll.ch, jbaron@akamai.com, gregkh@linuxfoundation.org Cc: jim.cromie@gmail.com, mripard@kernel.org, tzimmermann@suse.de, maarten.lankhorst@linux.intel.com, jani.nikula@intel.com, ville.syrjala@linux.intel.com, christian.koenig@amd.com, matthew.auld@intel.com, arunpravin.paneerselvam@amd.com, louis.chauvet@bootlin.com, skhan@linuxfoundation.org, pmladek@suse.com, ukaszb@chromium.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Subject: [PATCH v12 18/69] dyndbg: macrofy a 2-index for-loop pattern Date: Thu, 26 Mar 2026 12:53:22 -0600 Message-ID: <20260326185413.1205870-19-jim.cromie@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260326185413.1205870-1-jim.cromie@gmail.com> References: <20260326185413.1205870-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: quoted-printable Content-Type: text/plain; charset="utf-8" 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__) =20 +/* + * 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) =3D 0, \ + (_sp) =3D (_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; =20 - for (map =3D dt->classes, i =3D 0; i < dt->num_classes; i++, map++) { + for_subvec(i, map, dt, classes) { idx =3D match_string(map->class_names, map->length, class_string); if (idx >=3D 0) { *class_id =3D idx + map->base; @@ -1232,8 +1254,7 @@ static void ddebug_attach_module_classes(struct ddebu= g_table *dt, struct _ddebug * the builtin/modular classmap vector/section. Save the start * and length of the subrange at its edges. */ - for (cm =3D di->classes, i =3D 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= ", --=20 2.53.0