Skip to contentSkip to conversation

trace-cmd: compile warning fixes

PATCH Superseded Darren Hart 1 participant 2 messages Feb 1, 2010

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover trace-cmd: compile warning fixes

The following series fixes a few minor compiler warnings. These are mostly printf format type issues. Also includes an uninitialized variable fix.

--
Darren Hart
IBM Linux Technology Center
Real-Time Linux Team

#1 lore raw

PATCH 1/3 trace-cmd: Handle empty CPUs without crashing

From: Steven Rostedt <[email protected]>

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.

---
 trace-input.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)
trace-input.c +13 -3
index 0c7f9ad..69c2ce7 100644
@@ -678,6 +678,10 @@ static int get_page(struct tracecmd_input *handle, int cpu,
 	    handle->cpu_data[cpu].page)
 		return 1;
 
+	/* Do not map no data for CPU */
+	if (!handle->cpu_data[cpu].size)
+		return -1;
+
 	if (offset & (handle->page_size - 1)) {
 		errno = -EINVAL;
 		die("bad page offset %llx", offset);
@@ -941,7 +945,7 @@ int tracecmd_refresh_record(struct tracecmd_input *handle,
 	page_offset = record->offset & ~(handle->page_size - 1);
 	index = record->offset & (handle->page_size - 1);
 
-	ret = get_page(handle, record->cpu, page_offset) < 0;
+	ret =get_page(handle, record->cpu, page_offset);
 	if (ret < 0)
 		return -1;
 
@@ -976,7 +980,9 @@ int tracecmd_refresh_record(struct tracecmd_input *handle,
 struct record *
 tracecmd_read_cpu_first(struct tracecmd_input *handle, int cpu)
 {
-	get_page(handle, cpu, handle->cpu_data[cpu].file_offset);
+	if (get_page(handle, cpu, handle->cpu_data[cpu].file_offset) < 0)
+		return NULL;
+
 	handle->cpu_data[cpu].index = 0;
 	if (handle->cpu_data[cpu].next) {
 		free_record(handle->cpu_data[cpu].next);
@@ -1009,7 +1015,8 @@ tracecmd_read_cpu_last(struct tracecmd_input *handle, int cpu)
 	else
 		offset -= handle->page_size;
 
-	get_page(handle, cpu, offset);
+	if (get_page(handle, cpu, offset) < 0)
+		return NULL;
 
 	do {
 		free_record(record);
@@ -1048,6 +1055,9 @@ tracecmd_set_cpu_to_timestamp(struct tracecmd_input *handle, int cpu,
 		return -1;
 	}
 
+	if (!cpu_data->size)
+		return -1;
+
 	if (!cpu_data->page) {
 		if (init_cpu(handle, cpu))
 		    return -1;
Signature · 1 line
1.6.3.3