mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
	linux-kernel@vger.kernel.org, David Ahern <dsahern@gmail.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Jiri Olsa <jolsa@redhat.com>, Paul Mackerras <paulus@samba.org>,
	Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list
Date: Fri, 24 Oct 2014 17:38:49 +0300	[thread overview]
Message-ID: <544A6479.8030601@intel.com> (raw)
In-Reply-To: <544A63FE.60902@intel.com>

On 24/10/2014 5:36 p.m., Adrian Hunter wrote:
> On 24/10/2014 4:21 p.m., Arnaldo Carvalho de Melo wrote:
>> Em Fri, Oct 24, 2014 at 10:03:20AM -0300, Arnaldo Carvalho de Melo escreveu:
>>> Em Fri, Oct 24, 2014 at 09:57:02AM -0300, Arnaldo Carvalho de Melo escreveu:
>>>> Em Fri, Oct 24, 2014 at 02:15:52PM +0900, Namhyung Kim escreveu:
>>>>> On Thu, 23 Oct 2014 13:45:10 +0300, Adrian Hunter wrote:
>>>>>> +        if (pmu->selectable) {
>>>>>> +            scnprintf(buf, sizeof(buf), "%s//", pmu->name);
>>>>>> +            aliases[j] = strdup(buf);
>>>>>
>>>>> You need to check the return value here (and above too).
>>>>
>>>> Well spotted, fixing this up.
>>>
>>> Oh well, this print_pmu_events() function needs some care, it starts by
>>> trying to alloc the array, if it fails, it silently returns, does that
>>> mean that there are no pmu events? Or that memory allocation failed?
>>>
>>> Ok, will do the fixes in a separate patch...
>>>
>>> - Arnaldo
>>
>> The patch below should check everything and warn the user, even
>> maintaining that void return...
>>
>> Acked-by tags welcome as always :-)
>>
>> - Arnaldo
>>
>>
>> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
>> index 91dca60..881b754 100644
>> --- a/tools/perf/util/pmu.c
>> +++ b/tools/perf/util/pmu.c
>> @@ -753,9 +753,9 @@ void print_pmu_events(const char *event_glob, bool name_only)
>>           if (pmu->selectable)
>>               len++;
>>       }
>> -    aliases = malloc(sizeof(char *) * len);
>> +    aliases = zalloc(sizeof(char *) * len);
>>       if (!aliases)
>> -        return;
>> +        goto out_enomem;
>
> That path tries to free aliases[j] but aliases is null.  You could set len to 0 in that case.

Than again, no it doesn't sorry for the noise.

>
>>       pmu = NULL;
>>       j = 0;
>>       while ((pmu = perf_pmu__scan(pmu)) != NULL) {
>> @@ -768,16 +768,20 @@ void print_pmu_events(const char *event_glob, bool name_only)
>>                     (!is_cpu && strglobmatch(alias->name,
>>                                  event_glob))))
>>                   continue;
>> -            aliases[j] = name;
>> +
>>               if (is_cpu && !name_only)
>> -                aliases[j] = format_alias_or(buf, sizeof(buf),
>> -                                  pmu, alias);
>> -            aliases[j] = strdup(aliases[j]);
>> +                name = format_alias_or(buf, sizeof(buf), pmu, alias);
>> +
>> +            aliases[j] = strdup(name);
>> +            if (aliases[j] == NULL)
>> +                goto out_enomem;
>>               j++;
>>           }
>>           if (pmu->selectable) {
>> -            scnprintf(buf, sizeof(buf), "%s//", pmu->name);
>> -            aliases[j] = strdup(buf);
>> +            char *s;
>> +            if (asprintf(&s, "%s//", pmu->name) < 0)
>> +                goto out_enomem;
>> +            aliases[j] = s;
>>               j++;
>>           }
>>       }
>> @@ -789,12 +793,20 @@ void print_pmu_events(const char *event_glob, bool name_only)
>>               continue;
>>           }
>>           printf("  %-50s [Kernel PMU event]\n", aliases[j]);
>> -        zfree(&aliases[j]);
>>           printed++;
>>       }
>>       if (printed)
>>           printf("\n");
>> -    free(aliases);
>> +out_free:
>> +    for (j = 0; j < len; j++)
>> +        zfree(&aliases[j]);
>> +    zfree(&aliases);
>> +    return;
>> +
>> +out_enomem:
>> +    printf("FATAL: not enough memory to print PMU events\n");
>> +    if (aliases)
>> +        goto out_free;
>>   }
>>
>>   bool pmu_have_event(const char *pname, const char *name)
>>

  reply	other threads:[~2014-10-24 14:38 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-23 10:45 [PATCH 00/16] perf tools: Intel PT preparation continued Adrian Hunter
2014-10-23 10:45 ` [PATCH 01/16] perf tools: Add id index Adrian Hunter
2014-10-23 21:08   ` Arnaldo Carvalho de Melo
2014-10-24  5:10     ` Namhyung Kim
2014-10-24  7:25     ` Adrian Hunter
2014-10-29  8:55       ` Jiri Olsa
2014-10-23 10:45 ` [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list Adrian Hunter
2014-10-24  5:15   ` Namhyung Kim
2014-10-24 12:57     ` Arnaldo Carvalho de Melo
2014-10-24 13:03       ` Arnaldo Carvalho de Melo
2014-10-24 13:21         ` Arnaldo Carvalho de Melo
2014-10-24 14:36           ` Adrian Hunter
2014-10-24 14:38             ` Adrian Hunter [this message]
2014-10-24 14:45             ` Arnaldo Carvalho de Melo
2014-10-24 15:35               ` Arnaldo Carvalho de Melo
2014-10-30  6:45   ` [tip:perf/core] perf pmu: Let pmu' s " tip-bot for Adrian Hunter
2014-10-23 10:45 ` [PATCH 03/16] perf session: Add perf_session__deliver_synth_event() Adrian Hunter
2014-10-24  5:22   ` Namhyung Kim
2014-10-24 10:41     ` Adrian Hunter
2014-10-23 10:45 ` [PATCH 04/16] perf tools: Add a thread stack for synthesizing call chains Adrian Hunter
2014-10-23 20:51   ` Arnaldo Carvalho de Melo
2014-10-24  8:47     ` Adrian Hunter
2014-10-24  5:41   ` Namhyung Kim
2014-10-29  9:03   ` Jiri Olsa
2014-10-29  9:07   ` Jiri Olsa
2014-10-23 10:45 ` [PATCH 05/16] perf tools: Add facility to export data in database-friendly way Adrian Hunter
2014-10-23 21:42   ` Arnaldo Carvalho de Melo
2014-10-24  6:02   ` Namhyung Kim
2014-10-24  8:11     ` Adrian Hunter
2014-10-24 10:47       ` Adrian Hunter
2014-10-24 12:26         ` Namhyung Kim
2014-10-24 13:13           ` Adrian Hunter
2014-10-24 14:40             ` Arnaldo Carvalho de Melo
2014-10-24 14:41               ` Arnaldo Carvalho de Melo
2014-10-30  6:46   ` [tip:perf/core] " tip-bot for Adrian Hunter
2014-10-23 10:45 ` [PATCH 06/16] perf tools: Extend Python script interface to export data in a " Adrian Hunter
2014-10-30  6:47   ` [tip:perf/core] perf scripting python: Extend " tip-bot for Adrian Hunter
2014-10-23 10:45 ` [PATCH 07/16] perf tools: Add Python script to export to postgresql Adrian Hunter
2014-10-30  6:47   ` [tip:perf/core] perf script: " tip-bot for Adrian Hunter
2014-10-23 10:45 ` [PATCH 08/16] perf tools: Add branch type to db export Adrian Hunter
2014-10-23 10:45 ` [PATCH 09/16] perf tools: Add branch_type and in_tx to Python export Adrian Hunter
2014-10-23 10:45 ` [PATCH 10/16] perf tools: Enhance the thread stack to output call/return data Adrian Hunter
2014-10-29 13:23   ` Jiri Olsa
2014-10-29 14:02     ` Arnaldo Carvalho de Melo
2014-10-23 10:45 ` [PATCH 11/16] perf tools: Add call information to the database export API Adrian Hunter
2014-10-23 10:45 ` [PATCH 12/16] perf tools: Add call information to Python export Adrian Hunter
2014-10-23 10:45 ` [PATCH 13/16] perf tools: Defer export of comms that were not 'set' Adrian Hunter
2014-10-23 10:45 ` [PATCH 14/16] perf tools: Build programs to copy 32-bit compatibility VDSOs Adrian Hunter
2014-10-30  6:45   ` [tip:perf/core] perf tools: Build programs to copy 32-bit compatibility tip-bot for Adrian Hunter
2014-10-23 10:45 ` [PATCH 15/16] perf tools: Add support for 32-bit compatibility VDSOs Adrian Hunter
2014-10-30  6:45   ` [tip:perf/core] " tip-bot for Adrian Hunter
2014-10-23 10:45 ` [PATCH 16/16] perf tools: Do not attempt to run perf-read-vdso32 if it wasn't built Adrian Hunter
2014-10-30  6:46   ` [tip:perf/core] " tip-bot for Adrian Hunter
2014-10-23 21:11 ` [PATCH 00/16] perf tools: Intel PT preparation continued Arnaldo Carvalho de Melo
2014-10-23 23:43 ` Arnaldo Carvalho de Melo

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=544A6479.8030601@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namhyung@kernel.org \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.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

Powered by JetHome