diff mbox series

[03/26] trace-cmd: Simplify add_guest()

Message ID 20220514024756.1319681-4-rostedt@goodmis.org (mailing list archive)
State Accepted
Commit ae9f80b268907e242b1f151a98c6445f67fba0bc
Headers show
Series trace-cmd: Add agent proxy (agent on the host) | expand

Commit Message

Steven Rostedt May 14, 2022, 2:47 a.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Simplify the function add_guest by using a local variable to point to the
array element instead of dereferencing the array every time.

Link: https://lore.kernel.org/linux-trace-devel/20220428150635.789051-3-rostedt@goodmis.org

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 tracecmd/trace-vm.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/tracecmd/trace-vm.c b/tracecmd/trace-vm.c
index 47f8d96a4015..7a91038d75dc 100644
--- a/tracecmd/trace-vm.c
+++ b/tracecmd/trace-vm.c
@@ -56,18 +56,22 @@  bool trace_have_guests_pid(void)
 
 static struct trace_guest *add_guest(unsigned int cid, const char *name)
 {
+	struct trace_guest *guest;
+
 	guests = realloc(guests, (guests_len + 1) * sizeof(*guests));
 	if (!guests)
 		die("allocating new guest");
-	memset(&guests[guests_len], 0, sizeof(struct trace_guest));
-	guests[guests_len].name = strdup(name);
-	if (!guests[guests_len].name)
+
+	guest = &guests[guests_len++];
+
+	memset(guest, 0, sizeof(*guest));
+	guest->name = strdup(name);
+	if (!guest->name)
 		die("allocating guest name");
-	guests[guests_len].cid = cid;
-	guests[guests_len].pid = -1;
-	guests_len++;
+	guest->cid = cid;
+	guest->pid = -1;
 
-	return &guests[guests_len - 1];
+	return guest;
 }
 
 static struct tracefs_instance *start_trace_connect(void)