From nobody Tue Apr 7 12:55:31 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 331D439A059 for ; Fri, 13 Mar 2026 13:23:27 +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=1773408208; cv=none; b=Wfe/vADI/Lc0xhxgADYcEYbmP6kvId9ufj65ljWsC5MZk66JgLvqFn91ZPz7F3Phoim3niajRgDTENosatc4eHrH2ZfOrlo8tAyNiOu6jUOmhCuSDAD3vBycFHsIISKeiJZagrWpzZ6Yaenh1A6oSH46YKvYw4ynmyOBk6LtyNY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773408208; c=relaxed/simple; bh=h11SMXTTqtXfuGn+BXShMbaaEsHk1UVnXJbNCNEPy+A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UTtd9UgZ52aaIrgTB78QB+yLT9cOpC6K+OT6L5l2ABkVhYC0oazqllX/Vmp30l5FfZCJH4J7FFWxFHKcAUaQ+1bhSIfTLtBPolbhacMeOnAyyabcCKHOL+t5KYBOZyf5fgPP8NIOZA5fB2Xbfc1cUipZVcVMce4TohIljt/uxKQ= 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=JGBQEFoO; 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="JGBQEFoO" Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-46708149af2so1223011b6e.0 for ; Fri, 13 Mar 2026 06:23:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773408206; x=1774013006; 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=dBYomo+y0fMuoiYBGpthmpNvx8Y41pycbs0VlWTcMIg=; b=JGBQEFoONYEzKvZpADcuoM/DlEZ04sgngt7PnIlZELhRaqh2uBM52PJawkAEVqkwCY kI2QcBDdRNkMoH07scGBcJiS+QIMYcRR1lVGWOSgB8pRcdd1MijEUPNvZbjgCtRqOt18 ZzsOuXRdao3bYWYbcBC8+L+AEs228qCUYcDkaYORBRt0HZGcJB+3TEVdj9yE25jfTH7H bJjTvlMcGOWCWUqTKRenbiKr8AWA2c6LF69BzTGLHH1UZjHNEpGqNY5hKu9enFEanLgA /mezKrtrOy0OUdIQsTMdP2QAKam6gHGL9JwS56isp3l1Z0L+Ag3XlMjKExdLmVXQIWk7 G+Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773408206; x=1774013006; 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=dBYomo+y0fMuoiYBGpthmpNvx8Y41pycbs0VlWTcMIg=; b=XRIQX4mFSCf2WcUCTCdGou2AsckigkoaPwa6du/O0dJcnbnHK3SFtIeZzDitmRsKAW tpz3TWRFC4jsoj3RC5Bik5FDWjr969omumFPMC6wEordUA1FBKV0ASJ1yDC/3KWxpJ/H ktQdXcsNskuCD20bMN3EjeZoLqg3jl3belkiLM5uZWHJgeIxXXy3m+hYIwuzzCed29Q7 SooHSW/QksQtDLBEyqfBLE9gtAzIA+bTWzFbKvb0+S1e4mIKduFF65rnHntYdWS6EzFp 9aZez3VAZXiptRWQKmr7+ipNi+/kLxqo1c0y8tTl7g8L90yF+LW/YHJnYYExzwbPM++m GMgQ== X-Forwarded-Encrypted: i=1; AJvYcCU3RdMW7wCVAxPDSz6v06Zkts8wM7K555dGHAtbolkuTiBZKXM2SNugmc0YtxqsCdxPqGOx8wnK5bw71m8=@vger.kernel.org X-Gm-Message-State: AOJu0YwMsIGt7pLkMo+k9GyVGhR38xTb+oZWSzILA3LXkfWS7yKQDoEl RGMXRPCgS0qIXrcng9GROKsi9O60K1lVfIFjh0HQzGYeIa4+DJUeyRJ7 X-Gm-Gg: ATEYQzyqYeGC8W/hfHICK8+jPasEPUwG7qlekf5eTZqEEF6Aj2S8FNxiZz0dH18xPXI gTeOCqMNrZxP1n9iSAXL4Kufp/a5CsChNcq4wAa3El3uKzpn35UMpBdGCiNJI1CfwOyW2nAKCw6 taW6wASDNhcRVpX1qZ12F36hMQt2xrUi7PC6E1crtWRdCG9l4M3iHcSXkWiLziTO0X+FPuZdbvG fH5Q/5q37FnJ3wJAtJHODtZIa9RNO6tCDUcp9cRyKHIM3kwevEi7RUaampD11GNBuqgkcbiwubY vZhThXwef+YghbHN59Et2NGLHHnpNQgnh2WQ3Fn8BY16z76xrXwF7ITRkpuGG4cuHYideePC8E0 64EtohNjC9gg3pbTDVjnQPb1MlgEDjY1gENYEX2hR17K5iAQh+zSJ4hDfunDmJcrwF4IV2/6xt1 FiDBTYDQv/ulM3jYdPH9gw92sCvzDEgmkrd+Lado5NkudBfeFZ X-Received: by 2002:a05:6808:221f:b0:455:d5d1:8ac0 with SMTP id 5614622812f47-467574375ccmr1562149b6e.53.1773408205979; Fri, 13 Mar 2026 06:23:25 -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 5614622812f47-4673434a35csm4795987b6e.20.2026.03.13.06.23.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Mar 2026 06:23:25 -0700 (PDT) From: Jim Cromie To: airlied@gmail.com, simona@ffwll.ch, jbaron@akamai.com, gregkh@linuxfoundation.org, Jim Cromie , Andrew Morton , linux-kernel@vger.kernel.org Cc: 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 v11 15/65] dyndbg: macrofy a 2-index for-loop pattern Date: Fri, 13 Mar 2026 07:19:40 -0600 Message-ID: <20260313132103.2529746-16-jim.cromie@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260313132103.2529746-1-jim.cromie@gmail.com> References: <20260313132103.2529746-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 before the for-loop itself; they disappear at runtime. They do cause a "complex macro" CHECK from checkpatch --strict. Signed-off-by: Jim Cromie Reviewed-by: Louis Chauvet --- 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..cb7bfe8729a7 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