Skip to content

Commit 2a6b52e

Browse files
Wan Jiabingrostedt
authored andcommitted
rtla: Avoid record NULL pointer dereference
Fix the following null/deref_null.cocci errors: ./tools/tracing/rtla/src/osnoise_hist.c:870:31-36: ERROR: record is NULL but dereferenced. ./tools/tracing/rtla/src/osnoise_top.c:650:31-36: ERROR: record is NULL but dereferenced. ./tools/tracing/rtla/src/timerlat_hist.c:905:31-36: ERROR: record is NULL but dereferenced. ./tools/tracing/rtla/src/timerlat_top.c:700:31-36: ERROR: record is NULL but dereferenced. "record" is NULL before calling osnoise_init_trace_tool. Add a tag "out_free" to avoid dereferring a NULL pointer. Link: https://lkml.kernel.org/r/ae0e4500d383db0884eb2820286afe34ca303778.1651247710.git.bristot@kernel.org Link: https://lore.kernel.org/r/20220408151406.34823-1-wanjiabing@vivo.com/ Cc: kael_w@yeah.net Cc: Daniel Bristot de Oliveira <bristot@kernel.org> Fixes: 51d64c3 ("rtla: Add -e/--event support") Acked-by: Daniel Bristot de Oliveira <bristot@kernel.org> Signed-off-by: Wan Jiabing <wanjiabing@vivo.com> Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent fe4d0d5 commit 2a6b52e

4 files changed

Lines changed: 20 additions & 16 deletions

File tree

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ int osnoise_hist_main(int argc, char *argv[])
809809
retval = set_comm_sched_attr("osnoise/", &params->sched_param);
810810
if (retval) {
811811
err_msg("Failed to set sched parameters\n");
812-
goto out_hist;
812+
goto out_free;
813813
}
814814
}
815815

@@ -819,7 +819,7 @@ int osnoise_hist_main(int argc, char *argv[])
819819
record = osnoise_init_trace_tool("osnoise");
820820
if (!record) {
821821
err_msg("Failed to enable the trace instance\n");
822-
goto out_hist;
822+
goto out_free;
823823
}
824824

825825
if (params->events) {
@@ -869,6 +869,7 @@ int osnoise_hist_main(int argc, char *argv[])
869869
out_hist:
870870
trace_events_destroy(&record->trace, params->events);
871871
params->events = NULL;
872+
out_free:
872873
osnoise_free_histogram(tool->data);
873874
out_destroy:
874875
osnoise_destroy_tool(record);

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,22 +572,22 @@ int osnoise_top_main(int argc, char **argv)
572572
retval = osnoise_top_apply_config(tool, params);
573573
if (retval) {
574574
err_msg("Could not apply config\n");
575-
goto out_top;
575+
goto out_free;
576576
}
577577

578578
trace = &tool->trace;
579579

580580
retval = enable_osnoise(trace);
581581
if (retval) {
582582
err_msg("Failed to enable osnoise tracer\n");
583-
goto out_top;
583+
goto out_free;
584584
}
585585

586586
if (params->set_sched) {
587587
retval = set_comm_sched_attr("osnoise/", &params->sched_param);
588588
if (retval) {
589589
err_msg("Failed to set sched parameters\n");
590-
goto out_top;
590+
goto out_free;
591591
}
592592
}
593593

@@ -597,7 +597,7 @@ int osnoise_top_main(int argc, char **argv)
597597
record = osnoise_init_trace_tool("osnoise");
598598
if (!record) {
599599
err_msg("Failed to enable the trace instance\n");
600-
goto out_top;
600+
goto out_free;
601601
}
602602

603603
if (params->events) {
@@ -649,6 +649,7 @@ int osnoise_top_main(int argc, char **argv)
649649
out_top:
650650
trace_events_destroy(&record->trace, params->events);
651651
params->events = NULL;
652+
out_free:
652653
osnoise_free_top(tool->data);
653654
osnoise_destroy_tool(record);
654655
osnoise_destroy_tool(tool);

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -821,30 +821,30 @@ int timerlat_hist_main(int argc, char *argv[])
821821
retval = timerlat_hist_apply_config(tool, params);
822822
if (retval) {
823823
err_msg("Could not apply config\n");
824-
goto out_hist;
824+
goto out_free;
825825
}
826826

827827
trace = &tool->trace;
828828

829829
retval = enable_timerlat(trace);
830830
if (retval) {
831831
err_msg("Failed to enable timerlat tracer\n");
832-
goto out_hist;
832+
goto out_free;
833833
}
834834

835835
if (params->set_sched) {
836836
retval = set_comm_sched_attr("timerlat/", &params->sched_param);
837837
if (retval) {
838838
err_msg("Failed to set sched parameters\n");
839-
goto out_hist;
839+
goto out_free;
840840
}
841841
}
842842

843843
if (params->dma_latency >= 0) {
844844
dma_latency_fd = set_cpu_dma_latency(params->dma_latency);
845845
if (dma_latency_fd < 0) {
846846
err_msg("Could not set /dev/cpu_dma_latency.\n");
847-
goto out_hist;
847+
goto out_free;
848848
}
849849
}
850850

@@ -854,7 +854,7 @@ int timerlat_hist_main(int argc, char *argv[])
854854
record = osnoise_init_trace_tool("timerlat");
855855
if (!record) {
856856
err_msg("Failed to enable the trace instance\n");
857-
goto out_hist;
857+
goto out_free;
858858
}
859859

860860
if (params->events) {
@@ -904,6 +904,7 @@ int timerlat_hist_main(int argc, char *argv[])
904904
close(dma_latency_fd);
905905
trace_events_destroy(&record->trace, params->events);
906906
params->events = NULL;
907+
out_free:
907908
timerlat_free_histogram(tool->data);
908909
osnoise_destroy_tool(record);
909910
osnoise_destroy_tool(tool);

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -612,30 +612,30 @@ int timerlat_top_main(int argc, char *argv[])
612612
retval = timerlat_top_apply_config(top, params);
613613
if (retval) {
614614
err_msg("Could not apply config\n");
615-
goto out_top;
615+
goto out_free;
616616
}
617617

618618
trace = &top->trace;
619619

620620
retval = enable_timerlat(trace);
621621
if (retval) {
622622
err_msg("Failed to enable timerlat tracer\n");
623-
goto out_top;
623+
goto out_free;
624624
}
625625

626626
if (params->set_sched) {
627627
retval = set_comm_sched_attr("timerlat/", &params->sched_param);
628628
if (retval) {
629629
err_msg("Failed to set sched parameters\n");
630-
goto out_top;
630+
goto out_free;
631631
}
632632
}
633633

634634
if (params->dma_latency >= 0) {
635635
dma_latency_fd = set_cpu_dma_latency(params->dma_latency);
636636
if (dma_latency_fd < 0) {
637637
err_msg("Could not set /dev/cpu_dma_latency.\n");
638-
goto out_top;
638+
goto out_free;
639639
}
640640
}
641641

@@ -645,7 +645,7 @@ int timerlat_top_main(int argc, char *argv[])
645645
record = osnoise_init_trace_tool("timerlat");
646646
if (!record) {
647647
err_msg("Failed to enable the trace instance\n");
648-
goto out_top;
648+
goto out_free;
649649
}
650650

651651
if (params->events) {
@@ -699,6 +699,7 @@ int timerlat_top_main(int argc, char *argv[])
699699
close(dma_latency_fd);
700700
trace_events_destroy(&record->trace, params->events);
701701
params->events = NULL;
702+
out_free:
702703
timerlat_free_top(top->data);
703704
osnoise_destroy_tool(record);
704705
osnoise_destroy_tool(top);

0 commit comments

Comments
 (0)