aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-01-15 09:36:07 -0500
committerSteven Rostedt <rostedt@goodmis.org>2010-01-15 09:36:07 -0500
commit85e11f10baf72f3272f3b9aa5aa9e27ecbdfcd77 (patch)
tree1ffec09fb79ad3d1106ac9ba85329eb5ed28a7dc
parent91a4a56506bdcdab7142788337d63df668839617 (diff)
trace-cmd: Handle empty CPUs without crashing
The get_page() needs to return -1 on reading a CPU that has no data. Also added checks of get_page() return status that was missing from some callers. Have tracecmd_set_cpu_to_timestamp() also return -1 when reading an empty CPU. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--trace-input.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/trace-input.c b/trace-input.c
index 0c7f9ad..69c2ce7 100644
--- a/trace-input.c
+++ b/trace-input.c
@@ -678,6 +678,10 @@ static int get_page(struct tracecmd_input *handle, int cpu,
678 handle->cpu_data[cpu].page) 678 handle->cpu_data[cpu].page)
679 return 1; 679 return 1;
680 680
681 /* Do not map no data for CPU */
682 if (!handle->cpu_data[cpu].size)
683 return -1;
684
681 if (offset & (handle->page_size - 1)) { 685 if (offset & (handle->page_size - 1)) {
682 errno = -EINVAL; 686 errno = -EINVAL;
683 die("bad page offset %llx", offset); 687 die("bad page offset %llx", offset);
@@ -941,7 +945,7 @@ int tracecmd_refresh_record(struct tracecmd_input *handle,
941 page_offset = record->offset & ~(handle->page_size - 1); 945 page_offset = record->offset & ~(handle->page_size - 1);
942 index = record->offset & (handle->page_size - 1); 946 index = record->offset & (handle->page_size - 1);
943 947
944 ret = get_page(handle, record->cpu, page_offset) < 0; 948 ret =get_page(handle, record->cpu, page_offset);
945 if (ret < 0) 949 if (ret < 0)
946 return -1; 950 return -1;
947 951
@@ -976,7 +980,9 @@ int tracecmd_refresh_record(struct tracecmd_input *handle,
976struct record * 980struct record *
977tracecmd_read_cpu_first(struct tracecmd_input *handle, int cpu) 981tracecmd_read_cpu_first(struct tracecmd_input *handle, int cpu)
978{ 982{
979 get_page(handle, cpu, handle->cpu_data[cpu].file_offset); 983 if (get_page(handle, cpu, handle->cpu_data[cpu].file_offset) < 0)
984 return NULL;
985
980 handle->cpu_data[cpu].index = 0; 986 handle->cpu_data[cpu].index = 0;
981 if (handle->cpu_data[cpu].next) { 987 if (handle->cpu_data[cpu].next) {
982 free_record(handle->cpu_data[cpu].next); 988 free_record(handle->cpu_data[cpu].next);
@@ -1009,7 +1015,8 @@ tracecmd_read_cpu_last(struct tracecmd_input *handle, int cpu)
1009 else 1015 else
1010 offset -= handle->page_size; 1016 offset -= handle->page_size;
1011 1017
1012 get_page(handle, cpu, offset); 1018 if (get_page(handle, cpu, offset) < 0)
1019 return NULL;
1013 1020
1014 do { 1021 do {
1015 free_record(record); 1022 free_record(record);
@@ -1048,6 +1055,9 @@ tracecmd_set_cpu_to_timestamp(struct tracecmd_input *handle, int cpu,
1048 return -1; 1055 return -1;
1049 } 1056 }
1050 1057
1058 if (!cpu_data->size)
1059 return -1;
1060
1051 if (!cpu_data->page) { 1061 if (!cpu_data->page) {
1052 if (init_cpu(handle, cpu)) 1062 if (init_cpu(handle, cpu))
1053 return -1; 1063 return -1;