From: Namhyung Kim <namhyung.kim@lge.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
LKML <linux-kernel@vger.kernel.org>,
Ulrich Drepper <drepper@gmail.com>
Subject: Re: [PATCH 12/11] parse-events: Cleanup realloc use
Date: Tue, 15 May 2012 17:39:00 +0900 [thread overview]
Message-ID: <87r4ulzvmj.fsf@sejong.aot.lge.com> (raw)
In-Reply-To: <1335230984-7613-1-git-send-email-namhyung.kim@lge.com> (Namhyung Kim's message of "Tue, 24 Apr 2012 10:29:44 +0900")
Ping?
On Tue, 24 Apr 2012 10:29:44 +0900, Namhyung Kim wrote:
> The if branch is completely unnecessary since 'realloc' can
> handle NULL pointers for the first parameter.
>
> This patch is just an adoption of Ulrich Drepper's recent
> patch on perf tools.
>
> Cc: Ulrich Drepper <drepper@gmail.com>
> Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
> ---
> parse-events.c | 8 ++------
> parse-filter.c | 24 ++++++++----------------
> 2 files changed, 10 insertions(+), 22 deletions(-)
>
> diff --git a/parse-events.c b/parse-events.c
> index 3ccedd9..9779298 100644
> --- a/parse-events.c
> +++ b/parse-events.c
> @@ -627,12 +627,8 @@ static void add_event(struct pevent *pevent, struct event_format *event)
> {
> int i;
>
> - if (!pevent->events)
> - pevent->events = malloc_or_die(sizeof(event));
> - else
> - pevent->events =
> - realloc(pevent->events, sizeof(event) *
> - (pevent->nr_events + 1));
> + pevent->events = realloc(pevent->events, sizeof(event) *
> + (pevent->nr_events + 1));
> if (!pevent->events)
> die("Can not allocate events");
>
> diff --git a/parse-filter.c b/parse-filter.c
> index bc62f1f..79be550 100644
> --- a/parse-filter.c
> +++ b/parse-filter.c
> @@ -148,17 +148,11 @@ add_filter_type(struct event_filter *filter, int id)
> if (filter_type)
> return filter_type;
>
> - if (!filter->filters)
> - filter->event_filters =
> - malloc_or_die(sizeof(*filter->event_filters));
> - else {
> - filter->event_filters =
> - realloc(filter->event_filters,
> - sizeof(*filter->event_filters) *
> - (filter->filters + 1));
> - if (!filter->event_filters)
> - die("Could not allocate filter");
> - }
> + filter->event_filters = realloc(filter->event_filters,
> + sizeof(*filter->event_filters) *
> + (filter->filters + 1));
> + if (!filter->event_filters)
> + die("Could not allocate filter");
>
> for (i = 0; i < filter->filters; i++) {
> if (filter->event_filters[i].event_id > id)
> @@ -1481,7 +1475,7 @@ void pevent_filter_clear_trivial(struct event_filter *filter,
> {
> struct filter_type *filter_type;
> int count = 0;
> - int *ids;
> + int *ids = NULL;
> int i;
>
> if (!filter->filters)
> @@ -1505,10 +1499,8 @@ void pevent_filter_clear_trivial(struct event_filter *filter,
> default:
> break;
> }
> - if (count)
> - ids = realloc(ids, sizeof(*ids) * (count + 1));
> - else
> - ids = malloc(sizeof(*ids));
> +
> + ids = realloc(ids, sizeof(*ids) * (count + 1));
> if (!ids)
> die("Can't allocate ids");
> ids[count++] = filter_type->event_id;
next prev parent reply other threads:[~2012-05-15 8:40 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-23 4:58 [PATCH 00/11] trace-cmd: libparsevent cleanups - part 2 Namhyung Kim
2012-04-23 4:58 ` [PATCH 01/11] parse-events: Free flag/sym field on failure path Namhyung Kim
2012-04-23 16:21 ` Steven Rostedt
2012-04-24 0:05 ` Namhyung Kim
2012-04-24 1:07 ` [PATCH v2] " Namhyung Kim
2012-04-23 4:58 ` [PATCH 02/11] parse-events: Fix freeing arg on process_dynamic_array() Namhyung Kim
2012-04-23 16:34 ` Steven Rostedt
2012-04-23 4:58 ` [PATCH 03/11] parse-events: Get rid of handling concatenation on event_read_print Namhyung Kim
2012-04-23 16:33 ` Steven Rostedt
2012-04-24 0:09 ` Namhyung Kim
2012-04-24 0:26 ` Steven Rostedt
2012-04-23 4:58 ` [PATCH 04/11] parse-events: Remove unused arg->dynarray.index Namhyung Kim
2012-04-23 18:35 ` Steven Rostedt
2012-04-23 4:58 ` [PATCH 05/11] parse-events: Use proper function parameter type Namhyung Kim
2012-04-23 18:38 ` Steven Rostedt
2012-04-23 4:58 ` [PATCH 06/11] parse-events: Pass string type argument to args Namhyung Kim
2012-04-23 18:41 ` Steven Rostedt
2012-07-06 11:16 ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
2012-04-23 4:58 ` [PATCH 07/11] parse-events: Do not call add_event() again if allocation failed Namhyung Kim
2012-04-23 18:43 ` Steven Rostedt
2012-07-06 11:17 ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
2012-04-23 4:58 ` [PATCH 08/11] parse-events: Fix some comments Namhyung Kim
2012-04-23 18:47 ` Steven Rostedt
2012-07-06 11:18 ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
2012-04-23 4:58 ` [PATCH 09/11] parse-filter: Check result of malloc() during reading token Namhyung Kim
2012-04-23 18:48 ` Steven Rostedt
2012-04-24 0:15 ` Namhyung Kim
2012-07-06 11:19 ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
2012-04-23 4:58 ` [PATCH 10/11] parse-filter: Fix signature of create_arg_item() Namhyung Kim
2012-04-23 18:57 ` Steven Rostedt
2012-04-23 4:58 ` [PATCH 11/11] parse-filter: Check return value of arg_to_str() Namhyung Kim
2012-04-23 18:59 ` Steven Rostedt
2012-07-06 11:20 ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
2012-04-24 1:29 ` [PATCH 12/11] parse-events: Cleanup realloc use Namhyung Kim
2012-05-15 8:39 ` Namhyung Kim [this message]
2012-05-15 8:48 ` Steven Rostedt
2012-05-15 9:32 ` Namhyung Kim
2012-07-06 11:21 ` [tip:perf/core] tools lib traceevent: " tip-bot for Namhyung Kim
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=87r4ulzvmj.fsf@sejong.aot.lge.com \
--to=namhyung.kim@lge.com \
--cc=drepper@gmail.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/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