From: Ulrich Drepper <drepper@akkadia.org>
To: a.p.zijlstra@chello.nl, acme@ghostprotocols.net,
dsahern@gmail.com, eranian@google.com,
linux-kernel@vger.kernel.org, mingo@redhat.com, paulus@samba.org,
robert.richter@amd.com
Subject: [PATCH] Small perf cleanup
Date: Mon, 23 Apr 2012 09:04:29 -0400 [thread overview]
Message-ID: <201204231304.q3ND4TFe020805@drepperk.user.openhosting.com> (raw)
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);
next reply other threads:[~2012-04-23 13:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-23 13:04 Ulrich Drepper [this message]
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
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=201204231304.q3ND4TFe020805@drepperk.user.openhosting.com \
--to=drepper@akkadia.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@ghostprotocols.net \
--cc=dsahern@gmail.com \
--cc=eranian@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=paulus@samba.org \
--cc=robert.richter@amd.com \
/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®