From: "Serge E. Hallyn" <serge@hallyn.com>
To: Rui Teng <rui.teng@linux.vnet.ibm.com>
Cc: serge.hallyn@canonical.com, james.l.morris@oracle.com,
serge@hallyn.com, linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org,
Andy Lutomirski <luto@amacapital.net>
Subject: Re: [PATCH] security: Use || instead of | for boolean expressions
Date: Thu, 2 Jun 2016 09:13:49 -0500 [thread overview]
Message-ID: <20160602141349.GA26954@mail.hallyn.com> (raw)
In-Reply-To: <1464760982-3721-1-git-send-email-rui.teng@linux.vnet.ibm.com>
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
next prev parent reply other threads:[~2016-06-02 14:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-01 6:03 [PATCH] security: Use || instead of | for boolean expressions Rui Teng
2016-06-02 14:13 ` Serge E. Hallyn [this message]
2016-06-02 16:53 ` Rui Teng
2016-06-02 17:37 ` Al Viro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160602141349.GA26954@mail.hallyn.com \
--to=serge@hallyn.com \
--cc=james.l.morris@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=rui.teng@linux.vnet.ibm.com \
--cc=serge.hallyn@canonical.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).