staging: rtl8723bs: use PTR_ALIGN() for rsp_buf
PATCH v3 1/1 staging: rtl8723bs: use PTR_ALIGN() for rsp_buf
The original code was using manual bitwise calculation for the alignment of rsp_buf.
Replace this with the standard PTR_ALIGN() macro. The manual math ((SIZE_PTR)ptr & 3) always returns 0 and is completely unnecessary because kzalloc() already returns 8-byte aligned memory.
---
Changes in v3:
- Replaced manual bitwise math with PTR_ALIGN() macro based on feedback by Dan.
- 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +1 -1
@@ -184,7 +184,7 @@ int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)return -ENOMEM ; } - pcmdpriv->rsp_buf = pcmdpriv->rsp_allocated_buf +4 - ((SIZE_PTR )(pcmdpriv->rsp_allocated_buf) &3 ); + pcmdpriv->rsp_buf =PTR_ALIGN (pcmdpriv->rsp_allocated_buf,4 ); pcmdpriv->cmd_issued_cnt =0 ; pcmdpriv->cmd_done_cnt =0 ;
Signature · 1 line
2.54.0
drivers/staging/rtl8723bs/core/rtw_cmd.c int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv) · line 187
Quoted 10 lines · Devansh Soni
drivers/staging/rtl8723bs/core/rtw_cmd.c +1
-1@@ -184,7 +184,7 @@ int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)return -ENOMEM ; } - pcmdpriv->rsp_buf = pcmdpriv->rsp_allocated_buf +4 - ((SIZE_PTR )(pcmdpriv->rsp_allocated_buf) &3 ); + pcmdpriv->rsp_buf =PTR_ALIGN (pcmdpriv->rsp_allocated_buf,4 );
You're working against an old version of the kernel. You should be working against linux-next or devel-next.
The commit message mentions 8-byte aligned memory, but the code is still doing PTR_ALIGN(). The kmalloc() alignment is determined by ARCH_KMALLOC_MINALIGN and it's always at least 8 but it can be higher. Here the code is trying to ensure that it is 4 byte aligned, and 8 is already a multiple of 4. You could just delete the PTR_ALIGN() along with the related code.
1. It allocates 4 extra bytes. "MAX_RSPSZ + 4" bytes. It could instead just allocate MAX_RSPSZ bytes.
2. This pcmdpriv->rsp_buf = PTR_ALIGN() can be removed.
3. The pcmdpriv->rsp_allocated_buf pointer only exists to store the unaligned pointer. Just get rid of it.
The early part of function which does CMDBUFF_ALIGN_SZ is more complicated because that is 512 bytes. It's trying to ensure that the pointers are aligned enough for DMA. The proper alignment in that case is probably ARCH_DMA_MINALIGN but I'm less familiar with how that works.
regards,
dan carpenter