Skip to contentSkip to conversation

trace-cmd library: Have callbacks exit out of the iterator

PATCH New Steven Rostedt 1 participant 1 message Jun 15, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace-cmd library: Have callbacks exit out of the iterator

From: "Steven Rostedt (Google)" <[email protected]>

In the man page for tracecmd_iterate_events() it states that if the callback() returns anything other than zero, it will exit the iterator. But this is not true. It only exits if the callback returns less than zero. This is a bug as the code should do what the man page states. Have it exit the loop if the callback returns non zero.

---
 lib/trace-cmd/trace-input.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/trace-cmd/trace-input.c +2 -2
index 145c02eeb718..51420c13c750 100644
@@ -2816,7 +2816,7 @@ int tracecmd_iterate_events(struct tracecmd_input *handle,
 			records[next_cpu] = tracecmd_peek_data(handle, next_cpu);
 			tracecmd_free_record(record);
 		}
-	} while (next_cpu >= 0 && ret >= 0);
+	} while (next_cpu >= 0 && ret == 0);
 
 	/* Need to unlock and free the records */
 	for (cpu = 0; cpu < handle->max_cpu; cpu++) {
@@ -2912,7 +2912,7 @@ int tracecmd_iterate_events_multi(struct tracecmd_input **handles,
 			records[next_cpu].record = tracecmd_peek_data(handle, cpu);
 		}
 
-	} while (next_cpu >= 0 && ret >= 0);
+	} while (next_cpu >= 0 && ret == 0);
 
 	/* Unlock and free the records */
 	for (cpu = 0; cpu < all_cpus; cpu++) {
Signature · 1 line
2.39.2