Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1412273

Re: [PATCH] security: Use || instead of | for boolean expressions

From "Serge E. Hallyn" <serge@hallyn.com>
Newsgroups linux.kernel
Subject Re: [PATCH] security: Use || instead of | for boolean expressions
Date 2016-06-02 16:20 +0200
Message-ID <rFBDA-6Xf-19@gated-at.bofh.it> (permalink)
References <rF7vP-4JC-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wed, Jun 01, 2016 at 02:03:02PM +0800, Rui Teng wrote:
> Sparse spits out the following warning:
> 	security/commoncap.c:989:41: warning: dubious: !x | y
> 
> Bitwise and logical are equivalent here, but logical was intended.
> Replacing the bit-wise '|' with the boolean '||' silences the sparse warning.

Hi,

this looks ok, but I'm worried by

> The generated code for both cases is the same.

That cannot be.  The logical result should be the same, but the
generated code cannot be.

I'm cc:ing Andy as this code came in with his patch.  Is there an
actual reason for having used bitwise here?

thanks,
-serge

> Signed-off-by: Rui Teng <rui.teng@linux.vnet.ibm.com>
> ---
>  security/commoncap.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/security/commoncap.c b/security/commoncap.c
> index e7fadde..8f6fb24 100644
> --- a/security/commoncap.c
> +++ b/security/commoncap.c
> @@ -976,7 +976,7 @@ int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
>  
>  	case PR_CAP_AMBIENT:
>  		if (arg2 == PR_CAP_AMBIENT_CLEAR_ALL) {
> -			if (arg3 | arg4 | arg5)
> +			if (arg3 || arg4 || arg5)
>  				return -EINVAL;
>  
>  			new = prepare_creds();
> @@ -986,7 +986,7 @@ int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
>  			return commit_creds(new);
>  		}
>  
> -		if (((!cap_valid(arg3)) | arg4 | arg5))
> +		if (((!cap_valid(arg3)) || arg4 || arg5))
>  			return -EINVAL;
>  
>  		if (arg2 == PR_CAP_AMBIENT_IS_SET) {
> -- 
> 2.7.4

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] security: Use || instead of | for boolean expressions Rui Teng <rui.teng@linux.vnet.ibm.com> - 2016-06-01 08:10 +0200
  Re: [PATCH] security: Use || instead of | for boolean expressions "Serge E. Hallyn" <serge@hallyn.com> - 2016-06-02 16:20 +0200
    Re: [PATCH] security: Use || instead of | for boolean expressions Rui Teng <rui.teng@linux.vnet.ibm.com> - 2016-06-02 19:00 +0200
      Re: [PATCH] security: Use || instead of | for boolean expressions Al Viro <viro@ZenIV.linux.org.uk> - 2016-06-02 19:40 +0200

csiph-web