Re: [PATCH v2] staging: rtl8723bs: os_dep: avoid NULL pointer dereference in rtw_cbuf_alloc

From: Shyam Sunder Reddy Padira

Date: Mon Apr 13 2026 - 19:57:45 EST


Apologies, the previous mail may not have reached the mailing list
correctly due to a mail client issue. Resending for visibility.

Thanks & Regards,
Shyam Sunder Reddy


On Tue, 14 Apr 2026 at 05:02, Shyam Sunder Reddy Padira
<shyamsunderreddypadira@xxxxxxxxx> wrote:
>
> Apologies, the previous mail had an incorrect To address.
>
> Resending correct recipients in the thread for visibility.
>
> Thanks,
> Shyam Sunder Reddy Padira
>
> On Tue, 14 Apr, 2026, 04:17 Shyam Sunder Reddy Padira, <shyamsunderreddypadira@xxxxxxxxx> wrote:
>>
>> The return value of kzalloc_flex() is used without
>> ensuring that the allocation succeeded, and the
>> pointer is dereferenced unconditionally.
>>
>> Guard the access to the allocated structure to
>> avoid a potential NULL pointer dereference if the
>> allocation fails.
>>
>> Fixes: 980cd426a25747daf8ed25e2a1904b2d26ffbb3d ("staging: rtl8723bs: replace rtw_zmalloc() with kzalloc()")
>>
>> Signed-off-by: Shyam Sunder Reddy Padira <shyamsunderreddypadira@xxxxxxxxx>
>> ---
>> changes in v2:
>> -Fixed spelling mistakes(dereference, potential)
>> -Added Fixes tag
>> ---
>> drivers/staging/rtl8723bs/os_dep/osdep_service.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/staging/rtl8723bs/os_dep/osdep_service.c b/drivers/staging/rtl8723bs/os_dep/osdep_service.c
>> index 7959daeabc6f..4cfdf7c62344 100644
>> --- a/drivers/staging/rtl8723bs/os_dep/osdep_service.c
>> +++ b/drivers/staging/rtl8723bs/os_dep/osdep_service.c
>> @@ -194,7 +194,8 @@ struct rtw_cbuf *rtw_cbuf_alloc(u32 size)
>> struct rtw_cbuf *cbuf;
>>
>> cbuf = kzalloc_flex(*cbuf, bufs, size);
>> - cbuf->size = size;
>> + if (cbuf)
>> + cbuf->size = size;
>>
>> return cbuf;
>> }
>> --
>> 2.43.0
>>
>>