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

perf header: Do_read shouldn't die

Propagate the errors instead, its callers already propagate
other 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-1-git-send-email-acme@infradead.org>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 63bbd5e2
...@@ -432,19 +432,19 @@ int perf_header__write(struct perf_header *self, int fd, bool at_exit) ...@@ -432,19 +432,19 @@ int perf_header__write(struct perf_header *self, int fd, bool at_exit)
return 0; return 0;
} }
static void do_read(int fd, void *buf, size_t size) static int do_read(int fd, void *buf, size_t size)
{ {
while (size) { while (size) {
int ret = read(fd, buf, size); int ret = read(fd, buf, size);
if (ret < 0) if (ret <= 0)
die("failed to read"); return -1;
if (ret == 0)
die("failed to read: missing data");
size -= ret; size -= ret;
buf += ret; buf += ret;
} }
return 0;
} }
int perf_header__process_sections(struct perf_header *self, int fd, int perf_header__process_sections(struct perf_header *self, int fd,
...@@ -455,7 +455,7 @@ int perf_header__process_sections(struct perf_header *self, int fd, ...@@ -455,7 +455,7 @@ int perf_header__process_sections(struct perf_header *self, int fd,
int nr_sections; int nr_sections;
int sec_size; int sec_size;
int idx = 0; int idx = 0;
int err = 0, feat = 1; int err = -1, feat = 1;
nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS); nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS);
if (!nr_sections) if (!nr_sections)
...@@ -469,8 +469,10 @@ int perf_header__process_sections(struct perf_header *self, int fd, ...@@ -469,8 +469,10 @@ int perf_header__process_sections(struct perf_header *self, int fd,
lseek(fd, self->data_offset + self->data_size, SEEK_SET); lseek(fd, self->data_offset + self->data_size, SEEK_SET);
do_read(fd, feat_sec, sec_size); if (do_read(fd, feat_sec, sec_size))
goto out_free;
err = 0;
while (idx < nr_sections && feat < HEADER_LAST_FEATURE) { while (idx < nr_sections && feat < HEADER_LAST_FEATURE) {
if (perf_header__has_feat(self, feat)) { if (perf_header__has_feat(self, feat)) {
struct perf_file_section *sec = &feat_sec[idx++]; struct perf_file_section *sec = &feat_sec[idx++];
...@@ -481,18 +483,18 @@ int perf_header__process_sections(struct perf_header *self, int fd, ...@@ -481,18 +483,18 @@ int perf_header__process_sections(struct perf_header *self, int fd,
} }
++feat; ++feat;
} }
out_free:
free(feat_sec); free(feat_sec);
return err; return err;
}; }
int perf_file_header__read(struct perf_file_header *self, int perf_file_header__read(struct perf_file_header *self,
struct perf_header *ph, int fd) struct perf_header *ph, int fd)
{ {
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
do_read(fd, self, sizeof(*self));
if (self->magic != PERF_MAGIC || if (do_read(fd, self, sizeof(*self)) ||
self->magic != PERF_MAGIC ||
self->attr_size != sizeof(struct perf_file_attr)) self->attr_size != sizeof(struct perf_file_attr))
return -1; return -1;
...@@ -558,7 +560,8 @@ int perf_header__read(struct perf_header *self, int fd) ...@@ -558,7 +560,8 @@ int perf_header__read(struct perf_header *self, int fd)
struct perf_header_attr *attr; struct perf_header_attr *attr;
off_t tmp; off_t tmp;
do_read(fd, &f_attr, sizeof(f_attr)); if (do_read(fd, &f_attr, sizeof(f_attr)))
goto out_errno;
tmp = lseek(fd, 0, SEEK_CUR); tmp = lseek(fd, 0, SEEK_CUR);
attr = perf_header_attr__new(&f_attr.attr); attr = perf_header_attr__new(&f_attr.attr);
...@@ -569,7 +572,8 @@ int perf_header__read(struct perf_header *self, int fd) ...@@ -569,7 +572,8 @@ int perf_header__read(struct perf_header *self, int fd)
lseek(fd, f_attr.ids.offset, SEEK_SET); lseek(fd, f_attr.ids.offset, SEEK_SET);
for (j = 0; j < nr_ids; j++) { for (j = 0; j < nr_ids; j++) {
do_read(fd, &f_id, sizeof(f_id)); if (do_read(fd, &f_id, sizeof(f_id)))
goto out_errno;
if (perf_header_attr__add_id(attr, f_id) < 0) { if (perf_header_attr__add_id(attr, f_id) < 0) {
perf_header_attr__delete(attr); perf_header_attr__delete(attr);
...@@ -589,7 +593,8 @@ int perf_header__read(struct perf_header *self, int fd) ...@@ -589,7 +593,8 @@ int perf_header__read(struct perf_header *self, int fd)
events = malloc(f_header.event_types.size); events = malloc(f_header.event_types.size);
if (events == NULL) if (events == NULL)
return -ENOMEM; return -ENOMEM;
do_read(fd, events, f_header.event_types.size); if (do_read(fd, events, f_header.event_types.size))
goto out_errno;
event_count = f_header.event_types.size / sizeof(struct perf_trace_event_type); event_count = f_header.event_types.size / sizeof(struct perf_trace_event_type);
} }
...@@ -599,6 +604,8 @@ int perf_header__read(struct perf_header *self, int fd) ...@@ -599,6 +604,8 @@ int perf_header__read(struct perf_header *self, int fd)
self->frozen = 1; self->frozen = 1;
return 0; return 0;
out_errno:
return -errno;
} }
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