From: Steven Rostedt <rostedt@goodmis.org>
To: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: [PATCH] trace-cmd Library: Update record after callback in iterators
Date: Thu, 10 Nov 2022 00:33:25 -0500 [thread overview]
Message-ID: <20221110003325.007663c7@rorschach.local.home> (raw)
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
The function graph plugin will look at the next event and may even
increment it if it is a leaf function. The current iterators update the
next record before the callback. This leaves them vulnerable to
corruption if the callback updates to the next record like function
graph plugin does.
Peek at the next record after the callback to ensure that the next
record is the one that will be used for the next iterator.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
lib/trace-cmd/trace-input.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index aa54e7fa..594eb74a 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -2810,11 +2810,11 @@ int tracecmd_iterate_events(struct tracecmd_input *handle,
if (next_cpu >= 0) {
/* Need to call read_data to increment to the next record */
record = tracecmd_read_data(handle, next_cpu);
- records[next_cpu] = tracecmd_peek_data(handle, next_cpu);
ret = call_callbacks(handle, record, next_cpu,
callback, callback_data);
+ records[next_cpu] = tracecmd_peek_data(handle, next_cpu);
tracecmd_free_record(record);
}
} while (next_cpu >= 0 && ret >= 0);
@@ -2900,12 +2900,12 @@ int tracecmd_iterate_events_multi(struct tracecmd_input **handles,
cpu = next_cpu - handle->start_cpu;
/* Need to call read_data to increment to the next record */
record = tracecmd_read_data(handle, cpu);
- records[next_cpu].record = tracecmd_peek_data(handle, cpu);
ret = call_callbacks(handle, record, next_cpu,
callback, callback_data);
tracecmd_free_record(record);
+ records[next_cpu].record = tracecmd_peek_data(handle, cpu);
}
} while (next_cpu >= 0 && ret >= 0);
--
2.35.1
reply other threads:[~2022-11-10 5:33 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221110003325.007663c7@rorschach.local.home \
--to=rostedt@goodmis.org \
--cc=linux-trace-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).