2008-07-23 23:52:34

by Harvey Harrison

[permalink] [raw]
Subject: [PATCH] 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

Signed-off-by: Harvey Harrison <[email protected]>
---
fs/cifs/cifssmb.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 4511b70..56f1a71 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -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



2008-07-24 00:20:33

by Steve French

[permalink] [raw]
Subject: Re: [PATCH] cifs: avoid mixing bool and le16

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?

On Wed, Jul 23, 2008 at 6:52 PM, Harvey Harrison
<[email protected]> wrote:
> 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
>
> Signed-off-by: Harvey Harrison <[email protected]>
> ---
> fs/cifs/cifssmb.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
> index 4511b70..56f1a71 100644
> --- a/fs/cifs/cifssmb.c
> +++ b/fs/cifs/cifssmb.c
> @@ -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
>
>
>
>



--
Thanks,

Steve

2008-07-24 00:24:20

by Harvey Harrison

[permalink] [raw]
Subject: Re: [PATCH] cifs: avoid mixing bool and le16

On Wed, 2008-07-23 at 19:19 -0500, Steve French wrote:
> 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

2008-07-24 00:27:06

by Steve French

[permalink] [raw]
Subject: Re: [PATCH] cifs: avoid mixing bool and le16

On Wed, Jul 23, 2008 at 7:24 PM, Harvey Harrison
<[email protected]> wrote:
> 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 :)



--
Thanks,

Steve

2008-07-25 18:25:24

by Al Viro

[permalink] [raw]
Subject: Re: [PATCH] cifs: avoid mixing bool and le16

On Wed, Jul 23, 2008 at 04:52:18PM -0700, Harvey Harrison wrote:
> 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
>
> Signed-off-by: Harvey Harrison <[email protected]>

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.