[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251222082049.1782440-15-jim.cromie@gmail.com>
Date: Mon, 22 Dec 2025 21:20:31 +1300
From: Jim Cromie <jim.cromie@...il.com>
To: linux-kernel@...r.kernel.org,
jbaron@...mai.com,
gregkh@...uxfoundation.org,
ukaszb@...omium.org,
louis.chauvet@...tlin.com
Cc: dri-devel@...ts.freedesktop.org,
amd-gfx@...ts.freedesktop.org,
intel-gvt-dev@...ts.freedesktop.org,
intel-gfx@...ts.freedesktop.org,
daniel.vetter@...ll.ch,
tvrtko.ursulin@...ux.intel.com,
jani.nikula@...el.com,
ville.syrjala@...ux.intel.com,
seanpaul@...omium.org,
robdclark@...il.com,
groeck@...gle.com,
yanivt@...gle.com,
bleung@...gle.com,
quic_saipraka@...cinc.com,
will@...nel.org,
catalin.marinas@....com,
quic_psodagud@...cinc.com,
maz@...nel.org,
arnd@...db.de,
linux-arm-kernel@...ts.infradead.org,
linux-arm-msm@...r.kernel.org,
mingo@...hat.com,
jim.cromie@...il.com
Subject: [PATCH v7 14/31] dyndbg: macrofy a 2-index for-loop pattern
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 <jim.cromie@...il.com>
---
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__)
+/*
+ * 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) = 0, (_sp) = (_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;
- 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;
@@ -1231,8 +1253,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.52.0
Powered by blists - more mailing lists