Skip to content

Commit 648634d

Browse files
walaclenticularis39
authored andcommitted
rtla: Introduce for_each_action() helper
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>
1 parent 2a3a253 commit 648634d

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

tools/tracing/rtla/src/actions.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ void
3232
actions_destroy(struct actions *self)
3333
{
3434
/* Free any action-specific data */
35-
for (struct action *action = self->list; action < self->list + self->len; action++) {
35+
struct action *action;
36+
37+
for_each_action(self, action) {
3638
if (action->type == ACTION_SHELL)
3739
free(action->command);
3840
if (action->type == ACTION_TRACE_OUTPUT)
@@ -223,7 +225,7 @@ actions_perform(struct actions *self)
223225
int pid, retval;
224226
const struct action *action;
225227

226-
for (action = self->list; action < self->list + self->len; action++) {
228+
for_each_action(self, action) {
227229
switch (action->type) {
228230
case ACTION_TRACE_OUTPUT:
229231
retval = save_trace_to_file(self->trace_output_inst, action->trace_output);

tools/tracing/rtla/src/actions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ struct actions {
4242
struct tracefs_instance *trace_output_inst;
4343
};
4444

45+
#define for_each_action(actions, action) \
46+
for ((action) = (actions)->list; \
47+
(action) < (actions)->list + (actions)->len; \
48+
(action)++)
49+
4550
void actions_init(struct actions *self);
4651
void actions_destroy(struct actions *self);
4752
int actions_add_trace_output(struct actions *self, const char *trace_output);

0 commit comments

Comments
 (0)