Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: touchscreen - avoid bitwise vs logical OR warning

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.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reported-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Link: https://lore.kernel.org/r/20211014205757.3474635-1-nathan@kernel.org
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Nathan Chancellor and committed by
Dmitry Torokhov
a02dcde5 3378a07d

+21 -21
+21 -21
drivers/input/touchscreen.c
··· 80 80 81 81 data_present = touchscreen_get_prop_u32(dev, "touchscreen-min-x", 82 82 input_abs_get_min(input, axis_x), 83 - &minimum) | 84 - touchscreen_get_prop_u32(dev, "touchscreen-size-x", 85 - input_abs_get_max(input, 86 - axis_x) + 1, 87 - &maximum) | 88 - touchscreen_get_prop_u32(dev, "touchscreen-fuzz-x", 89 - input_abs_get_fuzz(input, axis_x), 90 - &fuzz); 83 + &minimum); 84 + data_present |= touchscreen_get_prop_u32(dev, "touchscreen-size-x", 85 + input_abs_get_max(input, 86 + axis_x) + 1, 87 + &maximum); 88 + data_present |= touchscreen_get_prop_u32(dev, "touchscreen-fuzz-x", 89 + input_abs_get_fuzz(input, axis_x), 90 + &fuzz); 91 91 if (data_present) 92 92 touchscreen_set_params(input, axis_x, minimum, maximum - 1, fuzz); 93 93 94 94 data_present = touchscreen_get_prop_u32(dev, "touchscreen-min-y", 95 95 input_abs_get_min(input, axis_y), 96 - &minimum) | 97 - touchscreen_get_prop_u32(dev, "touchscreen-size-y", 98 - input_abs_get_max(input, 99 - axis_y) + 1, 100 - &maximum) | 101 - touchscreen_get_prop_u32(dev, "touchscreen-fuzz-y", 102 - input_abs_get_fuzz(input, axis_y), 103 - &fuzz); 96 + &minimum); 97 + data_present |= touchscreen_get_prop_u32(dev, "touchscreen-size-y", 98 + input_abs_get_max(input, 99 + axis_y) + 1, 100 + &maximum); 101 + data_present |= touchscreen_get_prop_u32(dev, "touchscreen-fuzz-y", 102 + input_abs_get_fuzz(input, axis_y), 103 + &fuzz); 104 104 if (data_present) 105 105 touchscreen_set_params(input, axis_y, minimum, maximum - 1, fuzz); 106 106 ··· 108 108 data_present = touchscreen_get_prop_u32(dev, 109 109 "touchscreen-max-pressure", 110 110 input_abs_get_max(input, axis), 111 - &maximum) | 112 - touchscreen_get_prop_u32(dev, 113 - "touchscreen-fuzz-pressure", 114 - input_abs_get_fuzz(input, axis), 115 - &fuzz); 111 + &maximum); 112 + data_present |= touchscreen_get_prop_u32(dev, 113 + "touchscreen-fuzz-pressure", 114 + input_abs_get_fuzz(input, axis), 115 + &fuzz); 116 116 if (data_present) 117 117 touchscreen_set_params(input, axis, 0, maximum, fuzz); 118 118