]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rtla: Introduce for_each_action() helper
authorWander Lairson Costa <wander@redhat.com>
Tue, 6 Jan 2026 11:49:39 +0000 (08:49 -0300)
committerTomas Glozar <tglozar@redhat.com>
Wed, 7 Jan 2026 14:57:55 +0000 (15:57 +0100)
The for loop to iterate over the list of actions is used in
more than one place. To avoid code duplication and improve
readability, introduce a for_each_action() helper macro.

Replace the open-coded for loops with the new helper.

Signed-off-by: Wander Lairson Costa <wander@redhat.com>
Link: https://lore.kernel.org/r/20260106133655.249887-4-wander@redhat.com
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
tools/tracing/rtla/src/actions.c
tools/tracing/rtla/src/actions.h

index 8945aee58d511f13c6b07290069ca4db0cf0bd31..31bc98db9228ca9d4cd545d35d4d2609cb3604af 100644 (file)
@@ -32,7 +32,9 @@ void
 actions_destroy(struct actions *self)
 {
        /* Free any action-specific data */
-       for (struct action *action = self->list; action < self->list + self->len; action++) {
+       struct action *action;
+
+       for_each_action(self, action) {
                if (action->type == ACTION_SHELL)
                        free(action->command);
                if (action->type == ACTION_TRACE_OUTPUT)
@@ -223,7 +225,7 @@ actions_perform(struct actions *self)
        int pid, retval;
        const struct action *action;
 
-       for (action = self->list; action < self->list + self->len; action++) {
+       for_each_action(self, action) {
                switch (action->type) {
                case ACTION_TRACE_OUTPUT:
                        retval = save_trace_to_file(self->trace_output_inst, action->trace_output);
index a4f9b570775b55e352f2aa2eebac0a221c165dfe..fb77069c972baee3b0e48b29fdd37e1bbcf4c50f 100644 (file)
@@ -42,6 +42,11 @@ struct actions {
        struct tracefs_instance *trace_output_inst;
 };
 
+#define for_each_action(actions, action)                       \
+       for ((action) = (actions)->list;                        \
+            (action) < (actions)->list + (actions)->len;       \
+            (action)++)
+
 void actions_init(struct actions *self);
 void actions_destroy(struct actions *self);
 int actions_add_trace_output(struct actions *self, const char *trace_output);