mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Darren Hart <dvhltc@us.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: rostedt@goodmis.org, Steven Rostedt <srostedt@redhat.com>
Subject: [PATCH 1/3] trace-cmd: Handle empty CPUs without crashing
Date: Mon,  1 Feb 2010 08:44:04 -0800	[thread overview]
Message-ID: <1265042646-24573-2-git-send-email-dvhltc@us.ibm.com> (raw)
In-Reply-To: <1265042646-24573-1-git-send-email-dvhltc@us.ibm.com>

From: Steven Rostedt <srostedt@redhat.com>

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>
---
 trace-input.c |   16 +++++++++++++---
 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,
 	    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;
-- 
1.6.3.3


      reply	other threads:[~2010-02-01 16:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-01 16:44 [PATCH 0/3] trace-cmd: compile warning fixes Darren Hart
2010-02-01 16:44 ` Darren Hart [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1265042646-24573-2-git-send-email-dvhltc@us.ibm.com \
    --to=dvhltc@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=srostedt@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®