All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nick Desaulniers <ndesaulniers@google.com>
To: Nathan Chancellor <nathan@kernel.org>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	linux-input@vger.kernel.org,  linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev
Subject: Re: [PATCH] Input: touchscreen - Avoid bitwise vs logical OR warning
Date: Thu, 14 Oct 2021 14:02:43 -0700	[thread overview]
Message-ID: <CAKwvOdm1W52TmoU5m-RokN+aZF7w4G0KUu0TcWyircWi63onsA@mail.gmail.com> (raw)
In-Reply-To: <20211014205757.3474635-1-nathan@kernel.org>

On Thu, Oct 14, 2021 at 1:58 PM Nathan Chancellor <nathan@kernel.org> wrote:
>
> A new warning in clang points out a few places in this driver where a
> bitwise OR is being used with boolean types:
>
> drivers/input/touchscreen.c:81:17: warning: use of bitwise '|' with boolean operands [-Wbitwise-instead-of-logical]
>         data_present = touchscreen_get_prop_u32(dev, "touchscreen-min-x",
>                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> This use of a bitwise OR is intentional, as bitwise operations do not
> short circuit, which allows all the calls to touchscreen_get_prop_u32()
> to happen so that the last parameter is initialized while coalescing the
> results of the calls to make a decision after they are all evaluated.
>
> To make this clearer to the compiler, use the '|=' operator to assign
> the result of each touchscreen_get_prop_u32() call to data_present,
> which keeps the meaning of the code the same but makes it obvious that
> every one of these calls is expected to happen.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1472
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Thanks for the patch!
Reported-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>  drivers/input/touchscreen.c | 42 ++++++++++++++++++-------------------
>  1 file changed, 21 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/input/touchscreen.c b/drivers/input/touchscreen.c
> index dd18cb917c4d..4620e20d0190 100644
> --- a/drivers/input/touchscreen.c
> +++ b/drivers/input/touchscreen.c
> @@ -80,27 +80,27 @@ void touchscreen_parse_properties(struct input_dev *input, bool multitouch,
>
>         data_present = touchscreen_get_prop_u32(dev, "touchscreen-min-x",
>                                                 input_abs_get_min(input, axis_x),
> -                                               &minimum) |
> -                      touchscreen_get_prop_u32(dev, "touchscreen-size-x",
> -                                               input_abs_get_max(input,
> -                                                                 axis_x) + 1,
> -                                               &maximum) |
> -                      touchscreen_get_prop_u32(dev, "touchscreen-fuzz-x",
> -                                               input_abs_get_fuzz(input, axis_x),
> -                                               &fuzz);
> +                                               &minimum);
> +       data_present |= touchscreen_get_prop_u32(dev, "touchscreen-size-x",
> +                                                input_abs_get_max(input,
> +                                                                  axis_x) + 1,
> +                                                &maximum);
> +       data_present |= touchscreen_get_prop_u32(dev, "touchscreen-fuzz-x",
> +                                                input_abs_get_fuzz(input, axis_x),
> +                                                &fuzz);
>         if (data_present)
>                 touchscreen_set_params(input, axis_x, minimum, maximum - 1, fuzz);
>
>         data_present = touchscreen_get_prop_u32(dev, "touchscreen-min-y",
>                                                 input_abs_get_min(input, axis_y),
> -                                               &minimum) |
> -                      touchscreen_get_prop_u32(dev, "touchscreen-size-y",
> -                                               input_abs_get_max(input,
> -                                                                 axis_y) + 1,
> -                                               &maximum) |
> -                      touchscreen_get_prop_u32(dev, "touchscreen-fuzz-y",
> -                                               input_abs_get_fuzz(input, axis_y),
> -                                               &fuzz);
> +                                               &minimum);
> +       data_present |= touchscreen_get_prop_u32(dev, "touchscreen-size-y",
> +                                                input_abs_get_max(input,
> +                                                                  axis_y) + 1,
> +                                                &maximum);
> +       data_present |= touchscreen_get_prop_u32(dev, "touchscreen-fuzz-y",
> +                                                input_abs_get_fuzz(input, axis_y),
> +                                                &fuzz);
>         if (data_present)
>                 touchscreen_set_params(input, axis_y, minimum, maximum - 1, fuzz);
>
> @@ -108,11 +108,11 @@ void touchscreen_parse_properties(struct input_dev *input, bool multitouch,
>         data_present = touchscreen_get_prop_u32(dev,
>                                                 "touchscreen-max-pressure",
>                                                 input_abs_get_max(input, axis),
> -                                               &maximum) |
> -                      touchscreen_get_prop_u32(dev,
> -                                               "touchscreen-fuzz-pressure",
> -                                               input_abs_get_fuzz(input, axis),
> -                                               &fuzz);
> +                                               &maximum);
> +       data_present |= touchscreen_get_prop_u32(dev,
> +                                                "touchscreen-fuzz-pressure",
> +                                                input_abs_get_fuzz(input, axis),
> +                                                &fuzz);
>         if (data_present)
>                 touchscreen_set_params(input, axis, 0, maximum, fuzz);
>
>
> base-commit: a41392e0877a271007e9209e63c34cab7527eb43
> --
> 2.33.1.637.gf443b226ca
>
>


-- 
Thanks,
~Nick Desaulniers

      reply	other threads:[~2021-10-14 21:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-14 20:57 [PATCH] Input: touchscreen - Avoid bitwise vs logical OR warning Nathan Chancellor
2021-10-14 21:02 ` Nick Desaulniers [this message]

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=CAKwvOdm1W52TmoU5m-RokN+aZF7w4G0KUu0TcWyircWi63onsA@mail.gmail.com \
    --to=ndesaulniers@google.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.