staging: r8188eu: convert type of second parameter of rtw_*_decrypt()
authorMichael Straube <straube.linux@gmail.com>
Sun, 29 Aug 2021 11:25:54 +0000 (13:25 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 13 Sep 2021 06:49:44 +0000 (08:49 +0200)
Convert the type of the second parameter of the rtw_*_decrypt() functions
to struct recv_frame.

All callers of the functions cast the type to (u8 *) and in the functions
it is casted back to the original type. Changing the type of the second
parameter to struct recv_frame avoids these unnecessary casts and improves
readability.

Acked-by: Phillip Potter <phil@philpotter.co.uk>
Signed-off-by: Michael Straube <straube.linux@gmail.com>
Link: https://lore.kernel.org/r/20210829112555.8726-3-straube.linux@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/r8188eu/core/rtw_recv.c
drivers/staging/r8188eu/core/rtw_security.c
drivers/staging/r8188eu/include/rtw_security.h

index e082edfbaad826d9cfe0b2721680456adc0334d3..019c5364905b44921b94314d074e6ad7f348313d 100644 (file)
@@ -418,13 +418,13 @@ static struct recv_frame *decryptor(struct adapter *padapter, struct recv_frame
                switch (prxattrib->encrypt) {
                case _WEP40_:
                case _WEP104_:
-                       rtw_wep_decrypt(padapter, (u8 *)precv_frame);
+                       rtw_wep_decrypt(padapter, precv_frame);
                        break;
                case _TKIP_:
-                       res = rtw_tkip_decrypt(padapter, (u8 *)precv_frame);
+                       res = rtw_tkip_decrypt(padapter, precv_frame);
                        break;
                case _AES_:
-                       res = rtw_aes_decrypt(padapter, (u8 *)precv_frame);
+                       res = rtw_aes_decrypt(padapter, precv_frame);
                        break;
                default:
                        break;
index 5168159d8ae7f8b0cd1683daf128af520faf8afa..0836f38ca2844f59c2914f7b32d64c6c20b430c8 100644 (file)
@@ -134,7 +134,7 @@ void rtw_wep_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe)
 
 }
 
-void rtw_wep_decrypt(struct adapter  *padapter, u8 *precvframe)
+void rtw_wep_decrypt(struct adapter *padapter, struct recv_frame *precvframe)
 {
        /*  exclude ICV */
        struct arc4context       mycontext;
@@ -142,10 +142,10 @@ void rtw_wep_decrypt(struct adapter  *padapter, u8 *precvframe)
        u32     keylength;
        u8      *pframe, *payload, *iv, wepkey[16];
        u8       keyindex;
-       struct  rx_pkt_attrib    *prxattrib = &(((struct recv_frame *)precvframe)->attrib);
+       struct  rx_pkt_attrib    *prxattrib = &precvframe->attrib;
        struct  security_priv   *psecuritypriv = &padapter->securitypriv;
 
-       pframe = (unsigned char *)((struct recv_frame *)precvframe)->rx_data;
+       pframe = (unsigned char *)precvframe->rx_data;
 
        /* start to decrypt recvframe */
        if ((prxattrib->encrypt == _WEP40_) || (prxattrib->encrypt == _WEP104_)) {
@@ -154,7 +154,7 @@ void rtw_wep_decrypt(struct adapter  *padapter, u8 *precvframe)
                keylength = psecuritypriv->dot11DefKeylen[keyindex];
                memcpy(&wepkey[0], iv, 3);
                memcpy(&wepkey[3], &psecuritypriv->dot11DefKey[keyindex].skey[0], keylength);
-               length = ((struct recv_frame *)precvframe)->len - prxattrib->hdrlen - prxattrib->iv_len;
+               length = precvframe->len - prxattrib->hdrlen - prxattrib->iv_len;
 
                payload = pframe + prxattrib->iv_len + prxattrib->hdrlen;
 
@@ -580,7 +580,7 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe)
 }
 
 /* The hlen isn't include the IV */
-u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
+u32 rtw_tkip_decrypt(struct adapter *padapter, struct recv_frame *precvframe)
 {                                                                                                                                      /*  exclude ICV */
        u16 pnl;
        u32 pnh;
@@ -596,11 +596,11 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
        u8      *pframe, *payload, *iv, *prwskey;
        union pn48 dot11txpn;
        struct  sta_info                *stainfo;
-       struct  rx_pkt_attrib    *prxattrib = &((struct recv_frame *)precvframe)->attrib;
+       struct  rx_pkt_attrib    *prxattrib = &precvframe->attrib;
        struct  security_priv   *psecuritypriv = &padapter->securitypriv;
        u32             res = _SUCCESS;
 
-       pframe = (unsigned char *)((struct recv_frame *)precvframe)->rx_data;
+       pframe = (unsigned char *)precvframe->rx_data;
 
        /* 4 start to decrypt recvframe */
        if (prxattrib->encrypt == _TKIP_) {
@@ -619,7 +619,7 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
 
                        iv = pframe + prxattrib->hdrlen;
                        payload = pframe + prxattrib->iv_len + prxattrib->hdrlen;
-                       length = ((struct recv_frame *)precvframe)->len - prxattrib->hdrlen - prxattrib->iv_len;
+                       length = precvframe->len - prxattrib->hdrlen - prxattrib->iv_len;
 
                        GET_TKIP_PN(iv, dot11txpn);
 
@@ -1402,17 +1402,18 @@ static int aes_decipher(u8 *key, uint   hdrlen,
        return res;
 }
 
-u32    rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe)
+u32 rtw_aes_decrypt(struct adapter *padapter, struct recv_frame *precvframe)
 {      /*  exclude ICV */
        /* Intermediate Buffers */
        int             length;
        u8      *pframe, *prwskey;      /*  *payload,*iv */
        struct  sta_info                *stainfo;
-       struct  rx_pkt_attrib    *prxattrib = &((struct recv_frame *)precvframe)->attrib;
+       struct  rx_pkt_attrib    *prxattrib = &precvframe->attrib;
        struct  security_priv   *psecuritypriv = &padapter->securitypriv;
        u32     res = _SUCCESS;
 
-       pframe = (unsigned char *)((struct recv_frame *)precvframe)->rx_data;
+       pframe = (unsigned char *)precvframe->rx_data;
+
        /* 4 start to encrypt each fragment */
        if (prxattrib->encrypt == _AES_) {
                stainfo = rtw_get_stainfo(&padapter->stapriv, &prxattrib->ta[0]);
@@ -1434,7 +1435,7 @@ u32       rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe)
                        } else {
                                prwskey = &stainfo->dot118021x_UncstKey.skey[0];
                        }
-                       length = ((struct recv_frame *)precvframe)->len - prxattrib->hdrlen - prxattrib->iv_len;
+                       length = precvframe->len - prxattrib->hdrlen - prxattrib->iv_len;
                        res = aes_decipher(prwskey, prxattrib->hdrlen, pframe, length);
                } else {
                        res = _FAIL;
index 4e6d4257b7bab2a68edfca923e8cf044c60bb167..1fc1a4f30eeccbf08c4b084da1d91736c69ca3b1 100644 (file)
@@ -333,9 +333,9 @@ void rtw_seccalctkipmic(u8 *key, u8 *header, u8 *data, u32 data_len,
 u32 rtw_aes_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe);
 u32 rtw_tkip_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe);
 void rtw_wep_encrypt(struct adapter *padapter, struct xmit_frame *pxmitframe);
-u32 rtw_aes_decrypt(struct adapter *padapter, u8  *precvframe);
-u32 rtw_tkip_decrypt(struct adapter *padapter, u8  *precvframe);
-void rtw_wep_decrypt(struct adapter *padapter, u8  *precvframe);
+u32 rtw_aes_decrypt(struct adapter *padapter, struct recv_frame *precvframe);
+u32 rtw_tkip_decrypt(struct adapter *padapter, struct recv_frame *precvframe);
+void rtw_wep_decrypt(struct adapter *padapter, struct recv_frame *precvframe);
 void rtw_use_tkipkey_handler(void *FunctionContext);
 
 #endif /* __RTL871X_SECURITY_H_ */