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

perf header: perf_header__push_event() shouldn't die

Just propagate eventual errors.
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1262047716-23171-2-git-send-email-acme@infradead.org>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 769885f3
...@@ -105,24 +105,28 @@ struct perf_trace_event_type { ...@@ -105,24 +105,28 @@ struct perf_trace_event_type {
static int event_count; static int event_count;
static struct perf_trace_event_type *events; static struct perf_trace_event_type *events;
void perf_header__push_event(u64 id, const char *name) int perf_header__push_event(u64 id, const char *name)
{ {
if (strlen(name) > MAX_EVENT_NAME) if (strlen(name) > MAX_EVENT_NAME)
pr_warning("Event %s will be truncated\n", name); pr_warning("Event %s will be truncated\n", name);
if (!events) { if (!events) {
events = malloc(sizeof(struct perf_trace_event_type)); events = malloc(sizeof(struct perf_trace_event_type));
if (!events) if (events == NULL)
die("nomem"); return -ENOMEM;
} else { } else {
events = realloc(events, (event_count + 1) * sizeof(struct perf_trace_event_type)); struct perf_trace_event_type *nevents;
if (!events)
die("nomem"); nevents = realloc(events, (event_count + 1) * sizeof(*events));
if (nevents == NULL)
return -ENOMEM;
events = nevents;
} }
memset(&events[event_count], 0, sizeof(struct perf_trace_event_type)); memset(&events[event_count], 0, sizeof(struct perf_trace_event_type));
events[event_count].event_id = id; events[event_count].event_id = id;
strncpy(events[event_count].name, name, MAX_EVENT_NAME - 1); strncpy(events[event_count].name, name, MAX_EVENT_NAME - 1);
event_count++; event_count++;
return 0;
} }
char *perf_header__find_event(u64 id) char *perf_header__find_event(u64 id)
......
...@@ -64,7 +64,7 @@ int perf_header__write(struct perf_header *self, int fd, bool at_exit); ...@@ -64,7 +64,7 @@ int perf_header__write(struct perf_header *self, int fd, bool at_exit);
int 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); int 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);
......
...@@ -753,11 +753,11 @@ parse_event_symbols(const char **str, struct perf_event_attr *attr) ...@@ -753,11 +753,11 @@ parse_event_symbols(const char **str, struct perf_event_attr *attr)
return ret; return ret;
} }
static void store_event_type(const char *orgname) static int store_event_type(const char *orgname)
{ {
char filename[PATH_MAX], *c; char filename[PATH_MAX], *c;
FILE *file; FILE *file;
int id; int id, n;
sprintf(filename, "%s/", debugfs_path); sprintf(filename, "%s/", debugfs_path);
strncat(filename, orgname, strlen(orgname)); strncat(filename, orgname, strlen(orgname));
...@@ -769,11 +769,14 @@ static void store_event_type(const char *orgname) ...@@ -769,11 +769,14 @@ static void store_event_type(const char *orgname)
file = fopen(filename, "r"); file = fopen(filename, "r");
if (!file) if (!file)
return; return 0;
if (fscanf(file, "%i", &id) < 1) n = fscanf(file, "%i", &id);
die("cannot store event ID");
fclose(file); fclose(file);
perf_header__push_event(id, orgname); if (n < 1) {
pr_err("cannot store event ID\n");
return -EINVAL;
}
return perf_header__push_event(id, orgname);
} }
int parse_events(const struct option *opt __used, const char *str, int unset __used) int parse_events(const struct option *opt __used, const char *str, int unset __used)
...@@ -782,7 +785,8 @@ int parse_events(const struct option *opt __used, const char *str, int unset __u ...@@ -782,7 +785,8 @@ int parse_events(const struct option *opt __used, const char *str, int unset __u
enum event_result ret; enum event_result ret;
if (strchr(str, ':')) if (strchr(str, ':'))
store_event_type(str); if (store_event_type(str) < 0)
return -1;
for (;;) { for (;;) {
if (nr_counters == MAX_COUNTERS) if (nr_counters == MAX_COUNTERS)
......
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