Re: [PATCH v5 4/8] perf headers: Store pmu caps in an array of strings

From: Ravi Bangoria
Date: Fri Jun 03 2022 - 01:20:39 EST


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@xxxxxxx> 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@xxxxxxx>
>> ---
> [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