lkml.org 
[lkml]   [2012]   [May]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 01/15] perf tools: Cleanup realloc use
    Date
    From: Ulrich Drepper <drepper@akkadia.org>

    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 file 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);
    --
    1.7.9.2.358.g22243


    \
     
     \ /
      Last update: 2012-05-02 21:41    [W:0.027 / U:90.316 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site