Skip to content

Commit ae99fb2

Browse files
acmelIngo Molnar
authored andcommitted
perf header: perf_header__push_event() shouldn't die
Just propagate eventual errors. Signed-off-by: Arnaldo 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: Ingo Molnar <mingo@elte.hu>
1 parent 769885f commit ae99fb2

3 files changed

Lines changed: 22 additions & 14 deletions

File tree

‎tools/perf/util/header.c‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,28 @@ struct perf_trace_event_type {
105105
static int event_count;
106106
static struct perf_trace_event_type *events;
107107

108-
void perf_header__push_event(u64 id, const char *name)
108+
int perf_header__push_event(u64 id, const char *name)
109109
{
110110
if (strlen(name) > MAX_EVENT_NAME)
111111
pr_warning("Event %s will be truncated\n", name);
112112

113113
if (!events) {
114114
events = malloc(sizeof(struct perf_trace_event_type));
115-
if (!events)
116-
die("nomem");
115+
if (events == NULL)
116+
return -ENOMEM;
117117
} else {
118-
events = realloc(events, (event_count + 1) * sizeof(struct perf_trace_event_type));
119-
if (!events)
120-
die("nomem");
118+
struct perf_trace_event_type *nevents;
119+
120+
nevents = realloc(events, (event_count + 1) * sizeof(*events));
121+
if (nevents == NULL)
122+
return -ENOMEM;
123+
events = nevents;
121124
}
122125
memset(&events[event_count], 0, sizeof(struct perf_trace_event_type));
123126
events[event_count].event_id = id;
124127
strncpy(events[event_count].name, name, MAX_EVENT_NAME - 1);
125128
event_count++;
129+
return 0;
126130
}
127131

128132
char *perf_header__find_event(u64 id)

‎tools/perf/util/header.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int perf_header__write(struct perf_header *self, int fd, bool at_exit);
6464
int perf_header__add_attr(struct perf_header *self,
6565
struct perf_header_attr *attr);
6666

67-
void perf_header__push_event(u64 id, const char *name);
67+
int perf_header__push_event(u64 id, const char *name);
6868
char *perf_header__find_event(u64 id);
6969

7070
struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr);

‎tools/perf/util/parse-events.c‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -753,11 +753,11 @@ parse_event_symbols(const char **str, struct perf_event_attr *attr)
753753
return ret;
754754
}
755755

756-
static void store_event_type(const char *orgname)
756+
static int store_event_type(const char *orgname)
757757
{
758758
char filename[PATH_MAX], *c;
759759
FILE *file;
760-
int id;
760+
int id, n;
761761

762762
sprintf(filename, "%s/", debugfs_path);
763763
strncat(filename, orgname, strlen(orgname));
@@ -769,11 +769,14 @@ static void store_event_type(const char *orgname)
769769

770770
file = fopen(filename, "r");
771771
if (!file)
772-
return;
773-
if (fscanf(file, "%i", &id) < 1)
774-
die("cannot store event ID");
772+
return 0;
773+
n = fscanf(file, "%i", &id);
775774
fclose(file);
776-
perf_header__push_event(id, orgname);
775+
if (n < 1) {
776+
pr_err("cannot store event ID\n");
777+
return -EINVAL;
778+
}
779+
return perf_header__push_event(id, orgname);
777780
}
778781

779782
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
782785
enum event_result ret;
783786

784787
if (strchr(str, ':'))
785-
store_event_type(str);
788+
if (store_event_type(str) < 0)
789+
return -1;
786790

787791
for (;;) {
788792
if (nr_counters == MAX_COUNTERS)

0 commit comments

Comments
 (0)