staging: rtl8723bs: replace and remove N_BYTE_ALIGMENT()
cover staging: rtl8723bs: replace and remove N_BYTE_ALIGMENT()
The macro N_BYTE_ALIGMENT() is used throughout the driver to perform byte alignment on pointers with manual castings to unsigned long and back to the pointer's type, making the code quite verbose.
This series replaces the macro N_BYTE_ALIGMENT() with the standard PTR_ALIGN() macro.
Note: I've noticed that several of these alignments are called right after kzalloc() or vzalloc() while aligning to 4, with kzalloc() guaranteeing at least 8-byte alignment, this alignment is redundant. I've left it as is since I don't have the hardware to test on and I couldn't find out whether vzalloc() also guarantees byte alignment. Please let me know if this change is desired.
---
Leonardo Martins Martins (2):
staging: rtl8723bs: replace N_BYTE_ALIGMENT() with PTR_ALIGN()
staging: rtl8723bs: remove unused macro N_BYTE_ALIGMENT()
drivers/staging/rtl8723bs/core/rtw_recv.c | 3 ++- drivers/staging/rtl8723bs/core/rtw_xmit.c | 13 +++++++------ drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c | 3 ++- drivers/staging/rtl8723bs/include/basic_types.h | 3 --- 4 files changed, 11 insertions(+), 11 deletions(-)
---
base-commit: c6eb4dc5964fdf4086b73b7f0f5dc0d595fb5cf3
change-id: 20260813-staging-testing-b664ef41cd30
Best regards,
Signature · 1 line
Leonardo Martins Martins <[email protected]>
PATCH 1/2 staging: rtl8723bs: replace N_BYTE_ALIGMENT() with PTR_ALIGN()
The macro N_BYTE_ALIGMENT() uses integer division and multiplication to perform byte alignment, with a result equivalent to the standard kernel macro ALIGN() which uses bitwise operations instead. The usages of this macro involve casting the pointer to SIZE_PTR and casting the returned value back, which is the same pattern that PTR_ALIGN() uses, by replacing it with PTR_ALIGN() the manual castings to SIZE_PTR and (u8 *) can be dropped, improving readability.
Compile tested only.
--- drivers/staging/rtl8723bs/core/rtw_recv.c | 3 ++- drivers/staging/rtl8723bs/core/rtw_xmit.c | 13 +++++++------ drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c | 3 ++- 3 files changed, 11 insertions(+), 8 deletions(-)
drivers/staging/rtl8723bs/core/rtw_recv.c +2 -1
@@ -9,6 +9,7 @@#include <rtw_recv.h> #include <net/cfg80211.h> #include <linux/unaligned.h> +#include <linux/align.h> static u8 SNAP_ETH_TYPE_IPX [2 ] = {0x81 ,0x37 };static u8 SNAP_ETH_TYPE_APPLETALK_AARP [2 ] = {0x80 ,0xf3 };
@@ -52,7 +53,7 @@ signed int _rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *pada goto exit; } - precvpriv->precv_frame_buf = (u8 *)N_BYTE_ALIGMENT ((SIZE_PTR )(precvpriv->pallocated_frame_buf),RXFRAME_ALIGN_SZ ); + precvpriv->precv_frame_buf =PTR_ALIGN (precvpriv->pallocated_frame_buf,RXFRAME_ALIGN_SZ );/* precvpriv->precv_frame_buf = precvpriv->pallocated_frame_buf + RXFRAME_ALIGN_SZ - */ /* ((SIZE_PTR) (precvpriv->pallocated_frame_buf) &(RXFRAME_ALIGN_SZ-1)); */
drivers/staging/rtl8723bs/core/rtw_xmit.c +7 -6
@@ -7,6 +7,7 @@#include <drv_types.h> #include <linux/delay.h> #include <linux/if_ether.h> +#include <linux/align.h> static u8 P802_1H_OUI [P80211_OUI_LEN ] = {0x00 ,0x00 ,0xf8 };static u8 RFC1042_OUI [P80211_OUI_LEN ] = {0x00 ,0x00 ,0x00 };
@@ -80,7 +81,7 @@ static int rtw_os_xmit_resource_alloc(struct adapter *padapter, struct xmit_bufif (!pxmitbuf->pallocated_buf)return -ENOMEM ; - pxmitbuf->pbuf = (u8 *)N_BYTE_ALIGMENT ((SIZE_PTR )(pxmitbuf->pallocated_buf),XMITBUF_ALIGN_SZ ); + pxmitbuf->pbuf =PTR_ALIGN (pxmitbuf->pallocated_buf,XMITBUF_ALIGN_SZ ); }return 0 ;
@@ -126,7 +127,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter) pxmitpriv->pxmit_frame_buf =NULL ;return -ENOMEM ; } - pxmitpriv->pxmit_frame_buf = (u8 *)N_BYTE_ALIGMENT ((SIZE_PTR )(pxmitpriv->pallocated_frame_buf),4 ); + pxmitpriv->pxmit_frame_buf =PTR_ALIGN (pxmitpriv->pallocated_frame_buf,4 ); pxframe = (struct xmit_frame *)pxmitpriv->pxmit_frame_buf;
@@ -162,7 +163,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)if (!pxmitpriv->pallocated_xmitbuf)return -ENOMEM ; - pxmitpriv->pxmitbuf = (u8 *)N_BYTE_ALIGMENT ((SIZE_PTR )(pxmitpriv->pallocated_xmitbuf),4 ); + pxmitpriv->pxmitbuf =PTR_ALIGN (pxmitpriv->pallocated_xmitbuf,4 ); pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
@@ -207,7 +208,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter) pxmitpriv->xframe_ext =NULL ;return -ENOMEM ; } - pxmitpriv->xframe_ext = (u8 *)N_BYTE_ALIGMENT ((SIZE_PTR )(pxmitpriv->xframe_ext_alloc_addr),4 ); + pxmitpriv->xframe_ext =PTR_ALIGN (pxmitpriv->xframe_ext_alloc_addr,4 ); pxframe = (struct xmit_frame *)pxmitpriv->xframe_ext;for (i =0 ; i <NR_XMIT_EXTBUFF ; i++) {
@@ -239,7 +240,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)if (!pxmitpriv->pallocated_xmit_extbuf)return -ENOMEM ; - pxmitpriv->pxmit_extbuf = (u8 *)N_BYTE_ALIGMENT ((SIZE_PTR )(pxmitpriv->pallocated_xmit_extbuf),4 ); + pxmitpriv->pxmit_extbuf =PTR_ALIGN (pxmitpriv->pallocated_xmit_extbuf,4 ); pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
@@ -1717,7 +1718,7 @@ struct xmit_frame *rtw_alloc_xmitframe_once(struct xmit_priv *pxmitpriv)if (!alloc_addr) goto exit; - pxframe = (struct xmit_frame *)N_BYTE_ALIGMENT ((SIZE_PTR )(alloc_addr),4 ); + pxframe = (struct xmit_frame *)PTR_ALIGN (alloc_addr,4 ); pxframe->alloc_addr = alloc_addr; pxframe->padapter = pxmitpriv->adapter;
drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c +2 -1
@@ -7,6 +7,7 @@#include <drv_types.h> #include <rtl8723b_hal.h> +#include <linux/align.h> static void initrecvbuf (struct recv_buf *precvbuf,struct adapter *padapter) {
@@ -386,7 +387,7 @@ s32 rtl8723bs_init_recv_priv(struct adapter *padapter) goto exit; } - precvpriv->precv_buf = (u8 *)N_BYTE_ALIGMENT ((SIZE_PTR )(precvpriv->pallocated_recv_buf),4 ); + precvpriv->precv_buf =PTR_ALIGN (precvpriv->pallocated_recv_buf,4 );/* init each recv buffer */ precvbuf = (struct recv_buf *)precvpriv->precv_buf;
Signature · 1 line
2.47.3
PATCH 2/2 staging: rtl8723bs: remove unused macro N_BYTE_ALIGMENT()
In reply to Leonardo Martins MartinsThe macro N_BYTE_ALIGMENT() no longer has any usages and can be removed.
--- drivers/staging/rtl8723bs/include/basic_types.h | 3 --- 1 file changed, 3 deletions(-)
drivers/staging/rtl8723bs/include/basic_types.h +0 -3
@@ -163,9 +163,6 @@ ); \ } -/* Get the N-bytes alignent offset from the current length */ -#define N_BYTE_ALIGMENT (__Value, __Aligment) ((__Aligment == 1) ? (__Value) : (((__Value + __Aligment - 1) / __Aligment) * __Aligment)) -#define TEST_FLAG (__Flag, __testFlag) (((__Flag) & (__testFlag)) != 0)#define SET_FLAG (__Flag, __setFlag) ((__Flag) |= __setFlag)#define CLEAR_FLAG (__Flag, __clearFlag) ((__Flag) &= ~(__clearFlag))
Signature · 1 line
2.47.3