Skip to contentSkip to conversation

cifs: avoid mixing bool and le16

PATCH In review Harvey Harrison 3 participants 5 messages Jul 23, 2008 – Jul 25, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: avoid mixing bool and le16

fs/cifs/cifssmb.c:3917:13: warning: incorrect type in assignment (different base types)
fs/cifs/cifssmb.c:3917:13: expected bool [unsigned] [usertype] is_unicode
fs/cifs/cifssmb.c:3917:13: got restricted __le16

---
 fs/cifs/cifssmb.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/cifs/cifssmb.c +1 -1
index 4511b70..56f1a71 100644
@@ -3914,7 +3914,7 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr,
 	bool is_unicode;
 	struct dfs_referral_level_3 *ref;
 
-	is_unicode = pSMBr->hdr.Flags2 & SMBFLG2_UNICODE;
+	is_unicode = !!(pSMBr->hdr.Flags2 & SMBFLG2_UNICODE);
 	*num_of_nodes = le16_to_cpu(pSMBr->NumberOfReferrals);
 
 	if (*num_of_nodes < 1) {
Signature · 1 line
1.5.6.4.570.g052e
#1 lore raw

Seems like a cast to bool or an "if ...else" would be clearer than using !! By the way I don't see this warning - is it a newer compiler warning?

Quoted 28 lines · Harvey Harrison

fs/cifs/cifssmb.c:3917:13: warning: incorrect type in assignment (different base types)
fs/cifs/cifssmb.c:3917:13: expected bool [unsigned] [usertype] is_unicode
fs/cifs/cifssmb.c:3917:13: got restricted __le16

---
 fs/cifs/cifssmb.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/cifs/cifssmb.c +1 -2
index 4511b70..56f1a71 100644
@@ -3914,7 +3914,7 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr,
       bool is_unicode;
       struct dfs_referral_level_3 *ref;
 
-       is_unicode = pSMBr->hdr.Flags2 & SMBFLG2_UNICODE;
+       is_unicode = !!(pSMBr->hdr.Flags2 & SMBFLG2_UNICODE);
       *num_of_nodes = le16_to_cpu(pSMBr->NumberOfReferrals);
 
       if (*num_of_nodes < 1) {
--

1.5.6.4.570.g052e

Signature · 3 lines
Thanks,

Steve
#2 lore raw
Quoted 3 lines · Steve French

Seems like a cast to bool or an "if ...else" would be clearer than using !! By the way I don't see this warning - is it a newer compiler warning?

Sorry, sometimes I forget to say sparse warning. This is with __CHECK_ENDIAN__ as well.

Would you prefer:

	if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE)
		is_unicode = true;
	else
		is_unicode = false;

Instead?

Harvey

#3 lore raw
Quoted 8 lines · Harvey Harrison

On Wed, 2008-07-23 at 19:19 -0500, Steve French wrote:
Would you prefer:

       if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE)
               is_unicode = true;
       else
               is_unicode = false;

Instead?

Yes :)

Signature · 3 lines
Thanks,

Steve
#4 lore raw
In reply to Harvey Harrison
Quoted 5 lines · Harvey Harrison

fs/cifs/cifssmb.c:3917:13: warning: incorrect type in assignment (different base types)
fs/cifs/cifssmb.c:3917:13: expected bool [unsigned] [usertype] is_unicode
fs/cifs/cifssmb.c:3917:13: got restricted __le16

It's a sparse bug - the thing doesn't treat conversions to bool right.

FWIW, if you want an obviously broken case, consider

char a[2 * (bool)2 - 1];

It *should* turn into

char a[1];

What happens instead is that bool is treated as 1-bit unsigned integer type, resulting in char a[-1].

So we need to fix that crap; the real rules are simple - conversion of any arithmetic or pointer type to _Bool behaves as if we had v != 0; same as for if/while/do/for conditions.