mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tip-bot for Ulrich Drepper <drepper@akkadia.org>
To: linux-tip-commits@vger.kernel.org
Cc: acme@redhat.com, linux-kernel@vger.kernel.org,
	eranian@google.com, paulus@samba.org, mingo@redhat.com,
	hpa@zytor.com, mingo@kernel.org, a.p.zijlstra@chello.nl,
	robert.richter@amd.com, drepper@gmail.com, drepper@akkadia.org,
	dsahern@gmail.com, tglx@linutronix.de
Subject: [tip:perf/core] perf tools: Cleanup realloc use
Date: Thu, 10 May 2012 23:25:29 -0700	[thread overview]
Message-ID: <tip-f3054c778e367d624ca0dfe68b8498b5c463a9d1@git.kernel.org> (raw)
In-Reply-To: <201204231304.q3ND4TFe020805@drepperk.user.openhosting.com>

Commit-ID:  f3054c778e367d624ca0dfe68b8498b5c463a9d1
Gitweb:     http://git.kernel.org/tip/f3054c778e367d624ca0dfe68b8498b5c463a9d1
Author:     Ulrich Drepper <drepper@akkadia.org>
AuthorDate: Mon, 23 Apr 2012 09:04:29 -0400
Committer:  Arnaldo Carvalho de Melo <acme@redhat.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@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/201204231304.q3ND4TFe020805@drepperk.user.openhosting.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.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);

      parent reply	other threads:[~2012-05-11  6:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-bot for Ulrich Drepper [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-f3054c778e367d624ca0dfe68b8498b5c463a9d1@git.kernel.org \
    --to=drepper@akkadia.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=drepper@gmail.com \
    --cc=dsahern@gmail.com \
    --cc=eranian@google.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulus@samba.org \
    --cc=robert.richter@amd.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®