From: Lin YuChen <starpt.official@gmail.com>
To: gregkh@linuxfoundation.org, dan.carpenter@linaro.org
Cc: straube.linux@gmail.com, starpt.official@gmail.com,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH v3 2/2] staging: rtl8723bs: use guard clause for stainfo check
Date: Thu, 19 Mar 2026 20:07:37 +0800 [thread overview]
Message-ID: <20260319120737.29692-3-starpt.official@gmail.com> (raw)
In-Reply-To: <20260319120737.29692-1-starpt.official@gmail.com>
Continue the refactor of rtw_aes_decrypt() by introducing a guard
clause for the stainfo check. This allows the subsequent multicast
and unicast decryption logic to be moved one indentation level to
the left, further improving code readability.
Signed-off-by: Lin YuChen <starpt.official@gmail.com>
---
v3: Use "return _FAIL" instead of "res = _FAIL; goto exit" for the stainfo
guard clause.
v3: Revert unrelated formatting and line-breaking changes (e.g., in
netdev_dbg calls) to keep the diff focused only on indentation
changes, as suggested by Dan Carpenter.
v2: Split the refactoring into a separate patch to make it easier to
verify logic changes.
drivers/staging/rtl8723bs/core/rtw_security.c | 96 +++++++++----------
1 file changed, 47 insertions(+), 49 deletions(-)
diff --git a/drivers/staging/rtl8723bs/core/rtw_security.c b/drivers/staging/rtl8723bs/core/rtw_security.c
index 3c89e911ac2d..cf910c268bb3 100644
--- a/drivers/staging/rtl8723bs/core/rtw_security.c
+++ b/drivers/staging/rtl8723bs/core/rtw_security.c
@@ -1216,66 +1216,64 @@ u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe)
if (prxattrib->encrypt != _AES_)
return _SUCCESS;
stainfo = rtw_get_stainfo(&padapter->stapriv, &prxattrib->ta[0]);
- if (stainfo) {
- if (is_multicast_ether_addr(prxattrib->ra)) {
- static unsigned long start;
- static u32 no_gkey_bc_cnt;
- static u32 no_gkey_mc_cnt;
-
- if (!psecuritypriv->binstallGrpkey) {
- res = _FAIL;
+ if (stainfo)
+ return _FAIL;
+ if (is_multicast_ether_addr(prxattrib->ra)) {
+ static unsigned long start;
+ static u32 no_gkey_bc_cnt;
+ static u32 no_gkey_mc_cnt;
- if (start == 0)
- start = jiffies;
+ if (!psecuritypriv->binstallGrpkey) {
+ res = _FAIL;
- if (is_broadcast_mac_addr(prxattrib->ra))
- no_gkey_bc_cnt++;
- else
- no_gkey_mc_cnt++;
-
- 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_ARG(padapter),
- no_gkey_bc_cnt,
- no_gkey_mc_cnt);
- }
- start = jiffies;
- no_gkey_bc_cnt = 0;
- no_gkey_mc_cnt = 0;
- }
+ if (start == 0)
+ start = jiffies;
- goto exit;
- }
+ if (is_broadcast_mac_addr(prxattrib->ra))
+ no_gkey_bc_cnt++;
+ else
+ no_gkey_mc_cnt++;
- 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_ARG(padapter),
- no_gkey_bc_cnt,
- no_gkey_mc_cnt);
+ 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_ARG(padapter),
+ no_gkey_bc_cnt,
+ no_gkey_mc_cnt);
+ }
+ start = jiffies;
+ no_gkey_bc_cnt = 0;
+ no_gkey_mc_cnt = 0;
}
- start = 0;
- no_gkey_bc_cnt = 0;
- no_gkey_mc_cnt = 0;
- prwskey = psecuritypriv->dot118021XGrpKey[prxattrib->key_index].skey;
- if (psecuritypriv->dot118021XGrpKeyid != prxattrib->key_index) {
- res = _FAIL;
- goto exit;
- }
- } else {
- prwskey = &stainfo->dot118021x_UncstKey.skey[0];
+ goto exit;
}
- length = ((union recv_frame *)precvframe)->u.hdr.len - prxattrib->hdrlen - prxattrib->iv_len;
-
- res = aes_decipher(prwskey, prxattrib->hdrlen, pframe, length);
+ 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_ARG(padapter),
+ no_gkey_bc_cnt,
+ no_gkey_mc_cnt);
+ }
+ start = 0;
+ no_gkey_bc_cnt = 0;
+ no_gkey_mc_cnt = 0;
+ prwskey = psecuritypriv->dot118021XGrpKey[prxattrib->key_index].skey;
+ if (psecuritypriv->dot118021XGrpKeyid != prxattrib->key_index) {
+ res = _FAIL;
+ goto exit;
+ }
} else {
- res = _FAIL;
+ prwskey = &stainfo->dot118021x_UncstKey.skey[0];
}
+
+ length = ((union recv_frame *)precvframe)->u.hdr.len - prxattrib->hdrlen - prxattrib->iv_len;
+
+ res = aes_decipher(prwskey, prxattrib->hdrlen, pframe, length);
+
exit:
return res;
}
--
2.34.1
next prev parent reply other threads:[~2026-03-19 12:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-17 16:51 [PATCH] staging: rtl8723bs: refactor rtw_aes_decrypt() to reduce nesting Lin YuChen
2026-03-18 15:56 ` Greg KH
2026-03-18 21:51 ` [PATCH v2 0/2] staging: rtl8723bs: refactor rtw_aes_decrypt() Lin YuChen
2026-03-18 21:51 ` [PATCH v2 1/2] staging: rtl8723bs: use guard clause for AES check Lin YuChen
2026-03-19 7:59 ` Dan Carpenter
2026-03-19 12:07 ` [PATCH v3 0/2] staging: rtl8723bs: refactor rtw_aes_decrypt() Lin YuChen
2026-03-19 12:07 ` [PATCH v3 1/2] staging: rtl8723bs: use guard clause for AES check Lin YuChen
2026-03-19 12:07 ` Lin YuChen [this message]
2026-03-19 12:46 ` [PATCH v3 0/2] staging: rtl8723bs: refactor rtw_aes_decrypt() Dan Carpenter
2026-03-19 17:01 ` YuChen Lin
2026-03-18 21:51 ` [PATCH v2 2/2] staging: rtl8723bs: use guard clause for stainfo check Lin YuChen
2026-03-19 7:58 ` [PATCH] staging: rtl8723bs: refactor rtw_aes_decrypt() to reduce nesting Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260319120737.29692-3-starpt.official@gmail.com \
--to=starpt.official@gmail.com \
--cc=dan.carpenter@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=straube.linux@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox