* [PATCH][next] Input: resistive-adc-touch: Fix uninitialized variable 'press'
@ 2021-06-03 22:08 Colin King
2021-06-05 23:19 ` Dmitry Torokhov
0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2021-06-03 22:08 UTC (permalink / raw)
To: Eugen Hristev, Dmitry Torokhov, linux-input; +Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
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. This affects a later
comparison of press < st->pressure_min. 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>
---
drivers/input/touchscreen/resistive-adc-touch.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/input/touchscreen/resistive-adc-touch.c b/drivers/input/touchscreen/resistive-adc-touch.c
index ea7dd9d2b2ac..744544a723b7 100644
--- a/drivers/input/touchscreen/resistive-adc-touch.c
+++ b/drivers/input/touchscreen/resistive-adc-touch.c
@@ -59,7 +59,7 @@ static int grts_cb(const void *data, void *private)
{
const u16 *touch_info = data;
struct grts_state *st = private;
- unsigned int x, y, press;
+ unsigned int x, y, press = 0;
x = touch_info[st->ch_map[GRTS_CH_X]];
y = touch_info[st->ch_map[GRTS_CH_Y]];
@@ -84,8 +84,6 @@ static int grts_cb(const void *data, void *private)
*/
if (Rt < GRTS_DEFAULT_PRESSURE_MAX)
press = GRTS_DEFAULT_PRESSURE_MAX - Rt;
- else
- press = 0;
}
if ((!x && !y) || (st->pressure && (press < st->pressure_min))) {
--
2.31.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH][next] Input: resistive-adc-touch: Fix uninitialized variable 'press'
2021-06-03 22:08 [PATCH][next] Input: resistive-adc-touch: Fix uninitialized variable 'press' Colin King
@ 2021-06-05 23:19 ` Dmitry Torokhov
0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Torokhov @ 2021-06-05 23:19 UTC (permalink / raw)
To: Colin King; +Cc: Eugen Hristev, linux-input, kernel-janitors, linux-kernel
Hi Colin,
On Thu, Jun 03, 2021 at 11:08:09PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> 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. This affects a later
> comparison of press < st->pressure_min.
If neither of the conditions is true, then st->pressure is also false,
and we will not be evaluating condition involving "press". However it is
impossible for the compiler/Coverity to figure this out, so I'll apply
the patch adjusting the description a bit.
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-06-05 23:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-03 22:08 [PATCH][next] Input: resistive-adc-touch: Fix uninitialized variable 'press' Colin King
2021-06-05 23:19 ` Dmitry Torokhov
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.