Messages in this thread | | | Date | Tue, 21 Nov 2023 12:15:30 +0100 | Subject | Re: [PATCH iwl-next] i40e: Use correct buffer size | From | Alexander Lobakin <> |
| |
From: Kunwu Chan <chentao@kylinos.cn> 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
| |