staging: rtl8723bs: clean up SIZE_PTR usage and remove custom macro
cover staging: rtl8723bs: clean up SIZE_PTR usage and remove custom macro
This patch series cleans up the custom macro SIZE_PTR (__kernel_size_t) across the rtl8723bs driver as part of addressing the TODO item to "convert any remaining unusual variable types".
Instead of a mechanical substitution, each occurrence has been converted to its idiomatic kernel equivalent:
1. Replace open-coded pointer alignments with the standard PTR_ALIGN() macro, removing an unused variable left behind.
2. Remove redundant pointer-to-integer casts where pointer arithmetic or pointer arguments are already sufficient.
3. Replace the remaining pointer-to-integer address casts with uintptr_t, use size_t for alignment offsets, and delete the custom SIZE_PTR macro definition entirely.
Ashmit Kumar (3):
staging: rtl8723bs: use PTR_ALIGN() for pointer alignment
staging: rtl8723bs: remove unnecessary pointer-to-integer casts
staging: rtl8723bs: replace SIZE_PTR with uintptr_t and remove
definition
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 8 ++++---- drivers/staging/rtl8723bs/core/rtw_security.c | 6 +++--- drivers/staging/rtl8723bs/core/rtw_sta_mgt.c | 3 +-- drivers/staging/rtl8723bs/core/rtw_xmit.c | 8 ++------ drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c | 11 ++++++----- drivers/staging/rtl8723bs/hal/sdio_ops.c | 6 +++--- drivers/staging/rtl8723bs/include/basic_types.h | 2 -- drivers/staging/rtl8723bs/os_dep/xmit_linux.c | 2 +- 8 files changed, 20 insertions(+), 26 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/3 staging: rtl8723bs: use PTR_ALIGN() for pointer alignment
The driver open-codes pointer alignment using round_up() with the custom SIZE_PTR macro, or performs manual arithmetic on pointer addresses.
Replace these open-coded pointer alignments with the standard PTR_ALIGN() macro, and remove the now unused temporary variable addr in rtw_xmitframe_coalesce().
--- drivers/staging/rtl8723bs/core/rtw_security.c | 6 +++--- drivers/staging/rtl8723bs/core/rtw_sta_mgt.c | 3 +-- drivers/staging/rtl8723bs/core/rtw_xmit.c | 8 ++------ 3 files changed, 6 insertions(+), 11 deletions(-)
drivers/staging/rtl8723bs/core/rtw_security.c +3 -3
@@ -92,7 +92,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)arc4_crypt (ctx, payload + length, crc.f1,4 ); pframe += pxmitpriv->frag_len; - pframe = (u8 *)round_up ((SIZE_PTR )(pframe),4 ); + pframe =PTR_ALIGN (pframe,4 ); } } }
@@ -492,7 +492,7 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)arc4_crypt (ctx, payload + length, crc.f1,4 ); pframe += pxmitpriv->frag_len; - pframe = (u8 *)round_up ((SIZE_PTR )(pframe),4 ); + pframe =PTR_ALIGN (pframe,4 ); } }return res;
@@ -977,7 +977,7 @@ u32 rtw_aes_encrypt(struct adapter *padapter, u8 *pxmitframe)aes_cipher (prwskey, pattrib->hdrlen, pframe, length); pframe += pxmitpriv->frag_len; - pframe = (u8 *)round_up ((SIZE_PTR )(pframe),4 ); + pframe =PTR_ALIGN (pframe,4 ); } }return res;
drivers/staging/rtl8723bs/core/rtw_sta_mgt.c +1 -2
@@ -56,8 +56,7 @@ u32 _rtw_init_sta_priv(struct sta_priv *pstapriv)if (!pstapriv->pallocated_stainfo_buf)return _FAIL; - pstapriv->pstainfo_buf = pstapriv->pallocated_stainfo_buf +4 - - ((SIZE_PTR )(pstapriv->pallocated_stainfo_buf) &3 ); + pstapriv->pstainfo_buf =PTR_ALIGN (pstapriv->pallocated_stainfo_buf,4 );INIT_LIST_HEAD (&pstapriv->free_sta_queue.queue);spin_lock_init (&pstapriv->free_sta_queue.lock);
drivers/staging/rtl8723bs/core/rtw_xmit.c +2 -6
@@ -853,7 +853,7 @@ static int xmitframe_addmic(struct adapter *padapter, struct xmit_frame *pxmitfr payload = pframe;for (curfragnum =0 ; curfragnum < pattrib->nr_frags; curfragnum++) { - payload = (u8 *)round_up ((SIZE_PTR )(payload),4 ); + payload =PTR_ALIGN (payload,4 ); payload = payload + pattrib->hdrlen + pattrib->iv_len;if ((curfragnum +1 ) == pattrib->nr_frags) {
@@ -1066,8 +1066,6 @@ int rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, structs32 frg_inx, frg_len, mpdu_len, llc_sz, mem_sz; -SIZE_PTR addr; -u8 *pframe, *mem_start;u8 hw_hdr_offset;
@@ -1162,9 +1160,7 @@ int rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, structbreak ; } - addr = (SIZE_PTR )(pframe); - - mem_start = (unsigned char *)round_up (addr,4 ) + hw_hdr_offset; + mem_start =PTR_ALIGN (pframe,4 ) + hw_hdr_offset;memcpy (mem_start, pbuf_start + hw_hdr_offset, pattrib->hdrlen); }
Signature · 1 line
2.43.0
PATCH 2/3 staging: rtl8723bs: remove unnecessary pointer-to-integer casts
In reply to Ashmit KumarThe pointer pframe in rtw_mlme_ext.c is cast to (SIZE_PTR) before being passed as an argument or evaluated in expressions where it is already a pointer type. In xmit_linux.c, the buffer length was calculated using unnecessary casts:
(SIZE_PTR)pfile->cur_addr - (SIZE_PTR)pfile->buf_start where standard pointer subtraction pfile->cur_addr - pfile->buf_start yields ptrdiff_t directly without any casting.
Remove these redundant casts to simplify the code and use standard C pointer arithmetic.
--- drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 8 ++++---- drivers/staging/rtl8723bs/os_dep/xmit_linux.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +4 -4
@@ -707,8 +707,8 @@ unsigned int OnAuth(struct adapter *padapter, union recv_frame *precv_frame) offset =4 ; } - algorithm =le16_to_cpu (*(__le16 *)((SIZE_PTR )pframe +WLAN_HDR_A3_LEN + offset)); - seq =le16_to_cpu (*(__le16 *)((SIZE_PTR )pframe +WLAN_HDR_A3_LEN + offset +2 )); + algorithm =le16_to_cpu (*(__le16 *)(pframe +WLAN_HDR_A3_LEN + offset)); + seq =le16_to_cpu (*(__le16 *)(pframe +WLAN_HDR_A3_LEN + offset +2 )); if (auth_mode == 2 && psecuritypriv->dot11_privacy_algrthm != _WEP40_ &&
@@ -856,8 +856,8 @@ unsigned int OnAuthClient(struct adapter *padapter, union recv_frame *precv_fram offset = (GetPrivacy (pframe)) ?4 :0 ; - seq =le16_to_cpu (*(__le16 *)((SIZE_PTR )pframe +WLAN_HDR_A3_LEN + offset +2 )); - status =le16_to_cpu (*(__le16 *)((SIZE_PTR )pframe +WLAN_HDR_A3_LEN + offset +4 )); + seq =le16_to_cpu (*(__le16 *)(pframe +WLAN_HDR_A3_LEN + offset +2 )); + status =le16_to_cpu (*(__le16 *)(pframe +WLAN_HDR_A3_LEN + offset +4 ));if (status !=0 ) {if (status ==13 ) {/* pmlmeinfo->auth_algo == dot11_auth_algrthm_auto) */
drivers/staging/rtl8723bs/os_dep/xmit_linux.c +1 -1
@@ -9,7 +9,7 @@unsigned int rtw_remainder_len (struct pkt_file *pfile) { -return (pfile->buf_len - ((SIZE_PTR )(pfile->cur_addr) - (SIZE_PTR )(pfile->buf_start))); +return pfile->buf_len - (pfile->cur_addr - pfile->buf_start); }void _rtw_open_pktfile (struct sk_buff *pktptr,struct pkt_file *pfile)
Signature · 1 line
2.43.0
PATCH 3/3 staging: rtl8723bs: replace SIZE_PTR with uintptr_t and remove definition
In reply to Ashmit KumarThe driver defines a custom macro SIZE_PTR as __kernel_size_t, which is used when casting pointer values to integers to calculate alignment offsets.
Replace the remaining casts of pointers to integers in rtl8723bs_recv.c and sdio_ops.c with uintptr_t, use size_t for the alignment variable, and remove the SIZE_PTR macro definition from basic_types.h.
--- drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c | 11 ++++++----- drivers/staging/rtl8723bs/hal/sdio_ops.c | 6 +++--- drivers/staging/rtl8723bs/include/basic_types.h | 2 -- 3 files changed, 9 insertions(+), 10 deletions(-)
drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c +6 -5
@@ -295,7 +295,8 @@ static void rtl8723bs_recv_tasklet(struct tasklet_struct *t) pkt_copy->dev = padapter->pnetdev; precvframe->u.hdr.pkt = pkt_copy; -skb_reserve (pkt_copy,8 - ((SIZE_PTR )(pkt_copy->data) &7 ));/* force pkt_copy->data at 8-byte alignment address */ +/* force pkt_copy->data at 8-byte alignment address */ +skb_reserve (pkt_copy,8 - ((uintptr_t )(pkt_copy->data) &7 ));skb_reserve (pkt_copy, shift_sz);/* force ip_hdr at 8-byte alignment address according to shift_sz. */ memcpy (pkt_copy->data, (ptr + rx_report_sz + pattrib->shift_sz), skb_len); precvframe->u.hdr.rx_head = pkt_copy->head;
@@ -390,15 +391,15 @@ s32 rtl8723bs_init_recv_priv(struct adapter *padapter)initrecvbuf (precvbuf, padapter);if (!precvbuf->pskb) { -SIZE_PTR tmpaddr =0 ; -SIZE_PTR alignment =0 ; +uintptr_t tmpaddr =0 ; +size_t alignment =0 ; precvbuf->pskb =__dev_alloc_skb (MAX_RECVBUF_SZ +RECVBUFF_ALIGN_SZ ,GFP_ATOMIC );if (precvbuf->pskb) { precvbuf->pskb->dev = padapter->pnetdev; - tmpaddr = (SIZE_PTR )precvbuf->pskb->data; - alignment = tmpaddr & (RECVBUFF_ALIGN_SZ -1 ); + tmpaddr = (uintptr_t )precvbuf->pskb->data; + alignment = tmpaddr & (RECVBUFF_ALIGN_SZ -1 );skb_reserve (precvbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment)); } }
drivers/staging/rtl8723bs/hal/sdio_ops.c +3 -3
@@ -653,8 +653,8 @@ static struct recv_buf *sd_recv_rxfifo(struct adapter *adapter, u32 size)/* 3 2. alloc skb */ if (!recvbuf->pskb) { -SIZE_PTR tmpaddr =0 ; -SIZE_PTR alignment =0 ; +uintptr_t tmpaddr =0 ; +size_t alignment =0 ; recvbuf->pskb =__dev_alloc_skb (MAX_RECVBUF_SZ +RECVBUFF_ALIGN_SZ ,GFP_ATOMIC );if (!recvbuf->pskb)
@@ -662,7 +662,7 @@ static struct recv_buf *sd_recv_rxfifo(struct adapter *adapter, u32 size) recvbuf->pskb->dev = adapter->pnetdev; - tmpaddr = (SIZE_PTR )recvbuf->pskb->data; + tmpaddr = (uintptr_t )recvbuf->pskb->data; alignment = tmpaddr & (RECVBUFF_ALIGN_SZ -1 );skb_reserve (recvbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment)); }
drivers/staging/rtl8723bs/include/basic_types.h +0 -2
@@ -13,8 +13,6 @@#include <linux/types.h> #include <linux/stddef.h> -#define SIZE_PTR __kernel_size_t -/* port from fw by thomas */ /* TODO: Belows are Sync from SD7-Driver. It is necessary to check correctness */
Signature · 1 line
2.43.0
Quoted 14 lines · Ashmit Kumar
This patch series cleans up the custom macro
SIZE_PTR(__kernel_size_t) across the rtl8723bs driver as part of addressing the TODO item to "convert any remaining unusual variable types".Instead of a mechanical substitution, each occurrence has been converted to its idiomatic kernel equivalent:
1. Replace open-coded pointer alignments with the standardPTR_ALIGN()macro, removing an unused variable left behind.
2. Remove redundant pointer-to-integer casts where pointer arithmetic or pointer arguments are already sufficient.
3. Replace the remaining pointer-to-integer address casts withuintptr_t, usesize_tfor alignment offsets, and delete the customSIZE_PTRmacro definition entirely.
Quoted 5 lines
Ashmit Kumar (3):
staging: rtl8723bs: usePTR_ALIGN()for pointer alignment
staging: rtl8723bs: remove unnecessary pointer-to-integer casts
staging: rtl8723bs: replaceSIZE_PTRwithuintptr_tand remove
definition
This driver has been deleted in linux-next.
regards,
dan carpenter