All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] trace-cmd/timesync: Remove double check of finding the protocol
@ 2021-02-17 20:50 Steven Rostedt
  0 siblings, 0 replies; only message in thread
From: Steven Rostedt @ 2021-02-17 20:50 UTC (permalink / raw)
  To: Linux Trace Devel

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

In the two locations that call clock_context_init(), the protocol is
searched for via tsync_proto_find() to test if it has clock_sync_calc set.
clock_context_init() then does another tsync_proto_find(). Instead of having
this duplicate search, have clock_context_init() do the search and check if
clock_sync_calc is set, and return the protocol back to the caller on
success.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 lib/trace-cmd/trace-timesync.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/lib/trace-cmd/trace-timesync.c b/lib/trace-cmd/trace-timesync.c
index 9cbed775..8d01c0bc 100644
--- a/lib/trace-cmd/trace-timesync.c
+++ b/lib/trace-cmd/trace-timesync.c
@@ -327,7 +327,8 @@ clock_synch_delete_instance(struct tracefs_instance *inst)
 	tracefs_instance_free(inst);
 }
 
-static int clock_context_init(struct tracecmd_time_sync *tsync, bool guest)
+static int clock_context_init(struct tracecmd_time_sync *tsync,
+			      struct tsync_proto **proto, bool guest)
 {
 	struct clock_sync_context *clock = NULL;
 	struct tsync_proto *protocol;
@@ -336,7 +337,7 @@ static int clock_context_init(struct tracecmd_time_sync *tsync, bool guest)
 		return 0;
 
 	protocol = tsync_proto_find(tsync->proto_name);
-	if (!protocol)
+	if (!protocol || !protocol->clock_sync_calc)
 		return -1;
 
 	clock = calloc(1, sizeof(struct clock_sync_context));
@@ -359,6 +360,8 @@ static int clock_context_init(struct tracecmd_time_sync *tsync, bool guest)
 	if (protocol->clock_sync_init && protocol->clock_sync_init(tsync) < 0)
 		goto error;
 
+	*proto = protocol;
+
 	return 0;
 error:
 	tsync->context = NULL;
@@ -432,11 +435,7 @@ void tracecmd_tsync_with_host(struct tracecmd_time_sync *tsync)
 	unsigned int command;
 	int ret;
 
-	proto = tsync_proto_find(tsync->proto_name);
-	if (!proto || !proto->clock_sync_calc)
-		return;
-
-	clock_context_init(tsync, true);
+	clock_context_init(tsync, &proto, true);
 	if (!tsync->context)
 		return;
 
@@ -534,11 +533,7 @@ void tracecmd_tsync_with_guest(struct tracecmd_time_sync *tsync)
 	bool end = false;
 	int ret;
 
-	proto = tsync_proto_find(tsync->proto_name);
-	if (!proto || !proto->clock_sync_calc)
-		return;
-
-	clock_context_init(tsync, false);
+	clock_context_init(tsync, &proto, false);
 	if (!tsync->context)
 		return;
 
-- 
2.25.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-02-17 20:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-17 20:50 [PATCH] trace-cmd/timesync: Remove double check of finding the protocol Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.