Re: [PATCH 2/7] rtl8xxxu: add handle for mac80211 get_txpower

From: Joe Perches
Date: Fri May 14 2021 - 00:22:36 EST


On Fri, 2021-05-14 at 04:04 +0200, Reto Schneider wrote:
> From: Chris Chiu <chiu@xxxxxxxxxxxxx>
>
> add .get_txpower handle for mac80211 operations for `iw` and `wext`
> tools to get the underlying tx power (max limit).
[]
> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
[]

> +int
> +rtl8xxxu_gen1_get_tx_power(struct rtl8xxxu_priv *priv)
> +{
> + u8 txpwr_level;
> + int txpwr_dbm;
> +
> + txpwr_level = priv->cur_cck_txpwridx;
> + txpwr_dbm = rtl8xxxu_gen1_txpwridx_to_dbm(priv, WIRELESS_MODE_B,
> + txpwr_level);
> + txpwr_level = priv->cur_ofdm24g_txpwridx +
> + priv->ofdm_tx_power_index_diff[1].a;
> +
> + if (rtl8xxxu_gen1_txpwridx_to_dbm(priv, WIRELESS_MODE_G, txpwr_level)
> + > txpwr_dbm)
> + txpwr_dbm = rtl8xxxu_gen1_txpwridx_to_dbm(priv, WIRELESS_MODE_G,
> + txpwr_level);

probably better to use a temporaries instead of multiple calls.

foo = rtl8xxxu_gen1_txpwridx_to_dbm(priv, WIRELESS_MODE_G, txpwr_level);
if (foo > txpwr_dbm)
txpwr_dbm = foo;

> + txpwr_level = priv->cur_ofdm24g_txpwridx;
> + if (rtl8xxxu_gen1_txpwridx_to_dbm(priv, WIRELESS_MODE_N_24G,
> + txpwr_level) > txpwr_dbm)
> + txpwr_dbm = rtl8xxxu_gen1_txpwridx_to_dbm(priv,
> + WIRELESS_MODE_N_24G,
> + txpwr_level);
> +
> + return txpwr_dbm;

foo = rtl8xxxu_gen1_txpwridx_to_dbm(priv, WIRELESS_MODE_N_24G, txpwr_level);

return min(txpwr_dbm, foo);