Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754468AbZKPVaj (ORCPT ); Mon, 16 Nov 2009 16:30:39 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754444AbZKPVaf (ORCPT ); Mon, 16 Nov 2009 16:30:35 -0500 Received: from casper.infradead.org ([85.118.1.10]:55225 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754368AbZKPVae (ORCPT ); Mon, 16 Nov 2009 16:30:34 -0500 From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Frederic Weisbecker , Mike Galbraith , Paul Mackerras , Peter Zijlstra Subject: [PATCH 1/2] perf tools: Don't die in perf_header_attr__new Date: Mon, 16 Nov 2009 19:30:26 -0200 Message-Id: <1258407027-384-1-git-send-email-acme@infradead.org> X-Mailer: git-send-email 1.6.2.5 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3149 Lines: 103 From: Arnaldo Carvalho de Melo We really should propagate such kinds of errors so that users of these library functions decide what to do in such cases instead of exiting in random places like now. Cc: Frederic Weisbecker Cc: Mike Galbraith Cc: Paul Mackerras Cc: Peter Zijlstra Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-record.c | 5 ++++- tools/perf/util/header.c | 22 ++++++++++++---------- tools/perf/util/header.h | 4 +--- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 04f335e..4c03bb7 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -220,7 +220,8 @@ static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int n h_attr = header->attr[nr]; } else { h_attr = perf_header_attr__new(a); - perf_header__add_attr(header, h_attr); + if (h_attr != NULL) + perf_header__add_attr(header, h_attr); } return h_attr; @@ -308,6 +309,8 @@ try_again: } h_attr = get_header_attr(attr, counter); + if (h_attr == NULL) + die("nomem\n"); if (!file_new) { if (memcmp(&h_attr->attr, attr, sizeof(*attr))) { diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index d8416f0..2f07a23 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -19,16 +19,16 @@ struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr) { struct perf_header_attr *self = malloc(sizeof(*self)); - if (!self) - die("nomem"); - - self->attr = *attr; - self->ids = 0; - self->size = 1; - self->id = malloc(sizeof(u64)); - - if (!self->id) - die("nomem"); + if (self != NULL) { + self->attr = *attr; + self->ids = 0; + self->size = 1; + self->id = malloc(sizeof(u64)); + if (self->id == NULL) { + free(self); + self = NULL; + } + } return self; } @@ -423,6 +423,8 @@ struct perf_header *perf_header__read(int fd) tmp = lseek(fd, 0, SEEK_CUR); attr = perf_header_attr__new(&f_attr.attr); + if (attr == NULL) + die("nomem"); nr_ids = f_attr.ids.size / sizeof(u64); lseek(fd, f_attr.ids.offset, SEEK_SET); diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index f1b3bf7..0cbd4c9 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -64,9 +64,7 @@ void perf_header__add_attr(struct perf_header *self, void perf_header__push_event(u64 id, const char *name); 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__add_id(struct perf_header_attr *self, u64 id); u64 perf_header__sample_type(struct perf_header *header); -- 1.6.2.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/