aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/header.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2009-12-28 19:48:32 -0500
committerIngo Molnar <mingo@elte.hu>2009-12-30 05:59:56 -0500
commit769885f372300a7fcfb9e54e4e2990718d40b529 (patch)
treeaf466762d61d853ff9d0ba69309968bdab730d0f /tools/perf/util/header.c
parent63bbd5e2d539c9290b229c832f62d42aac23db94 (diff)
perf header: Do_read shouldn't die
Propagate the errors instead, its callers already propagate other 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-1-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util/header.c')
-rw-r--r--tools/perf/util/header.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index df237c3a041b..6b3cb94e8a2b 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -432,19 +432,19 @@ int perf_header__write(struct perf_header *self, int fd, bool at_exit)
432 return 0; 432 return 0;
433} 433}
434 434
435static void do_read(int fd, void *buf, size_t size) 435static int do_read(int fd, void *buf, size_t size)
436{ 436{
437 while (size) { 437 while (size) {
438 int ret = read(fd, buf, size); 438 int ret = read(fd, buf, size);
439 439
440 if (ret < 0) 440 if (ret <= 0)
441 die("failed to read"); 441 return -1;
442 if (ret == 0)
443 die("failed to read: missing data");
444 442
445 size -= ret; 443 size -= ret;
446 buf += ret; 444 buf += ret;
447 } 445 }
446
447 return 0;
448} 448}
449 449
450int perf_header__process_sections(struct perf_header *self, int fd, 450int 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 int nr_sections; 455 int nr_sections;
456 int sec_size; 456 int sec_size;
457 int idx = 0; 457 int idx = 0;
458 int err = 0, feat = 1; 458 int err = -1, feat = 1;
459 459
460 nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS); 460 nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS);
461 if (!nr_sections) 461 if (!nr_sections)
@@ -469,8 +469,10 @@ int perf_header__process_sections(struct perf_header *self, int fd,
469 469
470 lseek(fd, self->data_offset + self->data_size, SEEK_SET); 470 lseek(fd, self->data_offset + self->data_size, SEEK_SET);
471 471
472 do_read(fd, feat_sec, sec_size); 472 if (do_read(fd, feat_sec, sec_size))
473 goto out_free;
473 474
475 err = 0;
474 while (idx < nr_sections && feat < HEADER_LAST_FEATURE) { 476 while (idx < nr_sections && feat < HEADER_LAST_FEATURE) {
475 if (perf_header__has_feat(self, feat)) { 477 if (perf_header__has_feat(self, feat)) {
476 struct perf_file_section *sec = &feat_sec[idx++]; 478 struct perf_file_section *sec = &feat_sec[idx++];
@@ -481,18 +483,18 @@ int perf_header__process_sections(struct perf_header *self, int fd,
481 } 483 }
482 ++feat; 484 ++feat;
483 } 485 }
484 486out_free:
485 free(feat_sec); 487 free(feat_sec);
486 return err; 488 return err;
487}; 489}
488 490
489int perf_file_header__read(struct perf_file_header *self, 491int perf_file_header__read(struct perf_file_header *self,
490 struct perf_header *ph, int fd) 492 struct perf_header *ph, int fd)
491{ 493{
492 lseek(fd, 0, SEEK_SET); 494 lseek(fd, 0, SEEK_SET);
493 do_read(fd, self, sizeof(*self));
494 495
495 if (self->magic != PERF_MAGIC || 496 if (do_read(fd, self, sizeof(*self)) ||
497 self->magic != PERF_MAGIC ||
496 self->attr_size != sizeof(struct perf_file_attr)) 498 self->attr_size != sizeof(struct perf_file_attr))
497 return -1; 499 return -1;
498 500
@@ -558,7 +560,8 @@ int perf_header__read(struct perf_header *self, int fd)
558 struct perf_header_attr *attr; 560 struct perf_header_attr *attr;
559 off_t tmp; 561 off_t tmp;
560 562
561 do_read(fd, &f_attr, sizeof(f_attr)); 563 if (do_read(fd, &f_attr, sizeof(f_attr)))
564 goto out_errno;
562 tmp = lseek(fd, 0, SEEK_CUR); 565 tmp = lseek(fd, 0, SEEK_CUR);
563 566
564 attr = perf_header_attr__new(&f_attr.attr); 567 attr = perf_header_attr__new(&f_attr.attr);
@@ -569,7 +572,8 @@ int perf_header__read(struct perf_header *self, int fd)
569 lseek(fd, f_attr.ids.offset, SEEK_SET); 572 lseek(fd, f_attr.ids.offset, SEEK_SET);
570 573
571 for (j = 0; j < nr_ids; j++) { 574 for (j = 0; j < nr_ids; j++) {
572 do_read(fd, &f_id, sizeof(f_id)); 575 if (do_read(fd, &f_id, sizeof(f_id)))
576 goto out_errno;
573 577
574 if (perf_header_attr__add_id(attr, f_id) < 0) { 578 if (perf_header_attr__add_id(attr, f_id) < 0) {
575 perf_header_attr__delete(attr); 579 perf_header_attr__delete(attr);
@@ -589,7 +593,8 @@ int perf_header__read(struct perf_header *self, int fd)
589 events = malloc(f_header.event_types.size); 593 events = malloc(f_header.event_types.size);
590 if (events == NULL) 594 if (events == NULL)
591 return -ENOMEM; 595 return -ENOMEM;
592 do_read(fd, events, f_header.event_types.size); 596 if (do_read(fd, events, f_header.event_types.size))
597 goto out_errno;
593 event_count = f_header.event_types.size / sizeof(struct perf_trace_event_type); 598 event_count = f_header.event_types.size / sizeof(struct perf_trace_event_type);
594 } 599 }
595 600
@@ -599,6 +604,8 @@ int perf_header__read(struct perf_header *self, int fd)
599 604
600 self->frozen = 1; 605 self->frozen = 1;
601 return 0; 606 return 0;
607out_errno:
608 return -errno;
602} 609}
603 610
604u64 perf_header__sample_type(struct perf_header *header) 611u64 perf_header__sample_type(struct perf_header *header)