Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtla: Fix segmentation fault when failing to enable -t

rtla osnoise and timerlat are causing a segmentation fault when running
with the --trace option on a kernel that does not support multiple
instances. For example:

[root@f34 rtla]# rtla osnoise top -t
failed to enable the tracer osnoise
Could not enable osnoiser tracer for tracing
Failed to enable the trace instance
Segmentation fault (core dumped)

This error happens because the exit code of the tools is trying
to destroy the trace instance that failed to be created.

Make osnoise_destroy_tool() aware of possible NULL osnoise_tool *,
and do not attempt to destroy it. This also simplifies the exit code.

Link: https://lkml.kernel.org/r/5660a2b6bf66c2655842360f2d7f6b48db5dba23.1644327249.git.bristot@kernel.org

Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Fixes: 1eceb2fc2ca5 ("rtla/osnoise: Add osnoise top mode")
Fixes: 829a6c0b5698 ("rtla/osnoise: Add the hist mode")
Fixes: a828cd18bc4a ("rtla: Add timerlat tool and timelart top mode")
Fixes: 1eeb6328e8b3 ("rtla/timerlat: Add timerlat hist mode")
Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

authored by

Daniel Bristot de Oliveira and committed by
Steven Rostedt (Google)
4bbf59a9 1a622909

+15 -16
+3
tools/tracing/rtla/src/osnoise.c
··· 750 750 */ 751 751 void osnoise_destroy_tool(struct osnoise_tool *top) 752 752 { 753 + if (!top) 754 + return; 755 + 753 756 trace_instance_destroy(&top->trace); 754 757 755 758 if (top->context)
+3 -4
tools/tracing/rtla/src/osnoise_hist.c
··· 701 701 int osnoise_hist_main(int argc, char *argv[]) 702 702 { 703 703 struct osnoise_hist_params *params; 704 + struct osnoise_tool *record = NULL; 705 + struct osnoise_tool *tool = NULL; 704 706 struct trace_instance *trace; 705 - struct osnoise_tool *record; 706 - struct osnoise_tool *tool; 707 707 int return_value = 1; 708 708 int retval; 709 709 ··· 792 792 out_hist: 793 793 osnoise_free_histogram(tool->data); 794 794 out_destroy: 795 + osnoise_destroy_tool(record); 795 796 osnoise_destroy_tool(tool); 796 - if (params->trace_output) 797 - osnoise_destroy_tool(record); 798 797 free(params); 799 798 out_exit: 800 799 exit(return_value);
+3 -4
tools/tracing/rtla/src/osnoise_top.c
··· 483 483 int osnoise_top_main(int argc, char **argv) 484 484 { 485 485 struct osnoise_top_params *params; 486 + struct osnoise_tool *record = NULL; 487 + struct osnoise_tool *tool = NULL; 486 488 struct trace_instance *trace; 487 - struct osnoise_tool *record; 488 - struct osnoise_tool *tool; 489 489 int return_value = 1; 490 490 int retval; 491 491 ··· 571 571 572 572 out_top: 573 573 osnoise_free_top(tool->data); 574 + osnoise_destroy_tool(record); 574 575 osnoise_destroy_tool(tool); 575 - if (params->trace_output) 576 - osnoise_destroy_tool(record); 577 576 out_exit: 578 577 exit(return_value); 579 578 }
+3 -4
tools/tracing/rtla/src/timerlat_hist.c
··· 729 729 int timerlat_hist_main(int argc, char *argv[]) 730 730 { 731 731 struct timerlat_hist_params *params; 732 + struct osnoise_tool *record = NULL; 733 + struct osnoise_tool *tool = NULL; 732 734 struct trace_instance *trace; 733 - struct osnoise_tool *record; 734 - struct osnoise_tool *tool; 735 735 int return_value = 1; 736 736 int retval; 737 737 ··· 813 813 814 814 out_hist: 815 815 timerlat_free_histogram(tool->data); 816 + osnoise_destroy_tool(record); 816 817 osnoise_destroy_tool(tool); 817 - if (params->trace_output) 818 - osnoise_destroy_tool(record); 819 818 free(params); 820 819 out_exit: 821 820 exit(return_value);
+3 -4
tools/tracing/rtla/src/timerlat_top.c
··· 521 521 int timerlat_top_main(int argc, char *argv[]) 522 522 { 523 523 struct timerlat_top_params *params; 524 + struct osnoise_tool *record = NULL; 525 + struct osnoise_tool *top = NULL; 524 526 struct trace_instance *trace; 525 - struct osnoise_tool *record; 526 - struct osnoise_tool *top; 527 527 int return_value = 1; 528 528 int retval; 529 529 ··· 609 609 610 610 out_top: 611 611 timerlat_free_top(top->data); 612 + osnoise_destroy_tool(record); 612 613 osnoise_destroy_tool(top); 613 - if (params->trace_output) 614 - osnoise_destroy_tool(record); 615 614 free(params); 616 615 out_exit: 617 616 exit(return_value);