Re: [PATCH 6/7] perf auxtrace: Make auxtrace_queues__add_buffer() allocate struct buffer
From: Adrian Hunter
Date: Thu Apr 05 2018 - 02:18:04 EST
On 07/03/18 16:11, Arnaldo Carvalho de Melo wrote:
> Em Wed, Mar 07, 2018 at 10:06:50AM +0200, Adrian Hunter escreveu:
>> On 06/03/18 22:25, Arnaldo Carvalho de Melo wrote:
>>> Em Tue, Mar 06, 2018 at 11:13:17AM +0200, Adrian Hunter escreveu:
>>>> In preparation for supporting AUX area sampling buffers,
>>>> auxtrace_queues__add_buffer() needs to be more generic. To that end, move
>>>> memory allocation for struct buffer into it.
>>>>
>>>> Signed-off-by: Adrian Hunter <adrian.hunter@xxxxxxxxx>
>>>> ---
>>>> tools/perf/util/auxtrace.c | 54 +++++++++++++++++++++-------------------------
>>>> 1 file changed, 24 insertions(+), 30 deletions(-)
>>>>
>>>> diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
>>>> index fb357a00dd86..e1aff91c54a8 100644
>>>> --- a/tools/perf/util/auxtrace.c
>>>> +++ b/tools/perf/util/auxtrace.c
>>>> @@ -308,7 +308,11 @@ static int auxtrace_queues__add_buffer(struct auxtrace_queues *queues,
>>>> struct auxtrace_buffer *buffer,
>>>> struct auxtrace_buffer **buffer_ptr)
>>>> {
>>>> - int err;
>>>> + int err = -ENOMEM;
>>>> +
>>>> + buffer = memdup(buffer, sizeof(*buffer));
>>>
>>> this is a bit strange, why not make buffer a local variable in this
>>> function then?
>>
>> Do you mean the following?
>>
>> struct auxtrace_buffer *new_buf;
>>
>> new_buf = memdup(buffer, sizeof(*buffer));
>
> I hadn't noticed that you were using buffer as both r and l value :-\
>
> If all you want is to receive that buffer, duplicate it and then use
> just the duplicate, not needing any reference to the original buffer,
> then your code is correct, it just looked strange from a quick look, so
> nevermind, I'll continue processing this one and the others.
Looks like this patch and patch 7 "perf auxtrace: Make
auxtrace_queues__add_buffer() do CPU filtering" got left behind. They still
apply cleanly.