Commit fe0a7e3d authored by Oleksij Rempel's avatar Oleksij Rempel Committed by Dmitry Torokhov

Input: resistive-adc-touch - fix division by zero error on z1 == 0

For proper pressure calculation we need at least x and z1 to be non
zero. Even worse, in case z1 we may run in to division by zero
error.

Fixes: 60b7db91 ("Input: resistive-adc-touch - rework mapping of channels")
Signed-off-by: default avatarOleksij Rempel <o.rempel@pengutronix.de>
Link: https://lore.kernel.org/r/20211007095727.29579-1-o.rempel@pengutronix.deSigned-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent d997cc17
...@@ -71,6 +71,7 @@ static int grts_cb(const void *data, void *private) ...@@ -71,6 +71,7 @@ static int grts_cb(const void *data, void *private)
unsigned int z2 = touch_info[st->ch_map[GRTS_CH_Z2]]; unsigned int z2 = touch_info[st->ch_map[GRTS_CH_Z2]];
unsigned int Rt; unsigned int Rt;
if (likely(x && z1)) {
Rt = z2; Rt = z2;
Rt -= z1; Rt -= z1;
Rt *= st->x_plate_ohms; Rt *= st->x_plate_ohms;
...@@ -79,12 +80,14 @@ static int grts_cb(const void *data, void *private) ...@@ -79,12 +80,14 @@ static int grts_cb(const void *data, void *private)
Rt /= z1; Rt /= z1;
Rt = DIV_ROUND_CLOSEST(Rt, 256); Rt = DIV_ROUND_CLOSEST(Rt, 256);
/* /*
* On increased pressure the resistance (Rt) is decreasing * On increased pressure the resistance (Rt) is
* so, convert values to make it looks as real pressure. * decreasing so, convert values to make it looks as
* real pressure.
*/ */
if (Rt < GRTS_DEFAULT_PRESSURE_MAX) if (Rt < GRTS_DEFAULT_PRESSURE_MAX)
press = GRTS_DEFAULT_PRESSURE_MAX - Rt; press = GRTS_DEFAULT_PRESSURE_MAX - Rt;
} }
}
if ((!x && !y) || (st->pressure && (press < st->pressure_min))) { if ((!x && !y) || (st->pressure && (press < st->pressure_min))) {
/* report end of touch */ /* report end of touch */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment