linux-kernel.vger.kernel.org archive mirror
 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 related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Small perf cleanup
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-04-23 18:39 UTC (permalink / raw)
  To: Ulrich Drepper
  Cc: a.p.zijlstra, dsahern, eranian, linux-kernel, mingo, paulus,
	robert.richter

Em Mon, Apr 23, 2012 at 09:04:29AM -0400, Ulrich Drepper escreveu:
> 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.

Thanks, applied to my perf/core branch at:

http://git.kernel.org/?p=linux/kernel/git/acme/linux.git;a=shortlog;h=refs/heads/perf/core

- Arnaldo

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

* [tip:perf/core] perf tools: Cleanup realloc use
  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
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Ulrich Drepper @ 2012-05-11  6:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, eranian, paulus, mingo, hpa, mingo,
	a.p.zijlstra, robert.richter, drepper, drepper, dsahern, tglx

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);

^ permalink raw reply related	[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;
as well as URLs for NNTP newsgroup(s).