Skip to contentSkip to conversation

staging: rtl8723bs: core: fix some incorrect type warnings

PATCH In review Wan Jiabing 2 participants 5 messages Jun 3, 2021 – Jun 4, 2021 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8723bs: core: fix some incorrect type warnings

Fix some "incorrect type in assignment" in rtw_security.c.

The sparse warings:
drivers/staging//rtl8723bs/core/rtw_security.c:72:50: warning: incorrect type in assignment
drivers/staging//rtl8723bs/core/rtw_security.c:72:50: expected restricted __le32 [usertype]
drivers/staging//rtl8723bs/core/rtw_security.c:72:50: got unsigned int
drivers/staging//rtl8723bs/core/rtw_security.c:80:50: warning: incorrect type in assignment
drivers/staging//rtl8723bs/core/rtw_security.c:80:50: expected restricted __le32 [usertype]
drivers/staging//rtl8723bs/core/rtw_security.c:80:50: got unsigned int
drivers/staging//rtl8723bs/core/rtw_security.c:124:33: warning: cast to restricted __le32 drivers/staging//rtl8723bs/core/rtw_security.c:509:58: warning: incorrect type in assignment
drivers/staging//rtl8723bs/core/rtw_security.c:509:58: expected restricted __le32 [usertype]
drivers/staging//rtl8723bs/core/rtw_security.c:509:58: got unsigned int
drivers/staging//rtl8723bs/core/rtw_security.c:517:58: warning: incorrect type in assignment
drivers/staging//rtl8723bs/core/rtw_security.c:517:58: expected restricted __le32 [usertype]
drivers/staging//rtl8723bs/core/rtw_security.c:517:58: got unsigned int
drivers/staging//rtl8723bs/core/rtw_security.c:621:41: warning: cast to restricted __le32

---
 drivers/staging/rtl8723bs/core/rtw_security.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/staging/rtl8723bs/core/rtw_security.c +7 -7
index a99f439..4760999 100644
@@ -36,7 +36,7 @@ const char *security_type_str(u8 value)
 void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
 {																	/*  exclude ICV */
 
-	unsigned char crc[4];
+	u8 crc[4];
 
 	signed int	curfragnum, length;
 	u32 keylength;
@@ -69,7 +69,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
 
 				length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
 
-				*((__le32 *)crc) = ~crc32_le(~0, payload, length);
+				*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length));
 
 				arc4_setkey(ctx, wepkey, 3 + keylength);
 				arc4_crypt(ctx, payload, payload, length);
@@ -77,7 +77,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
 
 			} else {
 				length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
-				*((__le32 *)crc) = ~crc32_le(~0, payload, length);
+				*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length));
 				arc4_setkey(ctx, wepkey, 3 + keylength);
 				arc4_crypt(ctx, payload, payload, length);
 				arc4_crypt(ctx, payload + length, crc, 4);
@@ -121,7 +121,7 @@ void rtw_wep_decrypt(struct adapter  *padapter, u8 *precvframe)
 		arc4_crypt(ctx, payload, payload,  length);
 
 		/* calculate icv and compare the icv */
-		*((u32 *)crc) = le32_to_cpu(~crc32_le(~0, payload, length - 4));
+		*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length - 4));
 
 	}
 }
@@ -506,7 +506,7 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)
 
 				if ((curfragnum+1) == pattrib->nr_frags) {	/* 4 the last fragment */
 					length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
-					*((__le32 *)crc) = ~crc32_le(~0, payload, length);
+					*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length));
 
 					arc4_setkey(ctx, rc4key, 16);
 					arc4_crypt(ctx, payload, payload, length);
@@ -514,7 +514,7 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)
 
 				} else {
 					length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
-					*((__le32 *)crc) = ~crc32_le(~0, payload, length);
+					*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length));
 
 					arc4_setkey(ctx, rc4key, 16);
 					arc4_crypt(ctx, payload, payload, length);
@@ -618,7 +618,7 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
 			arc4_setkey(ctx, rc4key, 16);
 			arc4_crypt(ctx, payload, payload, length);
 
-			*((u32 *)crc) = le32_to_cpu(~crc32_le(~0, payload, length - 4));
+			*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length - 4));
 
 			if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] ||
 			    crc[1] != payload[length - 3] || crc[0] != payload[length - 4])
Signature · 1 line
2.7.4
#1 lore raw

Hi,all

I fix these warnings by refering other patches.

Actually, I don't understand clearly what I did.

But there are no warnings after this fix.

So if this fix were totally wrong, please told me and gave me some suggestions.

It is important for me to fix a sparse bug.

Thanks,
Jiabing

Quoted 93 lines

Fix some "incorrect type in assignment" in rtw_security.c.

The sparse warings:
drivers/staging//rtl8723bs/core/rtw_security.c:72:50: warning: incorrect type in assignment
drivers/staging//rtl8723bs/core/rtw_security.c:72:50: expected restricted __le32 [usertype]
drivers/staging//rtl8723bs/core/rtw_security.c:72:50: got unsigned int
drivers/staging//rtl8723bs/core/rtw_security.c:80:50: warning: incorrect type in assignment
drivers/staging//rtl8723bs/core/rtw_security.c:80:50: expected restricted __le32 [usertype]
drivers/staging//rtl8723bs/core/rtw_security.c:80:50: got unsigned int
drivers/staging//rtl8723bs/core/rtw_security.c:124:33: warning: cast to restricted __le32 drivers/staging//rtl8723bs/core/rtw_security.c:509:58: warning: incorrect type in assignment
drivers/staging//rtl8723bs/core/rtw_security.c:509:58: expected restricted __le32 [usertype]
drivers/staging//rtl8723bs/core/rtw_security.c:509:58: got unsigned int
drivers/staging//rtl8723bs/core/rtw_security.c:517:58: warning: incorrect type in assignment
drivers/staging//rtl8723bs/core/rtw_security.c:517:58: expected restricted __le32 [usertype]
drivers/staging//rtl8723bs/core/rtw_security.c:517:58: got unsigned int
drivers/staging//rtl8723bs/core/rtw_security.c:621:41: warning: cast to restricted __le32

---
drivers/staging/rtl8723bs/core/rtw_security.c | 14 +++++++-------

1 file changed, 7 insertions(+), 7 deletions(-)
drivers/staging/rtl8723bs/core/rtw_security.c +0 -0
index a99f439..4760999 100644
@@ -36,7 +36,7 @@ const char *security_type_str(u8 value)
 void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)

{ /* exclude ICV */

drivers/staging/rtl8723bs/core/rtw_security.c +1 -1
-	unsigned char crc[4];
+	u8 crc[4];
	signed int	curfragnum, length;
	u32 keylength;
drivers/staging/rtl8723bs/core/rtw_security.c +6 -6
@@ -69,7 +69,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
 
 				length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
 
-				*((__le32 *)crc) = ~crc32_le(~0, payload, length);
+				*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length));
 
 				arc4_setkey(ctx, wepkey, 3 + keylength);
 				arc4_crypt(ctx, payload, payload, length);
@@ -77,7 +77,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
 
 			} else {
 				length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
-				*((__le32 *)crc) = ~crc32_le(~0, payload, length);
+				*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length));
 				arc4_setkey(ctx, wepkey, 3 + keylength);
 				arc4_crypt(ctx, payload, payload, length);
 				arc4_crypt(ctx, payload + length, crc, 4);
@@ -121,7 +121,7 @@ void rtw_wep_decrypt(struct adapter  *padapter, u8 *precvframe)
 		arc4_crypt(ctx, payload, payload,  length);
 
 		/* calculate icv and compare the icv */
-		*((u32 *)crc) = le32_to_cpu(~crc32_le(~0, payload, length - 4));
+		*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length - 4));
 
 	}
 }
@@ -506,7 +506,7 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)
 
 				if ((curfragnum+1) == pattrib->nr_frags) {	/* 4 the last fragment */
 					length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
-					*((__le32 *)crc) = ~crc32_le(~0, payload, length);
+					*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length));
 
 					arc4_setkey(ctx, rc4key, 16);
 					arc4_crypt(ctx, payload, payload, length);
@@ -514,7 +514,7 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)
 
 				} else {
 					length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
-					*((__le32 *)crc) = ~crc32_le(~0, payload, length);
+					*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length));
 
 					arc4_setkey(ctx, rc4key, 16);
 					arc4_crypt(ctx, payload, payload, length);
@@ -618,7 +618,7 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
 			arc4_setkey(ctx, rc4key, 16);
 			arc4_crypt(ctx, payload, payload, length);
 
-			*((u32 *)crc) = le32_to_cpu(~crc32_le(~0, payload, length - 4));
+			*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length - 4));
 
 			if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] ||
 			    crc[1] != payload[length - 3] || crc[0] != payload[length - 4])
Signature · 1 line
2.7.4
#2 lore raw
Quoted 6 lines · Jiabing Wan

Hi,all

I fix these warnings by refering other patches.

Quoted 8 lines

Actually, I don't understand clearly what I did.

But there are no warnings after this fix.

So if this fix were totally wrong, please told me and gave me some suggestions.

It is important for me to fix a sparse bug.

Do not fix sparse bugs just for the sake of fixing sparse bugs. Fix things you know are needed to be fixed.

Please look closer at this to ensure that you really are fixing this correctly and understand what you are doing before sending it out.

thanks,

greg k-h

#3 lore raw
In reply to Wan Jiabing
Quoted 28 lines · Wan Jiabing

Fix some "incorrect type in assignment" in rtw_security.c.

The sparse warings:
drivers/staging//rtl8723bs/core/rtw_security.c:72:50: warning: incorrect type in assignment
drivers/staging//rtl8723bs/core/rtw_security.c:72:50: expected restricted __le32 [usertype]
drivers/staging//rtl8723bs/core/rtw_security.c:72:50: got unsigned int
drivers/staging//rtl8723bs/core/rtw_security.c:80:50: warning: incorrect type in assignment
drivers/staging//rtl8723bs/core/rtw_security.c:80:50: expected restricted __le32 [usertype]
drivers/staging//rtl8723bs/core/rtw_security.c:80:50: got unsigned int
drivers/staging//rtl8723bs/core/rtw_security.c:124:33: warning: cast to restricted __le32 drivers/staging//rtl8723bs/core/rtw_security.c:509:58: warning: incorrect type in assignment
drivers/staging//rtl8723bs/core/rtw_security.c:509:58: expected restricted __le32 [usertype]
drivers/staging//rtl8723bs/core/rtw_security.c:509:58: got unsigned int
drivers/staging//rtl8723bs/core/rtw_security.c:517:58: warning: incorrect type in assignment
drivers/staging//rtl8723bs/core/rtw_security.c:517:58: expected restricted __le32 [usertype]
drivers/staging//rtl8723bs/core/rtw_security.c:517:58: got unsigned int
drivers/staging//rtl8723bs/core/rtw_security.c:621:41: warning: cast to restricted __le32

---
 drivers/staging/rtl8723bs/core/rtw_security.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/staging/rtl8723bs/core/rtw_security.c +0 -0
index a99f439..4760999 100644

drivers/staging/rtl8723bs/core/rtw_security.c const char *security_type_str(u8 value) · line 39

Quoted 5 lines
drivers/staging/rtl8723bs/core/rtw_security.c +1 -1
@@ -36,7 +36,7 @@ const char *security_type_str(u8 value)
 void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
 {																	/*  exclude ICV */
 
-	unsigned char crc[4];
+	u8 crc[4];

Why change this?

drivers/staging/rtl8723bs/core/rtw_security.c void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe) · line 72

Quoted 9 lines
drivers/staging/rtl8723bs/core/rtw_security.c +1 -1
 	signed int	curfragnum, length;
 	u32 keylength;
@@ -69,7 +69,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
 
 				length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
 
-				*((__le32 *)crc) = ~crc32_le(~0, payload, length);
+				*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length));

Are you sure this does what you think it does?

What exactly is this doing now?

Quoted 13 lines
drivers/staging/rtl8723bs/core/rtw_security.c +1 -1
 				arc4_setkey(ctx, wepkey, 3 + keylength);
 				arc4_crypt(ctx, payload, payload, length);
@@ -77,7 +77,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
 
 			} else {
 				length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
-				*((__le32 *)crc) = ~crc32_le(~0, payload, length);
+				*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length));
 				arc4_setkey(ctx, wepkey, 3 + keylength);
 				arc4_crypt(ctx, payload, payload, length);
 				arc4_crypt(ctx, payload + length, crc, 4);

drivers/staging/rtl8723bs/core/rtw_security.c void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe) · line 124

Quoted 5 lines
drivers/staging/rtl8723bs/core/rtw_security.c +1 -1
@@ -121,7 +121,7 @@ void rtw_wep_decrypt(struct adapter  *padapter, u8 *precvframe)
 		arc4_crypt(ctx, payload, payload,  length);
 
 		/* calculate icv and compare the icv */
-		*((u32 *)crc) = le32_to_cpu(~crc32_le(~0, payload, length - 4));
+		*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length - 4));

This odd casting feels wrong, why is it correct now?

thanks,

greg k-h

#4 lore raw

Hi, Greg

I feel so sorry for a uncertain patch. I'll learn closer and fix it.

After learning deeper, I think:

Quoted 32 lines · Wan Jiabing
Quoted 31 lines

Fix some "incorrect type in assignment" in rtw_security.c.

The sparse warings:
drivers/staging//rtl8723bs/core/rtw_security.c:72:50: warning: incorrect type in assignment
drivers/staging//rtl8723bs/core/rtw_security.c:72:50: expected restricted __le32 [usertype]
drivers/staging//rtl8723bs/core/rtw_security.c:72:50: got unsigned int
drivers/staging//rtl8723bs/core/rtw_security.c:80:50: warning: incorrect type in assignment
drivers/staging//rtl8723bs/core/rtw_security.c:80:50: expected restricted __le32 [usertype]
drivers/staging//rtl8723bs/core/rtw_security.c:80:50: got unsigned int
drivers/staging//rtl8723bs/core/rtw_security.c:124:33: warning: cast to restricted __le32 drivers/staging//rtl8723bs/core/rtw_security.c:509:58: warning: incorrect type in assignment
drivers/staging//rtl8723bs/core/rtw_security.c:509:58: expected restricted __le32 [usertype]
drivers/staging//rtl8723bs/core/rtw_security.c:509:58: got unsigned int
drivers/staging//rtl8723bs/core/rtw_security.c:517:58: warning: incorrect type in assignment
drivers/staging//rtl8723bs/core/rtw_security.c:517:58: expected restricted __le32 [usertype]
drivers/staging//rtl8723bs/core/rtw_security.c:517:58: got unsigned int
drivers/staging//rtl8723bs/core/rtw_security.c:621:41: warning: cast to restricted __le32

---
 drivers/staging/rtl8723bs/core/rtw_security.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/staging/rtl8723bs/core/rtw_security.c +0 -0
index a99f439..4760999 100644
@@ -36,7 +36,7 @@ const char *security_type_str(u8 value)
 void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
 {																	/*  exclude ICV */
 
Quoted 5 lines

drivers/staging/rtl8723bs/core/rtw_security.c const char *security_type_str(u8 value) · line 39

Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_security.c +1 -1
-	unsigned char crc[4];
+	u8 crc[4];

Why change this?

* First reason is that other functions which using "~crc32_le" are all declaring "u8 crc[4];".

Only this function called "rtw_wep_encrypt" uses "unsigned char crc[4];" to declare crc. But anothor function called "rtw_wep_decrypt" uses "u8 crc[4];" to declare.

I think it is confusing and the declaration should be unanimous.

* Second reason is that function "crc32_le(~0, payload, length);" returns u32, so u8[4] is described u32.

* Third reason is that later function called "arc4_crypt" using "const *u8" as parameter.

So I think this change is reasonable.

Quoted 5 lines
Quoted 5 lines
drivers/staging/rtl8723bs/core/rtw_security.c +0 -0
 	signed int	curfragnum, length;
 	u32 keylength;
@@ -69,7 +69,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
 
Quoted 8 lines

drivers/staging/rtl8723bs/core/rtw_security.c void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe) · line 72

Quoted 4 lines
drivers/staging/rtl8723bs/core/rtw_security.c +1 -1
 				length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
 
-				*((__le32 *)crc) = ~crc32_le(~0, payload, length);
+				*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length));

Are you sure this does what you think it does?

What exactly is this doing now?

This change might be wrong totally. I feel sorry for this.

arc4_crypt need "const *u8" as parameter, so crc should be type "const *u8". But it use "__le32", so in my opinion, it should be

*((u32 *)crc) = ~crc32_le(~0, payload, length);

Quoted 16 lines
Quoted 16 lines
drivers/staging/rtl8723bs/core/rtw_security.c +1 -1
 				arc4_setkey(ctx, wepkey, 3 + keylength);
 				arc4_crypt(ctx, payload, payload, length);
@@ -77,7 +77,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
 
 			} else {
 				length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
-				*((__le32 *)crc) = ~crc32_le(~0, payload, length);
+				*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length));
 				arc4_setkey(ctx, wepkey, 3 + keylength);
 				arc4_crypt(ctx, payload, payload, length);
 				arc4_crypt(ctx, payload + length, crc, 4);
@@ -121,7 +121,7 @@ void rtw_wep_decrypt(struct adapter  *padapter, u8 *precvframe)
 		arc4_crypt(ctx, payload, payload,  length);
 
Quoted 6 lines

drivers/staging/rtl8723bs/core/rtw_security.c void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe) · line 124

Quoted 3 lines
drivers/staging/rtl8723bs/core/rtw_security.c +1 -1
 		/* calculate icv and compare the icv */
-		*((u32 *)crc) = le32_to_cpu(~crc32_le(~0, payload, length - 4));
+		*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length - 4));

This odd casting feels wrong, why is it correct now?

If we want to keep cpu value, we should fix it like this:
*((u32 *)crc) =~crc32_le(~0, payload, length - 4);

If we want to keep le32 value, we should fix it like this:
*((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length - 4));

These fix are all solve the warnings.
The problem is which one should I choose to meet the author's wishes.

And in this situation, it is hard to choose which one is better, as after this line, the function return directly.

Quoted 3 lines

thanks,

greg k-h

The new fix I choose to meet the author's wishes and fix warnings is following:
(Following content is just asked for suggestions and if it were proper, I would send v2.)

@@ -36,7 +36,7 @@ const char *security_type_str(u8 value)
void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
{ /* exclude ICV */

- unsigned char crc[4];
+ u8 crc[4];

signed int curfragnum, length;
u32 keylength;
@@ -69,7 +69,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)

length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;

- *((__le32 *)crc) = ~crc32_le(~0, payload, length);
+ *((u32 *)crc) =~crc32_le(~0, payload, length);

arc4_setkey(ctx, wepkey, 3 + keylength); arc4_crypt(ctx, payload, payload, length);
@@ -77,7 +77,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)

} else {
length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
- *((__le32 *)crc) = ~crc32_le(~0, payload, length);
+ *((u32 *)crc) = ~crc32_le(~0, payload, length);

arc4_setkey(ctx, wepkey, 3 + keylength); arc4_crypt(ctx, payload, payload, length); arc4_crypt(ctx, payload + length, crc, 4);
@@ -121,7 +121,7 @@ void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe)
arc4_crypt(ctx, payload, payload, length);

/* calculate icv and compare the icv */
- *((u32 *)crc) = le32_to_cpu(~crc32_le(~0, payload, length - 4));
+ *((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length - 4));

*- or
*-
*- + *((u32 *)crc) = ~crc32_le(~0, payload, length - 4);
*-
*- // !! This code is confusing, because after this line of code, the function return directly. I don't know what is the author's wish.

}
}
@@ -506,7 +506,7 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)

if ((curfragnum+1) == pattrib->nr_frags) { /* 4 the last fragment */
length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
- *((__le32 *)crc) = ~crc32_le(~0, payload, length);
+ *((u32 *)crc) = ~crc32_le(~0, payload, length);

arc4_setkey(ctx, rc4key, 16); arc4_crypt(ctx, payload, payload, length);
@@ -514,7 +514,7 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)

} else {
length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
- *((__le32 *)crc) = ~crc32_le(~0, payload, length);
+ *((u32 *)crc) = ~crc32_le(~0, payload, length);

arc4_setkey(ctx, rc4key, 16); arc4_crypt(ctx, payload, payload, length);
@@ -618,7 +618,7 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
arc4_setkey(ctx, rc4key, 16);
arc4_crypt(ctx, payload, payload, length);

- *((u32 *)crc) = le32_to_cpu(~crc32_le(~0, payload, length - 4));
+ *((u32 *)crc) = ~crc32_le(~0, payload, length - 4);

* or
*
* + *((__le32 *)crc) = cpu_to_le32(~crc32_le(~0, payload, length - 4));
*
* //!! This fix also confused me. But, IMO, u32 is better to meet the author's wishes.

 			if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] ||
 			    crc[1] != payload[length - 3] || crc[0] != payload[length - 4])
Signature · 8 lines
2.7.4

I think new patch is better, ;).

Please review.

Thanks,
Jiabing