mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Small perf cleanup
@ 2012-04-23 13:04 Ulrich Drepper
  2012-04-23 18:39 ` Arnaldo Carvalho de Melo
  2012-05-11  6:25 ` [tip:perf/core] perf tools: Cleanup realloc use tip-bot for Ulrich Drepper
  0 siblings, 2 replies; 3+ messages in thread
From: Ulrich Drepper @ 2012-04-23 13:04 UTC (permalink / raw)
  To: a.p.zijlstra, acme, dsahern, eranian, linux-kernel, mingo,
	paulus, robert.richter

I just noticed this.  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@gmail.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);

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-05-11  6:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-23 13:04 [PATCH] Small perf cleanup Ulrich Drepper
2012-04-23 18:39 ` Arnaldo Carvalho de Melo
2012-05-11  6:25 ` [tip:perf/core] perf tools: Cleanup realloc use tip-bot for Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®