Re: [PATCH iwl-next] i40e: Use correct buffer size

From: Kunwu Chan
Date: Wed Nov 22 2023 - 01:57:27 EST


Thanks you again for your reply.
I learned. I know how to use it, thanks, I'll look at the existing code and add logs to see how it works.

Thanks again.


On 2023/11/21 19:15, Alexander Lobakin wrote:
From: Kunwu Chan <chentao@xxxxxxxxxx>
Date: Tue, 21 Nov 2023 10:12:17 +0800

Thanks for your reply. I understand what you mean, i.e. the caller of
'kasprintf' is responsible for calling 'kfree' to free up memory.

My concern is that in many scenarios, the requested memory will be
released after a period of use.

Has anyone else forgotten to free up the requested memory when using
'kasprintf'? e.g. 'dam_heap_init' calls 'dma_heap_devnode' to allocate
memory:
dam_heap_init
    -> dma_heap_devnode
          -> kasprintf
            ->kvasprintf
                 ->kmalloc_node_track_caller
                  -> __kmalloc_node_track_caller
                      -> __do_kmalloc_node
                          -> kasan_kmalloc


There is no function like 'dam_heap_exit' to free the memmory allocated
by dma_heap_devnode.

Another case is 'cpuid_devnode'. Will this cause a memory leak, and is
there a better way to avoid the memory leak in this case?

Or is there a uniform place in the memory management module to free up
this memory?

If the lifetime of the allocated buffer equals to the lifetime of the
kernel, i.e. it's allocated once at kernel init and then used throughout
the whole uptime, there's no need to free this piece.
Temporary buffers or buffers allocated from a driver are a different
story, their lifetime is shorter, which means you always need to
manually free each of them on exit.


Thanks,
Kunwu
Thanks,
Olek