Re: [PATCH] staging: rtl8723bs: use kzalloc_obj() instead of kzalloc()
From: Mariyam Shahid
Date: Fri Feb 20 2026 - 02:04:32 EST
On Thu, Feb 19, 2026 at 1:15 PM Dan Carpenter <dan.carpenter@xxxxxxxxxx> wrote:
>
> 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
>
Thank you for catching that! You're absolutely right. I’ll also go
through the rest of the file to address the other possible conversions
you mentioned and will send an updated patch (v3). Thanks for your
patience as I'm still getting the hang of the process!
regards,
Mariyam