[PATCH 10/12] wifi: mwifiex: Use max() to improve code

Qianfeng Rong posted 12 patches 3 months ago
[PATCH 10/12] wifi: mwifiex: Use max() to improve code
Posted by Qianfeng Rong 3 months ago
Use max() to reduce the code and improve its readability.

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
 drivers/net/wireless/marvell/mwifiex/cfg80211.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/marvell/mwifiex/cfg80211.c b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
index 286378770e9e..d81db73ac77f 100644
--- a/drivers/net/wireless/marvell/mwifiex/cfg80211.c
+++ b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
@@ -4783,10 +4783,8 @@ int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
 		wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
 	wiphy->n_iface_combinations = 1;
 
-	if (adapter->max_sta_conn > adapter->max_p2p_conn)
-		wiphy->max_ap_assoc_sta = adapter->max_sta_conn;
-	else
-		wiphy->max_ap_assoc_sta = adapter->max_p2p_conn;
+	wiphy->max_ap_assoc_sta = max(adapter->max_sta_conn,
+				      adapter->max_p2p_conn);
 
 	/* Initialize cipher suits */
 	wiphy->cipher_suites = mwifiex_cipher_suites;
-- 
2.34.1
Re: [PATCH 10/12] wifi: mwifiex: Use max() to improve code
Posted by Jeff Chen 3 months ago
Hi Qianfeng,
Thanks for the cleanup.

On Wed, Jul 09, 2025 at 10:21:38 AM +0800, Qianfeng Rong wrote:
> Use max() to reduce the code and improve its readability.
> 
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
> ---
>  drivers/net/wireless/marvell/mwifiex/cfg80211.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/wireless/marvell/mwifiex/cfg80211.c b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
> index 286378770e9e..d81db73ac77f 100644
> --- a/drivers/net/wireless/marvell/mwifiex/cfg80211.c
> +++ b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
> @@ -4783,10 +4783,8 @@ int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
>  		wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
>  	wiphy->n_iface_combinations = 1;
>  
> -	if (adapter->max_sta_conn > adapter->max_p2p_conn)
> -		wiphy->max_ap_assoc_sta = adapter->max_sta_conn;
> -	else
> -		wiphy->max_ap_assoc_sta = adapter->max_p2p_conn;
> +	wiphy->max_ap_assoc_sta = max(adapter->max_sta_conn,
> +				      adapter->max_p2p_conn);

adapter->max_sta_conn and adapter->max_p2p_conn are u8, and wiphy->max_ap_assoc_sta is u16.
To ensure type safety and maintainability, I recommend using max_t() with typeof():
wiphy->max_ap_assoc_sta = max_t(typeof(wiphy->max_ap_assoc_sta),
                                adapter->max_sta_conn,
                                adapter->max_p2p_conn);

>  
>  	/* Initialize cipher suits */
>  	wiphy->cipher_suites = mwifiex_cipher_suites;
> -- 
> 2.34.1
> 
Re: [PATCH 10/12] wifi: mwifiex: Use max() to improve code
Posted by Qianfeng Rong 3 months ago
在 2025/7/9 13:42, Jeff Chen 写道:
> -     if (adapter->max_sta_conn > adapter->max_p2p_conn)
> -             wiphy->max_ap_assoc_sta = adapter->max_sta_conn;
> -     else
> -             wiphy->max_ap_assoc_sta = adapter->max_p2p_conn;
> +     wiphy->max_ap_assoc_sta = max(adapter->max_sta_conn,
> +                                   adapter->max_p2p_conn);
> adapter->max_sta_conn and adapter->max_p2p_conn are u8, and wiphy->max_ap_assoc_sta is u16.
> To ensure type safety and maintainability, I recommend using max_t() with typeof():
> wiphy->max_ap_assoc_sta = max_t(typeof(wiphy->max_ap_assoc_sta),
>                                  adapter->max_sta_conn,
>                                  adapter->max_p2p_conn);
>
Thanks for taking the time to reply.
I will try to do this in the next version.

Best regards,
Qianfeng
>