* [PATCH 1/2] staging: rtl8723bs: replace N_BYTE_ALIGMENT() with PTR_ALIGN()
2026-08-14 0:25 [PATCH 0/2] staging: rtl8723bs: replace and remove N_BYTE_ALIGMENT() Leonardo Martins Martins
@ 2026-08-14 0:25 ` Leonardo Martins Martins
2026-08-14 0:25 ` [PATCH 2/2] staging: rtl8723bs: remove unused macro N_BYTE_ALIGMENT() Leonardo Martins Martins
1 sibling, 0 replies; 3+ messages in thread
From: Leonardo Martins Martins @ 2026-08-14 0:25 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-staging, linux-kernel, Leonardo Martins Martins
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.
Signed-off-by: Leonardo Martins Martins <dev.lmmrtns@gmail.com>
---
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(-)
diff --git a/drivers/staging/rtl8723bs/core/rtw_recv.c b/drivers/staging/rtl8723bs/core/rtw_recv.c
index 7568fc514d7ce97274c1695d6b445b39cad84b51..dc6e7ef9857d54005f517d277d20102bd5eab5d8 100644
--- a/drivers/staging/rtl8723bs/core/rtw_recv.c
+++ b/drivers/staging/rtl8723bs/core/rtw_recv.c
@@ -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)); */
diff --git a/drivers/staging/rtl8723bs/core/rtw_xmit.c b/drivers/staging/rtl8723bs/core/rtw_xmit.c
index 81d9e713fc12bd00b05a2ad3dd312f93220489df..7ceca76553a6c2b9b930cd99c3734d3221cfcfc4 100644
--- a/drivers/staging/rtl8723bs/core/rtw_xmit.c
+++ b/drivers/staging/rtl8723bs/core/rtw_xmit.c
@@ -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_buf
if (!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;
diff --git a/drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c b/drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c
index e943c304950e7c50cb680b7ff4c7db1894077905..706d58741dcede8921f49ff2fcf6747062b96015 100644
--- a/drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c
+++ b/drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c
@@ -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;
--
2.47.3
^ permalink raw reply related [flat|nested] 3+ messages in thread