From nobody Tue Dec 2 02:41:31 2025 Received: from mail-io1-f47.google.com (mail-io1-f47.google.com [209.85.166.47]) (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 25665364E8C for ; Tue, 18 Nov 2025 20:19:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763497159; cv=none; b=FZ+SFVZBLGp670x0L8cHmnZMN5gjxr+ZmzSBj4H0qKY9Tg+/KPbrTbccuSifve2YFMRS8kw/BP/vy3YdU3fgx8pQ6PUrNB7eCzFbuG5nlYcMUNudEzlFdlpvnewWL0ARmj01OsWThU/KHBDWKxviZQ7YeMw2cm66cXpuuxix/cA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763497159; c=relaxed/simple; bh=OCKD5EV3sLHtsVsB9amTvKQ8ND5z1okePEOHBoF1W6k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DuY5/i5fR4Y25OBc9ZPYk0TBK1aJ8vqvjmJivfm4Tl6Ic+Fm9C/X9zBCYLF1Wf+O9zx80EmH45VHjDtzZnGQMEwiLHs3LrkYbswheoYVY3InSlhJOnUw/m57daGMWtz2GoNNL7x3+PyMniXQrPvqFKfdvTPozJm07kHFmm/trLY= 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=ZKU4uHoz; arc=none smtp.client-ip=209.85.166.47 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="ZKU4uHoz" Received: by mail-io1-f47.google.com with SMTP id ca18e2360f4ac-9490cbf951fso96551239f.1 for ; Tue, 18 Nov 2025 12:19:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763497156; x=1764101956; 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=Mom9p3QYL/HEnLm12XjQXHk1KtSfULxrp3u8JPNUlAU=; b=ZKU4uHozGH/SujWqU8jFpUF0EVF7l27+LeZfpvHHGRmqSnjiI5gGaq4KJehlr/uN3D hT4ZiKNkalmx1xZJ30VnliBt+ENE95zeitaSBZqaNR4pJ5YSYMDV5f8vqRoNHqHj//Rx gwSwTy8Akr9CU+gJKc9+1UOaqESMGtCVro1pMxyAz6BMdAjCKIhA9ulVGdgX2HkvtGVO 1banfJ9y63JUv+mFI5sPluO2A2MR6JOtvMJ2az9C9D1SFRU+MSgPSi/Ul1fp0wvOKuGY MOi55wmR3Plsge7RMNczeBmMIlhBqMZZfADV3BkRXxrY0TYjE0Ds6JMsgzcTGfIxfX0s zmXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763497156; x=1764101956; 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=Mom9p3QYL/HEnLm12XjQXHk1KtSfULxrp3u8JPNUlAU=; b=PkQC8e26vomhH3TZYrBqyIRldmmI3HuqgIn9V5m5X1KW5RD2tMFqid0hvdppdtnF2t 2TQYE/iqPDPohX/LNtxS1azS4IFHosDuEnyyo44kGJMzeurl+TO3j/TveAQZIzIhLLAK ny2ts8aNPayt6qKQ3GwdCrM/C3KC9z3UpdlsGLjdvB2rpEIYx/S6l6gCKs6KrEoxnAHj BlW1c1lugP8uTBA41EP563kmC8oSYvthve1YtWDmpdWPJJhHxMB8ZXn+cqAUF2wbQb/k uWHhozou9ChRz1kBBWrKDF7QPEam8zqq8LbOkwJGsUVB/lmifR8XRvjXY52eOwzEgNsR sZ5g== X-Gm-Message-State: AOJu0YwxiFQOoZPmB2raHE5z9197Qygci2KnsHLnA9dep2V3HMtFO3Bo +Irt+j7Xi62tG6nlsvEBoKX2BLExo3xNgYBRrmppKCTkONdGRKbAk4kw+e6WTwju X-Gm-Gg: ASbGncsBhj2rQOhdCgBbjeus7oijgk2HZlJCzBZR1/EXrIr8RyXEaesIHnmua37jjF0 X1SyPMbPq2NCxg+b+A9uVGnvGUkQ92/1Ev8lkeXAAb3jGrYt2M7dLWD17PlWxT3kuyI+3eN4BBm plE5KPZz8wgzYhAIl3aDWsN7EcVNwE+c7TAj9M/nNGS42cenxY/idq7DaV/HnQeJnhE5vUAd6fo l5jV0500fD2DOJly8ZcjYfvfehP0zMorhEB05VhGQlPtGkioe476i1uRS9s1FrzbiEqvLjsCMun wuEaD163RQ2vIUMrRG23w8Xd+K8AwZkETeron+d2MyeBiPEVN90JcthbECHPEcQzVxQESa98KzX qZkwvwDXWRaqfkC8W3bH7dC+ovtntFSXcy+GnhIUOFbXOAWGp+ZjNKQ+woSQ3yK/3uf+isFvlsW 5vVDlkT3IlwGV2KomnkSo7h4KWmqJHVqHr/KPaFaZONKdRcq3hO/IGJhhFpH05dVXZGgo= X-Google-Smtp-Source: AGHT+IF9qxBwV/U/VSjF667XqOPS3S0CMKNPPtG91ifTzUkTzfrgNjJ7HC4VQQdW5SFo4/2/ImAGSw== X-Received: by 2002:a05:6602:1344:b0:945:a1fc:a7a5 with SMTP id ca18e2360f4ac-948e0defd6amr1887003939f.11.1763497156071; Tue, 18 Nov 2025 12:19:16 -0800 (PST) Received: from godzilla.raven-morpho.ts.net (c-98-38-17-99.hsd1.co.comcast.net. [98.38.17.99]) by smtp.googlemail.com with ESMTPSA id ca18e2360f4ac-948fd4c273bsm419823939f.18.2025.11.18.12.19.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 12:19:15 -0800 (PST) From: Jim Cromie To: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, gregkh@linuxfoundation.org, jbaron@akamai.com Cc: ukaszb@chromium.org, louis.chauvet@bootlin.com, Jim Cromie Subject: [PATCH v6 14/31] dyndbg: macrofy a 2-index for-loop pattern Date: Tue, 18 Nov 2025 13:18:24 -0700 Message-ID: <20251118201842.1447666-15-jim.cromie@gmail.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251118201842.1447666-1-jim.cromie@gmail.com> References: <20251118201842.1447666-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 --- -v5+ add __ASSERT_*() macros add then drop __chkp_no_side_effects() macro due to changes v5+ drop Reviewed-by: Louis Chauvet this patch evokes these complaints, the "reuses" are all lvalues, so not issues. (vec) is incompatible with ## paste-up do-while also wont work here. CHECK: Macro argument '_vec' may be better as '(_vec)' to avoid precedence = issues WARNING: Non-declarative macros with multiple statements should be enclosed= in a do - while loop CHECK: Macro argument reuse '_i' - possible side-effects? CHECK: Macro argument reuse '_sp' - possible side-effects? CHECK: Macro argument reuse '_box' - possible side-effects? CHECK: Macro argument reuse '_vec' - possible side-effects? --- 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 e882e951d585..94d05d09a128 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -128,6 +128,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); \ + (void)sizeof((_box)->num_##_vec); \ +}) +#define for_subvec(_i, _sp, _box, _vec) \ + __ASSERT_IS_LVALUE(_i); \ + __ASSERT_IS_LVALUE(_sp); \ + __ASSERT_HAS_VEC_MEMBER(_box, _vec); \ + for ((_i) =3D 0, (_sp) =3D (_box)->_vec; \ + (_i) < (_box)->num_##_vec; \ + (_i)++, (_sp)++) + static void vpr_info_dq(const struct ddebug_query *query, const char *msg) { /* trim any trailing newlines */ @@ -155,7 +177,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; @@ -1231,8 +1253,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.51.1