Re: [PATCH] Input: cs40l50: Fix potential NULL dereference and memory leak
From: Dmitry Torokhov
Date: Fri Jul 04 2025 - 00:56:41 EST
Hi Yunshui,
On Fri, Jul 04, 2025 at 10:40:10AM +0800, Yunshui Jiang wrote:
> The cs40l50_upload_owt() function allocates memory via kmalloc()
> without checking for allocation failure, which could lead to a
> NULL pointer dereference when GFP_KERNEL allocation fails under
> memory pressure.
Yes, the check is indeed missing. It is likely that the allocation is
small enough so it always succeeds (or waits indefinitely), but it is a
good idea to add the check nevertheless.
>
> Additionally, if any subsequent operation fails after successful
> allocation, the allocated memory is not freed, causing a memory
> leak.
This is not correct. Because the new_owt_effect_data variable is
annotated as __free(kfree) it will be automatically freed at the end of
the function scope. Your patch introduces a double-free.
I will adjust to only keep the check and apply, thank you.
Thanks.
--
Dmitry