From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Mike Galbraith <efault@gmx.de>, Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <peterz@infradead.org>
Subject: [PATCH 2/4] perf tools: Don't die() in perf_header_attr__add_id
Date: Tue, 17 Nov 2009 01:18:10 -0200 [thread overview]
Message-ID: <1258427892-16312-2-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1258427892-16312-1-git-send-email-acme@infradead.org>
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Propagate the errors instead, the users are the ones to decide what
to do if a library call fails.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-record.c | 5 ++++-
| 18 ++++++++++++------
| 2 +-
3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 5411be4..2a85205 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -327,7 +327,10 @@ try_again:
exit(-1);
}
- perf_header_attr__add_id(h_attr, read_data.id);
+ if (perf_header_attr__add_id(h_attr, read_data.id) < 0) {
+ pr_warning("Not enough memory to add id\n");
+ exit(-1);
+ }
assert(fd[nr_cpu][counter] >= 0);
fcntl(fd[nr_cpu][counter], F_SETFL, O_NONBLOCK);
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 23ccdda..dee1ed2 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -39,18 +39,23 @@ void perf_header_attr__delete(struct perf_header_attr *self)
free(self);
}
-void perf_header_attr__add_id(struct perf_header_attr *self, u64 id)
+int perf_header_attr__add_id(struct perf_header_attr *self, u64 id)
{
int pos = self->ids;
self->ids++;
if (self->ids > self->size) {
- self->size *= 2;
- self->id = realloc(self->id, self->size * sizeof(u64));
- if (!self->id)
- die("nomem");
+ int nsize = self->size * 2;
+ u64 *nid = realloc(self->id, nsize * sizeof(u64));
+
+ if (nid == NULL)
+ return -1;
+
+ self->size = nsize;
+ self->id = nid;
}
self->id[pos] = id;
+ return 0;
}
/*
@@ -444,7 +449,8 @@ struct perf_header *perf_header__read(int fd)
for (j = 0; j < nr_ids; j++) {
do_read(fd, &f_id, sizeof(f_id));
- perf_header_attr__add_id(attr, f_id);
+ if (perf_header_attr__add_id(attr, f_id) < 0)
+ die("nomem");
}
if (perf_header__add_attr(self, attr) < 0)
die("nomem");
--git a/tools/perf/util/header.h b/tools/perf/util/header.h
index b0d5cd7..f46a94e 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -67,7 +67,7 @@ char *perf_header__find_event(u64 id);
struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr);
void perf_header_attr__delete(struct perf_header_attr *self);
-void perf_header_attr__add_id(struct perf_header_attr *self, u64 id);
+int perf_header_attr__add_id(struct perf_header_attr *self, u64 id);
u64 perf_header__sample_type(struct perf_header *header);
struct perf_event_attr *
--
1.6.2.5
next prev parent reply other threads:[~2009-11-17 3:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-17 3:18 [PATCH 1/4] perf tools: Don't die() in perf_header__add_attr Arnaldo Carvalho de Melo
2009-11-17 3:18 ` Arnaldo Carvalho de Melo [this message]
2009-11-17 3:18 ` [PATCH 3/4] perf tools: Don't die() in perf_header__new Arnaldo Carvalho de Melo
2009-11-17 3:18 ` [PATCH 4/4] perf tools: Don't die() in do_write Arnaldo Carvalho de Melo
2009-11-17 6:33 ` [tip:perf/core] perf tools: Don't die() in do_write() tip-bot for Arnaldo Carvalho de Melo
2009-11-17 6:33 ` [tip:perf/core] perf tools: Don't die() in perf_header__new() tip-bot for Arnaldo Carvalho de Melo
2009-11-17 6:32 ` [tip:perf/core] perf tools: Don't die() in perf_header_attr__add_id() tip-bot for Arnaldo Carvalho de Melo
2009-11-17 6:32 ` [tip:perf/core] perf tools: Don't die() in perf_header__add_attr() tip-bot for Arnaldo Carvalho de Melo
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=1258427892-16312-2-git-send-email-acme@infradead.org \
--to=acme@infradead.org \
--cc=acme@redhat.com \
--cc=efault@gmx.de \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
/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®