* [PATCH v4] staging: rtl8723bs: remove redundant rsp_allocated_buf
@ 2026-06-17 12:38 Devansh Soni
2026-06-17 13:21 ` Dan Carpenter
0 siblings, 1 reply; 2+ messages in thread
From: Devansh Soni @ 2026-06-17 12:38 UTC (permalink / raw)
To: gregkh; +Cc: linux-staging, linux-kernel, Devansh Soni, Dan Carpenter
The original code allocated extra memory and manually aligned the
rsp_buf pointer to a 4-byte boundary, however kzalloc() guarantees a
minimum of 8-byte alignment so this was unnecessary.
Also, because the pointer was shifted, the original pointer had to be
stored in rsp_allocated_buf just so it could be passed to kfree() later.
Remove the redundant alignment math, remove the extra 4 bytes of padding
from kzalloc() call, and assign memory directly to rsp_buf.
This allows us to remove the rsp_allocated_buf variable from cmd_priv
struct.
Suggested-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: Devansh Soni <devanshsoni874@gmail.com>
---
Changes in v4:
- Dropped PTR_ALIGN() entirely as kzalloc() 8-byte alignment is sufficient.
- Removed the +4 byte padding from kzalloc().
- Completely removed the rsp_allocated_buf tracking variable and updated kfree().
Changes in v3:
- Replaced manual bitwise math with PTR_ALIGN() macro based on feedback from v1.
- Updated commit message to detail kzalloc() 8-byte alignment guarantees.
Changes in v2:
- Wrapped commit log text to resolve line length issue noted by Greg.
drivers/staging/rtl8723bs/core/rtw_cmd.c | 9 +++------
drivers/staging/rtl8723bs/include/rtw_cmd.h | 1 -
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/staging/rtl8723bs/core/rtw_cmd.c b/drivers/staging/rtl8723bs/core/rtw_cmd.c
index b932670f5..fd1ba1b4e 100644
--- a/drivers/staging/rtl8723bs/core/rtw_cmd.c
+++ b/drivers/staging/rtl8723bs/core/rtw_cmd.c
@@ -178,15 +178,12 @@ int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
pcmdpriv->cmd_buf = PTR_ALIGN(pcmdpriv->cmd_allocated_buf, CMDBUFF_ALIGN_SZ);
- pcmdpriv->rsp_allocated_buf = kzalloc(MAX_RSPSZ + 4, GFP_ATOMIC);
- if (!pcmdpriv->rsp_allocated_buf) {
+ pcmdpriv->rsp_buf = kzalloc(MAX_RSPSZ, GFP_ATOMIC);
+ if (!pcmdpriv->rsp_buf) {
kfree(pcmdpriv->cmd_allocated_buf);
return -ENOMEM;
}
- pcmdpriv->rsp_buf = pcmdpriv->rsp_allocated_buf + 4 -
- ((SIZE_PTR)(pcmdpriv->rsp_allocated_buf) & 3);
-
pcmdpriv->cmd_issued_cnt = 0;
pcmdpriv->cmd_done_cnt = 0;
pcmdpriv->rsp_cnt = 0;
@@ -232,7 +229,7 @@ void _rtw_free_cmd_priv(struct cmd_priv *pcmdpriv)
if (pcmdpriv) {
kfree(pcmdpriv->cmd_allocated_buf);
- kfree(pcmdpriv->rsp_allocated_buf);
+ kfree(pcmdpriv->rsp_buf);
mutex_destroy(&pcmdpriv->sctx_mutex);
}
diff --git a/drivers/staging/rtl8723bs/include/rtw_cmd.h b/drivers/staging/rtl8723bs/include/rtw_cmd.h
index f78aa0d7a..66b970955 100644
--- a/drivers/staging/rtl8723bs/include/rtw_cmd.h
+++ b/drivers/staging/rtl8723bs/include/rtw_cmd.h
@@ -45,7 +45,6 @@
u8 *cmd_buf; /* shall be non-paged, and 4 bytes aligned */
u8 *cmd_allocated_buf;
u8 *rsp_buf; /* shall be non-paged, and 4 bytes aligned */
- u8 *rsp_allocated_buf;
u32 cmd_issued_cnt;
u32 cmd_done_cnt;
u32 rsp_cnt;
--
2.54.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v4] staging: rtl8723bs: remove redundant rsp_allocated_buf
2026-06-17 12:38 [PATCH v4] staging: rtl8723bs: remove redundant rsp_allocated_buf Devansh Soni
@ 2026-06-17 13:21 ` Dan Carpenter
0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2026-06-17 13:21 UTC (permalink / raw)
To: Devansh Soni; +Cc: gregkh, linux-staging, linux-kernel
On Wed, Jun 17, 2026 at 06:08:53PM +0530, Devansh Soni wrote:
> The original code allocated extra memory and manually aligned the
> rsp_buf pointer to a 4-byte boundary, however kzalloc() guarantees a
> minimum of 8-byte alignment so this was unnecessary.
>
> Also, because the pointer was shifted, the original pointer had to be
> stored in rsp_allocated_buf just so it could be passed to kfree() later.
>
> Remove the redundant alignment math, remove the extra 4 bytes of padding
> from kzalloc() call, and assign memory directly to rsp_buf.
>
> This allows us to remove the rsp_allocated_buf variable from cmd_priv
> struct.
>
> Suggested-by: Dan Carpenter <error27@gmail.com>
> Signed-off-by: Devansh Soni <devanshsoni874@gmail.com>
> ---
> Changes in v4:
> - Dropped PTR_ALIGN() entirely as kzalloc() 8-byte alignment is sufficient.
> - Removed the +4 byte padding from kzalloc().
> - Completely removed the rsp_allocated_buf tracking variable and updated kfree().
Thanks!
Reviewed-by: Dan Carpenter <error27@gmail.com>
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-17 14:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-17 12:38 [PATCH v4] staging: rtl8723bs: remove redundant rsp_allocated_buf Devansh Soni
2026-06-17 13:21 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox