lkml.org 
[lkml]   [2022]   [Jun]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH v5 4/8] perf headers: Store pmu caps in an array of strings
From
Hi Namhyung,

On 03-Jun-22 3:07 AM, Namhyung Kim wrote:
> On Tue, May 31, 2022 at 8:28 PM Ravi Bangoria <ravi.bangoria@amd.com> wrote:
>>
>> Currently all capabilities are stored in a single string separated
>> by NULL character. Instead, store them in an array which makes
>> searching of capability easier.
>>
>> Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
>> ---
> [SNIP]
>> @@ -3231,12 +3226,16 @@ static int process_per_cpu_pmu_caps(struct feat_fd *ff, int *nr_cpu_pmu_caps,
>> if (!value)
>> goto free_name;
>>
>> - if (strbuf_addf(&sb, "%s=%s", name, value) < 0)
>> + name_size = strlen(name);
>> + value_size = strlen(value);
>> + ptr = zalloc(sizeof(char) * (name_size + value_size + 2));
>> + if (!ptr)
>> goto free_value;
>>
>> - /* include a NULL character at the end */
>> - if (strbuf_add(&sb, "", 1) < 0)
>> - goto free_value;
>> + memcpy(ptr, name, name_size);
>> + ptr[name_size] = '=';
>> + memcpy(ptr + name_size + 1, value, value_size);
>
> What about using asprintf() instead?

Yeah asprintf() would make that code bit simpler. I think I'll have to
respin the series :)

Thanks,
Ravi

\
 
 \ /
  Last update: 2022-06-03 07:22    [W:0.324 / U:0.100 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site