From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v2 01/21] trace-cmd library: Read option id with correct endian
Date: Mon, 13 Sep 2021 15:27:39 +0300 [thread overview]
Message-ID: <20210913122759.3672494-2-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20210913122759.3672494-1-tz.stoyanov@gmail.com>
The id of a trace option is 2 bytes short integer. When reading it from
the trace file, use the tep handler associated with the file, if
available, to convert the option with the correct endian order.
A new helper function is introduced to read and convert 2 byte integer.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
lib/trace-cmd/trace-input.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index ac57bc4f..0dbcdbdc 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -336,6 +336,18 @@ static char *read_string(struct tracecmd_input *handle)
return NULL;
}
+static int read2(struct tracecmd_input *handle, unsigned short *size)
+{
+ struct tep_handle *pevent = handle->pevent;
+ unsigned short data;
+
+ if (do_read_check(handle, &data, 2))
+ return -1;
+
+ *size = tep_read_number(pevent, &data, 2);
+ return 0;
+}
+
static int read4(struct tracecmd_input *handle, unsigned int *size)
{
struct tep_handle *pevent = handle->pevent;
@@ -2660,16 +2672,15 @@ static int handle_options(struct tracecmd_input *handle)
handle->options_start = lseek64(handle->fd, 0, SEEK_CUR);
for (;;) {
- if (do_read_check(handle, &option, 2))
+ if (read2(handle, &option))
return -1;
if (option == TRACECMD_OPTION_DONE)
break;
/* next 4 bytes is the size of the option */
- if (do_read_check(handle, &size, 4))
+ if (read4(handle, &size))
return -1;
- size = tep_read_number(handle->pevent, &size, 4);
buf = malloc(size);
if (!buf)
return -ENOMEM;
--
2.31.1
next prev parent reply other threads:[~2021-09-13 12:28 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-13 12:27 [PATCH v2 00/21] trace-cmd fixes and clean-ups Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` Tzvetomir Stoyanov (VMware) [this message]
2021-09-13 12:27 ` [PATCH v2 02/21] trace-cmd report: Fix typos in error messages Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 03/21] trace-cmd library: Fix version string memory leak Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 04/21] trace-cmd library: Fixed a memory leak on input handler close Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 05/21] trace-cmd library: Do not pass guests list to a buffer instance Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 06/21] trace-cmd library: Set long size to the input tep handler when it is read from the file Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 07/21] trace-cmd library: Do not use local variables when reading CPU stat option Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 08/21] trace-cmd library: Reuse within the library the function that checks file state Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 09/21] trace-cmd library: Fix possible memory leak in read_ftrace_files() Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 10/21] trace-cmd library: Fix possible memory leak in read_event_files() Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 11/21] trace-cmd library: Fix possible memory leak in read_proc_kallsyms() Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 12/21] trace-cmd library: Fix possible memory leak in read_ftrace_printk() Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 13/21] trace-cmd library: Fix possible memory leak in read_and_parse_cmdlines() Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 14/21] trace-cmd library: Set input handler default values in allocation function Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 15/21] trace-cmd library: Track maximum CPUs count in input handler Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 16/21] trace-cmd report: Close input file handlers on exit Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 17/21] trace-cmd report: Do not print empty buffer name Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 18/21] trace-cmd library: Set correct CPU to the record, retrieved with tracecmd_peek_data Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 19/21] trace-cmd library: Refactor APIs for creating output handler Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 20/21] trace-cmd library: Refactor the logic for writing trace data in the file Tzvetomir Stoyanov (VMware)
2021-09-13 12:27 ` [PATCH v2 21/21] trace-cmd report: Init the top trace instance earlier Tzvetomir Stoyanov (VMware)
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=20210913122759.3672494-2-tz.stoyanov@gmail.com \
--to=tz.stoyanov@gmail.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.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).