From: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx> 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@xxxxxxxxxxx> --- 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