[PATCH v3] staging: rtl8723bs: fix lines exceeding 100 columns in rtw_security.c

From: Rareș-Mihai Vladu

Date: Wed Sep 16 2026 - 04:02:16 EST


Reformat long lines in rtw_security.c to fit within the 100-column
limit by splitting function arguments, expressions, and moving

Signed-off-by: Rareș-Mihai Vladu <vladurares@xxxxxxxxx>
---
Changes in v3:
- moved variable declarations to the top of their blocks
- reverted formatting of dead code comment (will be removed
in a separate patch)

Changes in v2:
- renamed keyid to bip_keyid to avoid redefinition error
reported by kernel test robot

drivers/staging/rtl8723bs/core/rtw_security.c | 90 +++++++++++++------
1 file changed, 63 insertions(+), 27 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_security.c b/drivers/staging/rtl8723bs/core/rtw_security.c
index 2217cffac..569030054 100644
--- a/drivers/staging/rtl8723bs/core/rtw_security.c
+++ b/drivers/staging/rtl8723bs/core/rtw_security.c
@@ -34,7 +34,8 @@ const char *security_type_str(u8 value)

/* Need to consider the fragment situation */
void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
-{ /* exclude ICV */
+{
+ /* exclude ICV */
union {
__le32 f0;
unsigned char f1[4];
@@ -62,14 +63,19 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
keylength = psecuritypriv->dot11DefKeylen[psecuritypriv->dot11PrivacyKeyIndex];

for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) {
+ int idx = psecuritypriv->dot11PrivacyKeyIndex;
+
iv = pframe + pattrib->hdrlen;
memcpy(&wepkey[0], iv, 3);
- memcpy(&wepkey[3], &psecuritypriv->dot11DefKey[psecuritypriv->dot11PrivacyKeyIndex].skey[0], keylength);
+ memcpy(&wepkey[3],
+ &psecuritypriv->dot11DefKey[idx].skey[0],
+ keylength);
payload = pframe + pattrib->iv_len + pattrib->hdrlen;

if ((curfragnum + 1) == pattrib->nr_frags) { /* the last fragment */

- length = pattrib->last_txcmdsz - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len;
+ length = pattrib->last_txcmdsz - pattrib->hdrlen -
+ pattrib->iv_len - pattrib->icv_len;

crc.f0 = cpu_to_le32(~crc32_le(~0, payload, length));

@@ -78,7 +84,8 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
arc4_crypt(ctx, payload + length, crc.f1, 4);

} else {
- length = pxmitpriv->frag_len - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len;
+ length = pxmitpriv->frag_len - pattrib->hdrlen -
+ pattrib->iv_len - pattrib->icv_len;
crc.f0 = cpu_to_le32(~crc32_le(~0, payload, length));
arc4_setkey(ctx, wepkey, 3 + keylength);
arc4_crypt(ctx, payload, payload, length);
@@ -113,8 +120,11 @@ void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe)
keylength = psecuritypriv->dot11DefKeylen[keyindex];
memcpy(&wepkey[0], iv, 3);
/* memcpy(&wepkey[3], &psecuritypriv->dot11DefKey[psecuritypriv->dot11PrivacyKeyIndex].skey[0], keylength); */
- memcpy(&wepkey[3], &psecuritypriv->dot11DefKey[keyindex].skey[0], keylength);
- length = ((union recv_frame *)precvframe)->u.hdr.len - prxattrib->hdrlen - prxattrib->iv_len;
+ memcpy(&wepkey[3],
+ &psecuritypriv->dot11DefKey[keyindex].skey[0],
+ keylength);
+ length = ((union recv_frame *)precvframe)->u.hdr.len -
+ prxattrib->hdrlen - prxattrib->iv_len;

payload = pframe + prxattrib->iv_len + prxattrib->hdrlen;

@@ -157,7 +167,8 @@ void rtw_secmicappendbyte(struct mic_data *pmicdata, u8 b)
pmicdata->L ^= pmicdata->M;
pmicdata->R ^= ROL32(pmicdata->L, 17);
pmicdata->L += pmicdata->R;
- pmicdata->R ^= ((pmicdata->L & 0xff00ff00) >> 8) | ((pmicdata->L & 0x00ff00ff) << 8);
+ pmicdata->R ^= ((pmicdata->L & 0xff00ff00) >> 8) |
+ ((pmicdata->L & 0x00ff00ff) << 8);
pmicdata->L += pmicdata->R;
pmicdata->R ^= ROL32(pmicdata->L, 3);
pmicdata->L += pmicdata->R;
@@ -418,7 +429,8 @@ static void phase2(u8 *rc4key, const u8 *tk, const u16 *p1k, u16 iv16)

/* The hlen isn't include the IV */
u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)
-{ /* exclude ICV */
+{
+ /* exclude ICV */
u16 pnl;
u32 pnh;
u8 rc4key[16];
@@ -467,7 +479,8 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)
phase2(&rc4key[0], prwskey, (u16 *)&ttkey[0], pnl);

if ((curfragnum + 1) == pattrib->nr_frags) { /* 4 the last fragment */
- length = pattrib->last_txcmdsz - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len;
+ length = pattrib->last_txcmdsz - pattrib->hdrlen -
+ pattrib->iv_len - pattrib->icv_len;
crc.f0 = cpu_to_le32(~crc32_le(~0, payload, length));

arc4_setkey(ctx, rc4key, 16);
@@ -475,7 +488,8 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)
arc4_crypt(ctx, payload + length, crc.f1, 4);

} else {
- length = pxmitpriv->frag_len - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len;
+ length = pxmitpriv->frag_len - pattrib->hdrlen -
+ pattrib->iv_len - pattrib->icv_len;
crc.f0 = cpu_to_le32(~crc32_le(~0, payload, length));

arc4_setkey(ctx, rc4key, 16);
@@ -491,7 +505,8 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)

/* The hlen isn't include the IV */
u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
-{ /* exclude ICV */
+{
+ /* exclude ICV */
u16 pnl;
u32 pnh;
u8 rc4key[16];
@@ -536,7 +551,8 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
if (jiffies_to_msecs(jiffies - start) > 1000) {
if (no_gkey_bc_cnt || no_gkey_mc_cnt) {
netdev_dbg(padapter->pnetdev,
- FUNC_ADPT_FMT " no_gkey_bc_cnt:%u, no_gkey_mc_cnt:%u\n",
+ FUNC_ADPT_FMT
+ " no_gkey_bc_cnt:%u, no_gkey_mc_cnt:%u\n",
FUNC_ADPT_ARG(padapter),
no_gkey_bc_cnt,
no_gkey_mc_cnt);
@@ -550,7 +566,8 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)

if (no_gkey_bc_cnt || no_gkey_mc_cnt) {
netdev_dbg(padapter->pnetdev,
- FUNC_ADPT_FMT " gkey installed. no_gkey_bc_cnt:%u, no_gkey_mc_cnt:%u\n",
+ FUNC_ADPT_FMT
+ " gkey installed. no_gkey_bc_cnt:%u, no_gkey_mc_cnt:%u\n",
FUNC_ADPT_ARG(padapter),
no_gkey_bc_cnt,
no_gkey_mc_cnt);
@@ -566,7 +583,8 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)

iv = pframe + prxattrib->hdrlen;
payload = pframe + prxattrib->iv_len + prxattrib->hdrlen;
- length = ((union recv_frame *)precvframe)->u.hdr.len - prxattrib->hdrlen - prxattrib->iv_len;
+ length = ((union recv_frame *)precvframe)->u.hdr.len -
+ prxattrib->hdrlen - prxattrib->iv_len;

GET_TKIP_PN(iv, dot11txpn);

@@ -757,10 +775,12 @@ static void construct_ctr_preload(u8 *ctr_preload,
if (frtype == WIFI_MGT_TYPE)
ctr_preload[1] |= BIT(4);

+ /* ctr_preload[2:7] = A2[0:5] = mpdu[10:15] */
for (i = 2; i < 8; i++)
- ctr_preload[i] = mpdu[i + 8]; /* ctr_preload[2:7] = A2[0:5] = mpdu[10:15] */
+ ctr_preload[i] = mpdu[i + 8];
+ /* ctr_preload[8:13] = PN[5:0] */
for (i = 8; i < 14; i++)
- ctr_preload[i] = pn_vector[13 - i]; /* ctr_preload[8:13] = PN[5:0] */
+ ctr_preload[i] = pn_vector[13 - i];
ctr_preload[14] = (unsigned char)(c / 256); /* Ctr */
ctr_preload[15] = (unsigned char)(c % 256);
}
@@ -952,11 +972,13 @@ u32 rtw_aes_encrypt(struct adapter *padapter, u8 *pxmitframe)

for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) {
if ((curfragnum + 1) == pattrib->nr_frags) { /* 4 the last fragment */
- length = pattrib->last_txcmdsz - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len;
+ length = pattrib->last_txcmdsz - pattrib->hdrlen -
+ pattrib->iv_len - pattrib->icv_len;

aes_cipher(prwskey, pattrib->hdrlen, pframe, length);
} else {
- length = pxmitpriv->frag_len - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len;
+ length = pxmitpriv->frag_len - pattrib->hdrlen -
+ pattrib->iv_len - pattrib->icv_len;

aes_cipher(prwskey, pattrib->hdrlen, pframe, length);
pframe += pxmitpriv->frag_len;
@@ -1205,7 +1227,8 @@ u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe)
if (jiffies_to_msecs(jiffies - start) > 1000) {
if (no_gkey_bc_cnt || no_gkey_mc_cnt) {
netdev_dbg(padapter->pnetdev,
- FUNC_ADPT_FMT " no_gkey_bc_cnt:%u, no_gkey_mc_cnt:%u\n",
+ FUNC_ADPT_FMT
+ " no_gkey_bc_cnt:%u, no_gkey_mc_cnt:%u\n",
FUNC_ADPT_ARG(padapter),
no_gkey_bc_cnt,
no_gkey_mc_cnt);
@@ -1220,7 +1243,8 @@ u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe)

if (no_gkey_bc_cnt || no_gkey_mc_cnt) {
netdev_dbg(padapter->pnetdev,
- FUNC_ADPT_FMT " gkey installed. no_gkey_bc_cnt:%u, no_gkey_mc_cnt:%u\n",
+ FUNC_ADPT_FMT
+ " gkey installed. no_gkey_bc_cnt:%u, no_gkey_mc_cnt:%u\n",
FUNC_ADPT_ARG(padapter),
no_gkey_bc_cnt,
no_gkey_mc_cnt);
@@ -1238,7 +1262,8 @@ u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe)
prwskey = &stainfo->dot118021x_UncstKey.skey[0];
}

- length = ((union recv_frame *)precvframe)->u.hdr.len - prxattrib->hdrlen - prxattrib->iv_len;
+ length = ((union recv_frame *)precvframe)->u.hdr.len -
+ prxattrib->hdrlen - prxattrib->iv_len;

res = aes_decipher(prwskey, prxattrib->hdrlen, pframe, length);

@@ -1269,13 +1294,20 @@ u32 rtw_BIP_verify(struct adapter *padapter, u8 *precvframe)
/* mapping to wlan header */
pwlanhdr = (struct ieee80211_hdr *)pframe;
/* save the frame body + MME */
- memcpy(BIP_AAD + BIP_AAD_SIZE, pframe + WLAN_HDR_A3_LEN, pattrib->pkt_len - WLAN_HDR_A3_LEN);
+ memcpy(BIP_AAD + BIP_AAD_SIZE,
+ pframe + WLAN_HDR_A3_LEN,
+ pattrib->pkt_len - WLAN_HDR_A3_LEN);
/* find MME IE pointer */
- p = rtw_get_ie(BIP_AAD + BIP_AAD_SIZE, WLAN_EID_MMIE, &len, pattrib->pkt_len - WLAN_HDR_A3_LEN);
+ p = rtw_get_ie(BIP_AAD + BIP_AAD_SIZE,
+ WLAN_EID_MMIE,
+ &len,
+ pattrib->pkt_len - WLAN_HDR_A3_LEN);
/* Baron */
if (p) {
u16 keyid = 0;
u64 temp_ipn = 0;
+ int bip_keyid;
+ u8 *bip_key;
/* save packet number */
memcpy(&le_tmp64, p + 4, 6);
temp_ipn = le64_to_cpu(le_tmp64);
@@ -1300,8 +1332,10 @@ u32 rtw_BIP_verify(struct adapter *padapter, u8 *precvframe)
/* conscruct AAD, copy address 1 to address 3 */
memcpy(BIP_AAD + 2, &pwlanhdr->addrs, sizeof(pwlanhdr->addrs));

- if (omac1_aes_128(padapter->securitypriv.dot11wBIPKey[padapter->securitypriv.dot11wBIPKeyid].skey
- , BIP_AAD, ori_len, mic))
+ bip_keyid = padapter->securitypriv.dot11wBIPKeyid;
+ bip_key = padapter->securitypriv.dot11wBIPKey[bip_keyid].skey;
+
+ if (omac1_aes_128(bip_key, BIP_AAD, ori_len, mic))
goto BIP_exit;

/* MIC field should be last 8 bytes of packet (packet without FCS) */
@@ -1430,7 +1464,8 @@ void rtw_sec_restore_wep_key(struct adapter *adapter)
struct security_priv *securitypriv = &adapter->securitypriv;
signed int keyid;

- if ((securitypriv->dot11_privacy_algrthm == _WEP40_) || (securitypriv->dot11_privacy_algrthm == _WEP104_)) {
+ if ((securitypriv->dot11_privacy_algrthm == _WEP40_) ||
+ (securitypriv->dot11_privacy_algrthm == _WEP104_)) {
for (keyid = 0; keyid < 4; keyid++) {
if (securitypriv->key_mask & BIT(keyid)) {
if (keyid == securitypriv->dot11PrivacyKeyIndex)
@@ -1448,7 +1483,8 @@ u8 rtw_handle_tkip_countermeasure(struct adapter *adapter, const char *caller)
u8 status = _SUCCESS;

if (securitypriv->btkip_countermeasure) {
- unsigned long passing_ms = jiffies_to_msecs(jiffies - securitypriv->btkip_countermeasure_time);
+ unsigned long elapsed = jiffies - securitypriv->btkip_countermeasure_time;
+ unsigned long passing_ms = jiffies_to_msecs(elapsed);

if (passing_ms > 60 * 1000) {
netdev_dbg(adapter->pnetdev,
--
2.43.0