[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <tip-f3054c778e367d624ca0dfe68b8498b5c463a9d1@git.kernel.org>
Date: Thu, 10 May 2012 23:25:29 -0700
From: tip-bot for Ulrich Drepper <drepper@...adia.org>
To: linux-tip-commits@...r.kernel.org
Cc: acme@...hat.com, linux-kernel@...r.kernel.org, eranian@...gle.com,
paulus@...ba.org, mingo@...hat.com, hpa@...or.com,
mingo@...nel.org, a.p.zijlstra@...llo.nl, robert.richter@....com,
drepper@...il.com, drepper@...adia.org, dsahern@...il.com,
tglx@...utronix.de
Subject: [tip:perf/core] perf tools: Cleanup realloc use
Commit-ID: f3054c778e367d624ca0dfe68b8498b5c463a9d1
Gitweb: http://git.kernel.org/tip/f3054c778e367d624ca0dfe68b8498b5c463a9d1
Author: Ulrich Drepper <drepper@...adia.org>
AuthorDate: Mon, 23 Apr 2012 09:04:29 -0400
Committer: Arnaldo Carvalho de Melo <acme@...hat.com>
CommitDate: Mon, 23 Apr 2012 15:33:05 -0300
perf tools: Cleanup realloc use
The if branch is completely unnecessary since 'realloc' handles NULL
pointers for the first parameter.
This is really only a cleanup and submitted mainly to prevent
proliferation of bad practices.
Signed-off-by: Ulrich Drepper <drepper@...il.com>
Cc: David Ahern <dsahern@...il.com>
Cc: Ingo Molnar <mingo@...hat.com>
Cc: Paul Mackerras <paulus@...ba.org>
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc: Robert Richter <robert.richter@....com>
Cc: Stephane Eranian <eranian@...gle.com>
Link: http://lkml.kernel.org/r/201204231304.q3ND4TFe020805@drepperk.user.openhosting.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>
---
tools/perf/util/header.c | 17 ++++++-----------
1 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 4c7c2d7..6e618ba 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -31,21 +31,16 @@ static const char **header_argv;
int perf_header__push_event(u64 id, const char *name)
{
+ struct perf_trace_event_type *nevents;
+
if (strlen(name) > MAX_EVENT_NAME)
pr_warning("Event %s will be truncated\n", name);
- if (!events) {
- events = malloc(sizeof(struct perf_trace_event_type));
- if (events == NULL)
- return -ENOMEM;
- } else {
- struct perf_trace_event_type *nevents;
+ nevents = realloc(events, (event_count + 1) * sizeof(*events));
+ if (nevents == NULL)
+ return -ENOMEM;
+ events = nevents;
- 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));
events[event_count].event_id = id;
strncpy(events[event_count].name, name, MAX_EVENT_NAME - 1);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists