linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] trace-cmd report: Avoid crash on unknown event
@ 2021-12-08 14:34 Vincent Whitchurch
  2021-12-08 14:45 ` Steven Rostedt
  0 siblings, 1 reply; 4+ messages in thread
From: Vincent Whitchurch @ 2021-12-08 14:34 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, kernel, Vincent Whitchurch

Do not segfault if the event cannot be found for some reason and
tep_find_event_by_record() returns NULL.

With this patch:

 kworker/u8:0-7 [003] 1.245773: sched_stat_runtime: comm=kworker/u8:...
[UNKNOWN EVENT][UNKNOWN EVENT] (NULL):               [UNKNOWN EVENT]
 kworker/u8:0-7 [003] 1.245776: sched_switch: kworker/u8:0:7 [120] W...

Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
 tracecmd/trace-read.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c
index 6f43c1d..df40b75 100644
--- a/tracecmd/trace-read.c
+++ b/tracecmd/trace-read.c
@@ -142,12 +142,13 @@ static struct trace_hash wakeup_hash;
 static void print_event_name(struct trace_seq *s, struct tep_event *event)
 {
 	static const char *spaces = "                    "; /* 20 spaces */
+	const char *name = event ? event->name : "(NULL)";
 	int len;
 
-	trace_seq_printf(s, " %s: ", event->name);
+	trace_seq_printf(s, " %s: ", name);
 
 	/* Space out the event names evenly. */
-	len = strlen(event->name);
+	len = strlen(name);
 	if (len < 20)
 		trace_seq_printf(s, "%.*s", 20 - len, spaces);
 }
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-08 15:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-08 14:34 [PATCH v2] trace-cmd report: Avoid crash on unknown event Vincent Whitchurch
2021-12-08 14:45 ` Steven Rostedt
2021-12-08 15:00   ` Vincent Whitchurch
2021-12-08 15:07     ` Steven Rostedt

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).