]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
staging: rtl8723bs: replace ternary min comparison with min()
authorWilliam Hansen-Baird <william.hansen.baird@gmail.com>
Sat, 7 Feb 2026 22:01:36 +0000 (17:01 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 23 Feb 2026 14:39:55 +0000 (15:39 +0100)
Change type of local variable wpa_ie_len from int to u8.
wpa_ie_len gets its value either from elems->wpa_ie_len or
elems->rsn_ie_len which are both u8, and thus there's no reason
to cast them to int.

This allows rewriting ternary min comparison using the min() function from
linux/minmax.h as now both sides are unsigned.

Rewrite as well wpa_ie_len + 2 to wpa_ie_len + 2u,
to keep the expression unsigned and avoid overflows.

Signed-off-by: William Hansen-Baird <william.hansen.baird@gmail.com>
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://patch.msgid.link/20260207220136.67923-1-william.hansen.baird@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c

index b1f20aa81efbfb1afc7320e52a80d58bde2122dd..c213d31af86967b0d762a4c470e0a9c13f2ccc4f 100644 (file)
@@ -8,6 +8,7 @@
 #include <rtw_wifi_regd.h>
 #include <hal_btcoex.h>
 #include <linux/kernel.h>
+#include <linux/minmax.h>
 #include <linux/unaligned.h>
 
 static struct mlme_handler mlme_sta_tbl[] = {
@@ -933,7 +934,8 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
        struct sta_info *pstat;
        unsigned char *p, *pos, *wpa_ie;
        unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
-       int             i, ie_len, wpa_ie_len, left;
+       int             i, ie_len, left;
+       u8 wpa_ie_len;
        unsigned char supportRate[16];
        int                                     supportRateNum;
        unsigned short          status = WLAN_STATUS_SUCCESS;
@@ -1154,7 +1156,7 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
                        pstat->flags |= WLAN_STA_WPS;
                        copy_len = 0;
                } else {
-                       copy_len = ((wpa_ie_len+2) > sizeof(pstat->wpa_ie)) ? (sizeof(pstat->wpa_ie)):(wpa_ie_len+2);
+                       copy_len = min(sizeof(pstat->wpa_ie), wpa_ie_len + 2u);
                }