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

Input: resistive-adc-touch - fix uninitialized variable 'press'

In the case where st->ch_map[GRTS_CH_PRESSURE] < GRTS_MAX_CHANNELS is false
and also st->ch_map[GRTS_CH_Z1] < GRTS_MAX_CHANNELS is false the variable
press is not initialized and contains garbage. In this situation
st->pressure is also false, so we do not actually use press value, but
it is impossible for the compiler to realize this, and it emits
"uninitialized variable" warning. Fix this by initializing press
to 0 and allows us to also remove an else clause that sets press to 0.

Addresses-Coverity: ("Uninitialized scalar variable")
Fixes: 60b7db914ddd ("Input: resistive-adc-touch - rework mapping of channels")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Link: https://lore.kernel.org/r/20210603220809.155118-1-colin.king@canonical.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Colin Ian King and committed by
Dmitry Torokhov
6cdc1ef8 2fcbda9a

+1 -3
+1 -3
drivers/input/touchscreen/resistive-adc-touch.c
··· 59 59 { 60 60 const u16 *touch_info = data; 61 61 struct grts_state *st = private; 62 - unsigned int x, y, press; 62 + unsigned int x, y, press = 0; 63 63 64 64 x = touch_info[st->ch_map[GRTS_CH_X]]; 65 65 y = touch_info[st->ch_map[GRTS_CH_Y]]; ··· 84 84 */ 85 85 if (Rt < GRTS_DEFAULT_PRESSURE_MAX) 86 86 press = GRTS_DEFAULT_PRESSURE_MAX - Rt; 87 - else 88 - press = 0; 89 87 } 90 88 91 89 if ((!x && !y) || (st->pressure && (press < st->pressure_min))) {