[PATCH v2] staging: rtl8723bs: use kzalloc_obj() instead of kzalloc()

Mariyam Shahid posted 1 patch 2 weeks, 1 day ago
drivers/staging/rtl8723bs/core/rtw_mlme.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH v2] staging: rtl8723bs: use kzalloc_obj() instead of kzalloc()
Posted by Mariyam Shahid 2 weeks, 1 day ago
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@gmail.com>
---

v2: Resending now that kzalloc_obj() is available in the tree.

 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);
 		if (!pcmd) {
 			kfree(psetkeyparm);
 			res = _FAIL;  /* try again */
-- 
2.43.0
Re: [PATCH v2] staging: rtl8723bs: use kzalloc_obj() instead of kzalloc()
Posted by Ethan Tidmore 2 weeks, 1 day ago
On Tue Feb 17, 2026 at 4:34 AM CST, 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@gmail.com>
> ---
>
> v2: Resending now that kzalloc_obj() is available in the tree.
>

Just updated my staging-next tree and kzalloc_obj() isn't there? Make
sure you're using staging-next when creating patches for staging.

>  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);

You still need to dereference pcmd here or this doesn't compile. Please
at least compile test your patches before sending them off.

Thanks,

ET