Commit 58754121 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo Committed by Ingo Molnar

perf tools: Don't die() in perf_header_attr__add_id()

Propagate the errors instead, the users are the ones to decide
what to do if a library call fails.
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
LKML-Reference: <1258427892-16312-2-git-send-email-acme@infradead.org>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 11deb1f9
...@@ -327,7 +327,10 @@ try_again: ...@@ -327,7 +327,10 @@ try_again:
exit(-1); 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); assert(fd[nr_cpu][counter] >= 0);
fcntl(fd[nr_cpu][counter], F_SETFL, O_NONBLOCK); fcntl(fd[nr_cpu][counter], F_SETFL, O_NONBLOCK);
......
...@@ -39,18 +39,23 @@ void perf_header_attr__delete(struct perf_header_attr *self) ...@@ -39,18 +39,23 @@ void perf_header_attr__delete(struct perf_header_attr *self)
free(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; int pos = self->ids;
self->ids++; self->ids++;
if (self->ids > self->size) { if (self->ids > self->size) {
self->size *= 2; int nsize = self->size * 2;
self->id = realloc(self->id, self->size * sizeof(u64)); u64 *nid = realloc(self->id, nsize * sizeof(u64));
if (!self->id)
die("nomem"); if (nid == NULL)
return -1;
self->size = nsize;
self->id = nid;
} }
self->id[pos] = id; self->id[pos] = id;
return 0;
} }
/* /*
...@@ -444,7 +449,8 @@ struct perf_header *perf_header__read(int fd) ...@@ -444,7 +449,8 @@ struct perf_header *perf_header__read(int fd)
for (j = 0; j < nr_ids; j++) { for (j = 0; j < nr_ids; j++) {
do_read(fd, &f_id, sizeof(f_id)); 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) if (perf_header__add_attr(self, attr) < 0)
die("nomem"); die("nomem");
......
...@@ -67,7 +67,7 @@ char *perf_header__find_event(u64 id); ...@@ -67,7 +67,7 @@ char *perf_header__find_event(u64 id);
struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr); 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__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); u64 perf_header__sample_type(struct perf_header *header);
struct perf_event_attr * struct perf_event_attr *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment