Re: [PATCH v2] media: imx-jpeg: convert kzalloc_obj() to devm_kzalloc()
From: Sanjay Chitroda
Date: Mon Mar 09 2026 - 22:58:57 EST
On 9 March 2026 9:23:57 pm IST, Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx> wrote:
>On 08.03.2026 11:35:54, Sanjay Chitroda wrote:
>> From: Sanjay Chitroda <sanjayembeddedse@xxxxxxxxx>
>>
>> The driver allcoates memory using kzalloc_obj() and frees it in the relase
>> path. since the allocated memory is tied to the lifetime of the device,
>> devm_kzalloc() can be used instead.
>
>What happens if you issue multiple open()/close() cycles per device
>lifetime? Will the memory pile up, until the mxc_jpeg_remove() function
>is called?
You are correct.
Since the context structure is allocated in .open() and released in
.release(), its lifetime is tied to the file handle rather than the
device.
Using devm_kzalloc() would defer freeing the memory until device
removal, which could cause memory accumulation across multiple
open()/close() cycles.
I'll drop this change.
>
>> Using device-managed allocation simplifies the error handling paths and
>> remove the need for manual cleanup.
>>
>> No functional change intended.
>
>Marc
>