Skip to contentSkip to conversation

staging: rtl8188eu: if/else replaced by min_t

PATCH In review Ivan Safonov 3 participants 3 messages Nov 6, 2015 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 staging: rtl8188eu: if/else replaced by min_t

Duplicated code removed.

---
 drivers/staging/rtl8188eu/core/rtw_cmd.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/staging/rtl8188eu/core/rtw_cmd.c +1 -4
index c0fff77..80c602e 100644
@@ -446,10 +446,7 @@ u8 rtw_joinbss_cmd(struct adapter  *padapter, struct wlan_network *pnetwork)
 
 	psecuritypriv->authenticator_ie[0] = (unsigned char)psecnetwork->IELength;
 
-	if ((psecnetwork->IELength-12) < (256-1))
-		memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->IEs[12], psecnetwork->IELength-12);
-	else
-		memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->IEs[12], (256-1));
+	memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->IEs[12], min_t(int, psecnetwork->IELength - 12, 256 - 1));
 
 	psecnetwork->IELength = 0;
 	/*  Added by Albert 2009/02/18 */
Signature · 1 line
2.4.10
#1 lore raw
Quoted 12 lines · Ivan Safonov

Duplicated code removed.

---
 drivers/staging/rtl8188eu/core/rtw_cmd.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/staging/rtl8188eu/core/rtw_cmd.c +0 -0
index c0fff77..80c602e 100644

drivers/staging/rtl8188eu/core/rtw_cmd.c u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork) · line 450

Quoted 9 lines
drivers/staging/rtl8188eu/core/rtw_cmd.c +1 -4
@@ -446,10 +446,7 @@ u8 rtw_joinbss_cmd(struct adapter  *padapter, struct wlan_network *pnetwork)
 
        psecuritypriv->authenticator_ie[0] = (unsigned char)psecnetwork->IELength;
 
-       if ((psecnetwork->IELength-12) < (256-1))
-               memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->IEs[12], psecnetwork->IELength-12);
-       else
-               memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->IEs[12], (256-1));
+       memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->IEs[12], min_t(int, psecnetwork->IELength - 12, 256 - 1));
 

Run checkpatch.pl.

256 looks like sizeof(…).

Quoted 10 lines
drivers/staging/rtl8188eu/core/rtw_cmd.c +0 -1
        psecnetwork->IELength = 0;
        /*  Added by Albert 2009/02/18 */
--

2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 4 lines · Andy Shevchenko
Quoted 2 lines · Ivan Safonov
        psecuritypriv->authenticator_ie[0] = (unsigned char)psecnetwork->IELength;
Quoted 8 lines

drivers/staging/rtl8188eu/core/rtw_cmd.c u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork) · line 449

Quoted 6 lines
drivers/staging/rtl8188eu/core/rtw_cmd.c +1 -4
-       if ((psecnetwork->IELength-12) < (256-1))
-               memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->IEs[12], psecnetwork->IELength-12);
-       else
-               memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->IEs[12], (256-1));
+       memcpy(&psecuritypriv->authenticator_ie[1], &psecnetwork->IEs[12], min_t(int, psecnetwork->IELength - 12, 256 - 1));

Run checkpatch.pl.

The long line was there in the original so it's forgivable but probably should be changed in v2.

The main thing though is that this looks to introduce a memory corruption but because the original used unsigned comparison and we have changed it to doing "int" comparison. It should be u32 like in the original code. Or size_t would be ok too.

Quoted 2 lines

256 looks like sizeof(…).

Yup.

regards,
dan carpenter