Re: [PATCH 2/3] perf disasm: Use disasm_line__free() to properly free disasm_line

From: Li Huafei
Date: Sat Oct 19 2024 - 03:47:49 EST




On 2024/10/15 21:55, Athira Rajeev wrote:
>
>
>> On 14 Oct 2024, at 5:12 PM, Li Huafei <lihuafei1@xxxxxxxxxx> wrote:
>>
>> The structure disasm_line contains members that require dynamically
>> allocated memory and need to be freed correctly using
>> disasm_line__free().
>>
>> This patch fixes the incorrect freeing in
>> symbol__disassemble_capstone_powerpc(). Also, since cs_disasm is not
>> enabled, it does not need to handle the situation described in
>> symbol__disassemble_capstone() where "offset != len" may occur due to
>> unknown instructions.
>>
>> Fixes: c5d60de1813a ("perf annotate: Add support to use libcapstone in powerpc")
>> Signed-off-by: Li Huafei <lihuafei1@xxxxxxxxxx>
>
> For the patches
>
> Tested-by: Athira Rajeev <atrajeev@xxxxxxxxxxxxxxxxxx <mailto:atrajeev@xxxxxxxxxxxxxxxxxx>>
>

Thank you for the testing. As suggested by Namhyung in patch 3, the
patches need some modifications. I have sent v2, and if there are any
issues with v2, please let me know.

Thanks,
Huafei

> Thanks
> Athira
>> ---
>> tools/perf/util/disasm.c | 16 +---------------
>> 1 file changed, 1 insertion(+), 15 deletions(-)
>>
>> diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
>> index 42222d61ceb5..40d99f4d5cc7 100644
>> --- a/tools/perf/util/disasm.c
>> +++ b/tools/perf/util/disasm.c
>> @@ -1580,20 +1580,6 @@ static int symbol__disassemble_capstone_powerpc(char *filename, struct symbol *s
>> offset += 4;
>> }
>>
>> - /* It failed in the middle */
>> - if (offset != len) {
>> - struct list_head *list = &notes->src->source;
>> -
>> - /* Discard all lines and fallback to objdump */
>> - while (!list_empty(list)) {
>> - dl = list_first_entry(list, struct disasm_line, al.node);
>> -
>> - list_del_init(&dl->al.node);
>> - disasm_line__free(dl);
>> - }
>> - count = -1;
>> - }
>> -
>> out:
>> if (needs_cs_close)
>> cs_close(&handle);
>> @@ -1612,7 +1598,7 @@ static int symbol__disassemble_capstone_powerpc(char *filename, struct symbol *s
>> */
>> list_for_each_entry_safe(dl, tmp, &notes->src->source, al.node) {
>> list_del(&dl->al.node);
>> - free(dl);
>> + disasm_line__free(dl);
>> }
>> }
>> count = -1;
>> --
>> 2.25.1
>>
>
>
> .
>