Re: [PATCH] staging: rtl8723bs: use kzalloc_obj() instead of kzalloc()
From: Dan Carpenter
Date: Thu Feb 19 2026 - 03:18:44 EST
On Mon, Feb 16, 2026 at 09:17:33PM +0500, Mariyam Shahid wrote:
> Replace kzalloc() using sizeof(*ptr) with kzalloc_obj() to improve
> type safety. kzalloc_obj() ensures that the size allocated matches
> the type of the pointer automatically, which prevents potential
> mismatches if the pointer type is ever refactored.
>
> This change cleans up a checkpatch.pl warning:
> "Prefer kzalloc_obj over kzalloc with sizeof"
>
> Signed-off-by: Mariyam Shahid <mariyam.shahid135@xxxxxxxxx>
> ---
> drivers/staging/rtl8723bs/core/rtw_mlme.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme.c b/drivers/staging/rtl8723bs/core/rtw_mlme.c
> index 22dc36e8e38a..8cb9a760f763 100644
> --- a/drivers/staging/rtl8723bs/core/rtw_mlme.c
> +++ b/drivers/staging/rtl8723bs/core/rtw_mlme.c
> @@ -1954,7 +1954,7 @@ signed int rtw_set_key(struct adapter *adapter, struct security_priv *psecurityp
> }
>
> if (enqueue) {
> - pcmd = kzalloc(sizeof(*pcmd), GFP_KERNEL);
> + pcmd = kzalloc_obj(pcmd, GFP_KERNEL);
This introduces a bug. It should be kzalloc_obj(*pcmd with an asterisk.
Also there are several other conversions which are possible in this
file...
regards,
dan carpenter