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

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

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-1-git-send-email-acme@infradead.org>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 1124ba73
...@@ -221,7 +221,10 @@ static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int n ...@@ -221,7 +221,10 @@ static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int n
} else { } else {
h_attr = perf_header_attr__new(a); h_attr = perf_header_attr__new(a);
if (h_attr != NULL) if (h_attr != NULL)
perf_header__add_attr(header, h_attr); if (perf_header__add_attr(header, h_attr) < 0) {
perf_header_attr__delete(h_attr);
h_attr = NULL;
}
} }
return h_attr; return h_attr;
......
...@@ -33,6 +33,12 @@ struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr) ...@@ -33,6 +33,12 @@ struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr)
return self; return self;
} }
void perf_header_attr__delete(struct perf_header_attr *self)
{
free(self->id);
free(self);
}
void perf_header_attr__add_id(struct perf_header_attr *self, u64 id) void perf_header_attr__add_id(struct perf_header_attr *self, u64 id)
{ {
int pos = self->ids; int pos = self->ids;
...@@ -66,22 +72,28 @@ struct perf_header *perf_header__new(void) ...@@ -66,22 +72,28 @@ struct perf_header *perf_header__new(void)
return self; return self;
} }
void perf_header__add_attr(struct perf_header *self, int perf_header__add_attr(struct perf_header *self,
struct perf_header_attr *attr) struct perf_header_attr *attr)
{ {
int pos = self->attrs; int pos = self->attrs;
if (self->frozen) if (self->frozen)
die("frozen"); return -1;
self->attrs++; self->attrs++;
if (self->attrs > self->size) { if (self->attrs > self->size) {
self->size *= 2; int nsize = self->size * 2;
self->attr = realloc(self->attr, self->size * sizeof(void *)); struct perf_header_attr **nattr;
if (!self->attr)
die("nomem"); nattr = realloc(self->attr, nsize * sizeof(void *));
if (nattr == NULL)
return -1;
self->size = nsize;
self->attr = nattr;
} }
self->attr[pos] = attr; self->attr[pos] = attr;
return 0;
} }
#define MAX_EVENT_NAME 64 #define MAX_EVENT_NAME 64
...@@ -434,7 +446,9 @@ struct perf_header *perf_header__read(int fd) ...@@ -434,7 +446,9 @@ struct perf_header *perf_header__read(int fd)
perf_header_attr__add_id(attr, f_id); perf_header_attr__add_id(attr, f_id);
} }
perf_header__add_attr(self, attr); if (perf_header__add_attr(self, attr) < 0)
die("nomem");
lseek(fd, tmp, SEEK_SET); lseek(fd, tmp, SEEK_SET);
} }
......
...@@ -58,13 +58,15 @@ struct perf_header { ...@@ -58,13 +58,15 @@ struct perf_header {
struct perf_header *perf_header__read(int fd); struct perf_header *perf_header__read(int fd);
void perf_header__write(struct perf_header *self, int fd, bool at_exit); void perf_header__write(struct perf_header *self, int fd, bool at_exit);
void perf_header__add_attr(struct perf_header *self, int perf_header__add_attr(struct perf_header *self,
struct perf_header_attr *attr); struct perf_header_attr *attr);
void perf_header__push_event(u64 id, const char *name); void perf_header__push_event(u64 id, const char *name);
char *perf_header__find_event(u64 id); 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__add_id(struct perf_header_attr *self, u64 id); void 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);
......
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