From: Leonardo Martins Martins <dev.lmmrtns@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
Leonardo Martins Martins <dev.lmmrtns@gmail.com>
Subject: [PATCH v2 3/3] staging: rtl8723bs: extract inner loop in phy_tx_power_limit_to_index()
Date: Fri, 02 Oct 2026 01:07:37 -0300 [thread overview]
Message-ID: <20261002-rtl8723bs-tx-pwr-limit-v2-3-48b180fb6f7f@gmail.com> (raw)
In-Reply-To: <20261002-rtl8723bs-tx-pwr-limit-v2-0-48b180fb6f7f@gmail.com>
phy_tx_power_limit_to_index() iterates over an array with 5 indexes,
making the code deeply nested, move the inner loop into an auxiliary
static function to reduce nesting and improve readability.
Signed-off-by: Leonardo Martins Martins <dev.lmmrtns@gmail.com>
---
drivers/staging/rtl8723bs/hal/hal_com_phycfg.c | 48 ++++++++++++++------------
1 file changed, 26 insertions(+), 22 deletions(-)
diff --git a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c
index 937441aa7dfee50857d37e0d0aa1415037b8cc60..f9f79bead66dcf3df155b505156f2ff73ea5fbed 100644
--- a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c
+++ b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c
@@ -713,35 +713,39 @@ s8 phy_get_tx_pwr_lmt(struct adapter *adapter, u32 reg_pwr_tbl_sel,
return pwr_lmt;
}
+static void __phy_tx_power_limit_to_index(struct hal_com_data *hal_data, struct registry_priv *r,
+ u8 regulation, u8 bw, u8 channel, u8 rs)
+{
+ s8 tmp_pwr_lmt = hal_data->TxPwrLimit_2_4G[regulation][bw][rs][channel][RF_PATH_A];
+ s8 tmp;
+ u8 path;
+ u8 pwr_base;
+
+ for (path = RF_PATH_A; path < MAX_RF_PATH_NUM; ++path) {
+ if (hal_data->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE)
+ pwr_base = hal_data->TxPwrByRateBase2_4G[path][rs];
+ else
+ pwr_base = r->reg_power_base * 2;
+
+ if (tmp_pwr_lmt != MAX_POWER_INDEX) {
+ tmp = tmp_pwr_lmt - pwr_base;
+ hal_data->TxPwrLimit_2_4G[regulation][bw][rs][channel][path] = tmp;
+ }
+ }
+}
+
void phy_tx_power_limit_to_index(struct adapter *adapter)
{
struct hal_com_data *hal_data = GET_HAL_DATA(adapter);
struct registry_priv *r = &adapter->registrypriv;
- u8 pwr_base = 0x2E;
u8 regulation, bw, channel, rs;
- s8 tmp = 0, tmp_pwr_lmt = 0;
- u8 path = 0;
for (regulation = 0; regulation < MAX_REGULATION_NUM; ++regulation) {
- for (bw = 0; bw < MAX_2_4G_BANDWIDTH_NUM; ++bw) {
- for (channel = 0; channel < CHANNEL_MAX_NUMBER_2G; ++channel) {
- for (rs = 0; rs < MAX_RATE_SECTION_NUM; ++rs) {
- tmp_pwr_lmt = hal_data->TxPwrLimit_2_4G[regulation][bw][rs][channel][RF_PATH_A];
-
- for (path = RF_PATH_A; path < MAX_RF_PATH_NUM; ++path) {
- if (hal_data->odmpriv.PhyRegPgValueType == PHY_REG_PG_EXACT_VALUE)
- pwr_base = hal_data->TxPwrByRateBase2_4G[path][rs];
- else
- pwr_base = r->reg_power_base * 2;
-
- if (tmp_pwr_lmt != MAX_POWER_INDEX) {
- tmp = tmp_pwr_lmt - pwr_base;
- hal_data->TxPwrLimit_2_4G[regulation][bw][rs][channel][path] = tmp;
- }
- }
- }
- }
- }
+ for (bw = 0; bw < MAX_2_4G_BANDWIDTH_NUM; ++bw)
+ for (channel = 0; channel < CHANNEL_MAX_NUMBER_2G; ++channel)
+ for (rs = 0; rs < MAX_RATE_SECTION_NUM; ++rs)
+ __phy_tx_power_limit_to_index(hal_data, r, regulation, bw,
+ channel, rs);
}
}
--
2.47.3
next prev parent reply other threads:[~2026-10-02 4:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-02 4:07 [PATCH v2 0/3] staging: rtl8723bs: refactor PHY_ConvertTxPowerLimitToPowerIndex() Leonardo Martins Martins
2026-10-02 4:07 ` [PATCH v2 1/3] staging: rtl8723bs: rename local vars in phy_tx_power_limit_to_index() Leonardo Martins Martins
2026-10-02 6:09 ` Greg Kroah-Hartman
2026-10-02 7:30 ` Leonardo Martins Martins
2026-10-02 4:07 ` [PATCH v2 2/3] staging: rtl8723bs: access TxPowerByRateBase2_4G directly Leonardo Martins Martins
2026-10-02 4:07 ` Leonardo Martins Martins [this message]
2026-10-02 6:10 ` [PATCH v2 0/3] staging: rtl8723bs: refactor PHY_ConvertTxPowerLimitToPowerIndex() Greg Kroah-Hartman
2026-10-02 7:39 ` Leonardo Martins Martins
2026-10-02 7:55 ` Greg Kroah-Hartman
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=20261002-rtl8723bs-tx-pwr-limit-v2-3-48b180fb6f7f@gmail.com \
--to=dev.lmmrtns@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
/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
all inboxes | Powered by JetHome®