public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: rtl8723bs: use kzalloc_obj() instead of kzalloc()
@ 2026-02-16 16:17 Mariyam Shahid
  2026-02-17  1:07 ` Ethan Tidmore
  2026-02-19  8:15 ` Dan Carpenter
  0 siblings, 2 replies; 11+ messages in thread
From: Mariyam Shahid @ 2026-02-16 16:17 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Michael Straube, linux-staging, linux-kernel, Mariyam Shahid

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


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] staging: rtl8723bs: use kzalloc_obj() instead of kzalloc()
  2026-02-16 16:17 [PATCH] staging: rtl8723bs: use kzalloc_obj() instead of kzalloc() Mariyam Shahid
@ 2026-02-17  1:07 ` Ethan Tidmore
  2026-02-17  9:12   ` Mariyam Shahid
  2026-02-19  8:15 ` Dan Carpenter
  1 sibling, 1 reply; 11+ messages in thread
From: Ethan Tidmore @ 2026-02-17  1:07 UTC (permalink / raw)
  To: Mariyam Shahid, Greg Kroah-Hartman
  Cc: Michael Straube, linux-staging, linux-kernel

On Mon Feb 16, 2026 at 10:17 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>
> ---

Hi,

The macro kzalloc_obj() is not in staging-next yet, so you'll likely get
a kernel test robot email. So, wait until this macro is in this branch
and then send this patch.

Thanks,

ET

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] staging: rtl8723bs: use kzalloc_obj() instead of kzalloc()
  2026-02-17  1:07 ` Ethan Tidmore
@ 2026-02-17  9:12   ` Mariyam Shahid
  0 siblings, 0 replies; 11+ messages in thread
From: Mariyam Shahid @ 2026-02-17  9:12 UTC (permalink / raw)
  To: Ethan Tidmore
  Cc: Greg Kroah-Hartman, Michael Straube, linux-staging, linux-kernel

On Tue, Feb 17, 2026 at 6:07 AM Ethan Tidmore <ethantidmore06@gmail.com> wrote:
>
> On Mon Feb 16, 2026 at 10:17 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>
> > ---
>
> Hi,
>
> The macro kzalloc_obj() is not in staging-next yet, so you'll likely get
> a kernel test robot email. So, wait until this macro is in this branch
> and then send this patch.
>
> Thanks,
>
> ET

Hi,

Thank you for the heads-up. I will keep an eye on the branch and
resend this patch once kzalloc_obj() has been merged into
staging-next.

Best regards, Mariyam

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] staging: rtl8723bs: use kzalloc_obj() instead of kzalloc()
  2026-02-16 16:17 [PATCH] staging: rtl8723bs: use kzalloc_obj() instead of kzalloc() Mariyam Shahid
  2026-02-17  1:07 ` Ethan Tidmore
@ 2026-02-19  8:15 ` Dan Carpenter
  2026-02-20  7:03   ` Mariyam Shahid
  1 sibling, 1 reply; 11+ messages in thread
From: Dan Carpenter @ 2026-02-19  8:15 UTC (permalink / raw)
  To: Mariyam Shahid
  Cc: Greg Kroah-Hartman, Michael Straube, linux-staging, linux-kernel

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@gmail.com>
> ---
>  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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] staging: rtl8723bs: use kzalloc_obj() instead of kzalloc()
  2026-02-19  8:15 ` Dan Carpenter
@ 2026-02-20  7:03   ` Mariyam Shahid
  2026-02-21 11:10     ` [PATCH v3] staging: rtl8723bs: Replace kzalloc with kzalloc_obj Mariyam Shahid
  0 siblings, 1 reply; 11+ messages in thread
From: Mariyam Shahid @ 2026-02-20  7:03 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Greg Kroah-Hartman, Michael Straube, linux-staging, linux-kernel

On Thu, Feb 19, 2026 at 1:15 PM Dan Carpenter <dan.carpenter@linaro.org> 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@gmail.com>
> > ---
> >  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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3] staging: rtl8723bs: Replace kzalloc with kzalloc_obj
  2026-02-20  7:03   ` Mariyam Shahid
@ 2026-02-21 11:10     ` Mariyam Shahid
  2026-02-21 18:29       ` Ethan Tidmore
  2026-02-22 16:20       ` [PATCH v4] " Mariyam Shahid
  0 siblings, 2 replies; 11+ messages in thread
From: Mariyam Shahid @ 2026-02-21 11:10 UTC (permalink / raw)
  To: gregkh
  Cc: straube.linux, dan.carpenter, linux-staging, linux-kernel,
	Mariyam Shahid

Replace kzalloc() using sizeof(*ptr) with kzalloc_obj()
to fix respective checkpatch warnings.

Signed-off-by: Mariyam Shahid <mariyam.shahid135@gmail.com>
---
 drivers/staging/rtl8723bs/core/rtw_mlme.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme.c b/drivers/staging/rtl8723bs/core/rtw_mlme.c
index 22dc36e8e38a..1bc90fa48d36 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme.c
@@ -1875,13 +1875,13 @@ signed int rtw_set_auth(struct adapter *adapter, struct security_priv *psecurity
 	struct	cmd_priv *pcmdpriv = &adapter->cmdpriv;
 	signed int		res = _SUCCESS;
 
-	pcmd = kzalloc(sizeof(*pcmd), GFP_KERNEL);
+	pcmd = kzalloc_obj(*pcmd, GFP_KERNEL);
 	if (!pcmd) {
 		res = _FAIL;  /* try again */
 		goto exit;
 	}
 
-	psetauthparm = kzalloc(sizeof(*psetauthparm), GFP_KERNEL);
+	psetauthparm = kzalloc_obj(*psetauthparm, GFP_KERNEL);
 	if (!psetauthparm) {
 		kfree(pcmd);
 		res = _FAIL;
@@ -1912,7 +1912,7 @@ signed int rtw_set_key(struct adapter *adapter, struct security_priv *psecurityp
 	struct cmd_priv *pcmdpriv = &adapter->cmdpriv;
 	signed int	res = _SUCCESS;
 
-	psetkeyparm = kzalloc(sizeof(*psetkeyparm), GFP_KERNEL);
+	psetkeyparm = kzalloc_obj(*psetkeyparm, GFP_KERNEL);
 	if (!psetkeyparm) {
 		res = _FAIL;
 		goto exit;
@@ -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


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v3] staging: rtl8723bs: Replace kzalloc with kzalloc_obj
  2026-02-21 11:10     ` [PATCH v3] staging: rtl8723bs: Replace kzalloc with kzalloc_obj Mariyam Shahid
@ 2026-02-21 18:29       ` Ethan Tidmore
  2026-02-22 16:20       ` [PATCH v4] " Mariyam Shahid
  1 sibling, 0 replies; 11+ messages in thread
From: Ethan Tidmore @ 2026-02-21 18:29 UTC (permalink / raw)
  To: Mariyam Shahid, gregkh
  Cc: straube.linux, dan.carpenter, linux-staging, linux-kernel

On Sat Feb 21, 2026 at 5:10 AM CST, Mariyam Shahid wrote:
> Replace kzalloc() using sizeof(*ptr) with kzalloc_obj()
> to fix respective checkpatch warnings.
>
> Signed-off-by: Mariyam Shahid <mariyam.shahid135@gmail.com>
> ---
^^^
No changelog.

>  drivers/staging/rtl8723bs/core/rtw_mlme.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>

LGTM. Just include the changelog, in your v4 you can put:

Reviewed-by: Ethan Tidmore <ethantidmore06@gmail.com>

Thanks,

ET

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v4] staging: rtl8723bs: Replace kzalloc with kzalloc_obj
  2026-02-21 11:10     ` [PATCH v3] staging: rtl8723bs: Replace kzalloc with kzalloc_obj Mariyam Shahid
  2026-02-21 18:29       ` Ethan Tidmore
@ 2026-02-22 16:20       ` Mariyam Shahid
  2026-02-22 16:42         ` Greg KH
  2026-02-23  5:35         ` Dan Carpenter
  1 sibling, 2 replies; 11+ messages in thread
From: Mariyam Shahid @ 2026-02-22 16:20 UTC (permalink / raw)
  To: gregkh
  Cc: straube.linux, dan.carpenter, ethantidmore06, linux-staging,
	linux-kernel, Mariyam Shahid

Replace kzalloc() using sizeof(*ptr) with kzalloc_obj()
to fix respective checkpatch warnings.

Reviewed-by: Ethan Tidmore <ethantidmore06@gmail.com>
Signed-off-by: Mariyam Shahid <mariyam.shahid135@gmail.com>
---

v4: added changelog
v3: rebased on staging-next, kzalloc_obj now available in this tree
v2: switched to kzalloc_obj as suggested by Dan Carpenter
v1: initial submission

 drivers/staging/rtl8723bs/core/rtw_mlme.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme.c b/drivers/staging/rtl8723bs/core/rtw_mlme.c
index 22dc36e8e38a..1bc90fa48d36 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme.c
@@ -1875,13 +1875,13 @@ signed int rtw_set_auth(struct adapter *adapter, struct security_priv *psecurity
 	struct	cmd_priv *pcmdpriv = &adapter->cmdpriv;
 	signed int		res = _SUCCESS;
 
-	pcmd = kzalloc(sizeof(*pcmd), GFP_KERNEL);
+	pcmd = kzalloc_obj(*pcmd, GFP_KERNEL);
 	if (!pcmd) {
 		res = _FAIL;  /* try again */
 		goto exit;
 	}
 
-	psetauthparm = kzalloc(sizeof(*psetauthparm), GFP_KERNEL);
+	psetauthparm = kzalloc_obj(*psetauthparm, GFP_KERNEL);
 	if (!psetauthparm) {
 		kfree(pcmd);
 		res = _FAIL;
@@ -1912,7 +1912,7 @@ signed int rtw_set_key(struct adapter *adapter, struct security_priv *psecurityp
 	struct cmd_priv *pcmdpriv = &adapter->cmdpriv;
 	signed int	res = _SUCCESS;
 
-	psetkeyparm = kzalloc(sizeof(*psetkeyparm), GFP_KERNEL);
+	psetkeyparm = kzalloc_obj(*psetkeyparm, GFP_KERNEL);
 	if (!psetkeyparm) {
 		res = _FAIL;
 		goto exit;
@@ -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


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v4] staging: rtl8723bs: Replace kzalloc with kzalloc_obj
  2026-02-22 16:20       ` [PATCH v4] " Mariyam Shahid
@ 2026-02-22 16:42         ` Greg KH
  2026-02-23 16:37           ` Mariyam Shahid
  2026-02-23  5:35         ` Dan Carpenter
  1 sibling, 1 reply; 11+ messages in thread
From: Greg KH @ 2026-02-22 16:42 UTC (permalink / raw)
  To: Mariyam Shahid
  Cc: straube.linux, dan.carpenter, ethantidmore06, linux-staging,
	linux-kernel

On Sun, Feb 22, 2026 at 09:20:18PM +0500, Mariyam Shahid wrote:
> Replace kzalloc() using sizeof(*ptr) with kzalloc_obj()
> to fix respective checkpatch warnings.
> 
> Reviewed-by: Ethan Tidmore <ethantidmore06@gmail.com>
> Signed-off-by: Mariyam Shahid <mariyam.shahid135@gmail.com>
> ---
> 
> v4: added changelog
> v3: rebased on staging-next, kzalloc_obj now available in this tree
> v2: switched to kzalloc_obj as suggested by Dan Carpenter
> v1: initial submission

This is not how the _obj() calls are changing to work, please wait for
-rc1 to be out before doing stuff like this (see the changes that _just_
landed in Linus's tree for this.)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v4] staging: rtl8723bs: Replace kzalloc with kzalloc_obj
  2026-02-22 16:20       ` [PATCH v4] " Mariyam Shahid
  2026-02-22 16:42         ` Greg KH
@ 2026-02-23  5:35         ` Dan Carpenter
  1 sibling, 0 replies; 11+ messages in thread
From: Dan Carpenter @ 2026-02-23  5:35 UTC (permalink / raw)
  To: Mariyam Shahid
  Cc: gregkh, straube.linux, ethantidmore06, linux-staging,
	linux-kernel

On Sun, Feb 22, 2026 at 09:20:18PM +0500, Mariyam Shahid wrote:
> Replace kzalloc() using sizeof(*ptr) with kzalloc_obj()
> to fix respective checkpatch warnings.
> 
> Reviewed-by: Ethan Tidmore <ethantidmore06@gmail.com>
> Signed-off-by: Mariyam Shahid <mariyam.shahid135@gmail.com>
> ---
> 
> v4: added changelog
> v3: rebased on staging-next, kzalloc_obj now available in this tree
> v2: switched to kzalloc_obj as suggested by Dan Carpenter
> v1: initial submission


I don't remember suggesting anything...  But, sure, looks good.

Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v4] staging: rtl8723bs: Replace kzalloc with kzalloc_obj
  2026-02-22 16:42         ` Greg KH
@ 2026-02-23 16:37           ` Mariyam Shahid
  0 siblings, 0 replies; 11+ messages in thread
From: Mariyam Shahid @ 2026-02-23 16:37 UTC (permalink / raw)
  To: Greg KH
  Cc: straube.linux, dan.carpenter, ethantidmore06, linux-staging,
	linux-kernel

On Sun, Feb 22, 2026 at 9:42 PM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Sun, Feb 22, 2026 at 09:20:18PM +0500, Mariyam Shahid wrote:
> > Replace kzalloc() using sizeof(*ptr) with kzalloc_obj()
> > to fix respective checkpatch warnings.
> >
> > Reviewed-by: Ethan Tidmore <ethantidmore06@gmail.com>
> > Signed-off-by: Mariyam Shahid <mariyam.shahid135@gmail.com>
> > ---
> >
> > v4: added changelog
> > v3: rebased on staging-next, kzalloc_obj now available in this tree
> > v2: switched to kzalloc_obj as suggested by Dan Carpenter
> > v1: initial submission
>
> This is not how the _obj() calls are changing to work, please wait for
> -rc1 to be out before doing stuff like this (see the changes that _just_
> landed in Linus's tree for this.)
>
> thanks,
>
> greg k-h

Hi Greg,

Understood, I'll review the new changes in Linus's tree, and update
the patch accordingly before resubmitting.

Thanks for the heads up.

Regards,
Mariyam

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-02-23 16:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-16 16:17 [PATCH] staging: rtl8723bs: use kzalloc_obj() instead of kzalloc() Mariyam Shahid
2026-02-17  1:07 ` Ethan Tidmore
2026-02-17  9:12   ` Mariyam Shahid
2026-02-19  8:15 ` Dan Carpenter
2026-02-20  7:03   ` Mariyam Shahid
2026-02-21 11:10     ` [PATCH v3] staging: rtl8723bs: Replace kzalloc with kzalloc_obj Mariyam Shahid
2026-02-21 18:29       ` Ethan Tidmore
2026-02-22 16:20       ` [PATCH v4] " Mariyam Shahid
2026-02-22 16:42         ` Greg KH
2026-02-23 16:37           ` Mariyam Shahid
2026-02-23  5:35         ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox