diff options
author | Oleksij Rempel <o.rempel@pengutronix.de> | 2020-11-17 15:33:24 -0800 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2020-11-17 16:28:16 -0800 |
commit | 820830ec918f6c3dcd77a54a1c6198ab57407916 (patch) | |
tree | c9c02b7ed4df1010b0794fb2c5f6a60efe0d1638 /drivers/input/touchscreen | |
parent | 9c9509717b53e701469493a8d87ed42c7d782502 (diff) | |
download | linux-820830ec918f6c3dcd77a54a1c6198ab57407916.tar.gz linux-820830ec918f6c3dcd77a54a1c6198ab57407916.tar.bz2 linux-820830ec918f6c3dcd77a54a1c6198ab57407916.zip |
Input: ads7846 - fix integer overflow on Rt calculation
In some rare cases the 32 bit Rt value will overflow if z2 and x is max,
z1 is minimal value and x_plate_ohms is relatively high (for example 800
ohm). This would happen on some screen age with low pressure.
There are two possible fixes:
- make Rt 64bit
- reorder calculation to avoid overflow
The second variant seems to be preferable, since 64 bit calculation on
32 bit system is a bit more expensive.
Fixes: ffa458c1bd9b6f653008d450f337602f3d52a646 ("spi: ads7846 driver")
Co-developed-by: David Jander <david@protonic.nl>
Signed-off-by: David Jander <david@protonic.nl>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Link: https://lore.kernel.org/r/20201113112240.1360-1-o.rempel@pengutronix.de
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/touchscreen')
-rw-r--r-- | drivers/input/touchscreen/ads7846.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c index 95e89f675ad5..636b901c1374 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c @@ -802,10 +802,11 @@ static void ads7846_report_state(struct ads7846 *ts) /* compute touch pressure resistance using equation #2 */ Rt = z2; Rt -= z1; - Rt *= x; Rt *= ts->x_plate_ohms; + Rt = DIV_ROUND_CLOSEST(Rt, 16); + Rt *= x; Rt /= z1; - Rt = (Rt + 2047) >> 12; + Rt = DIV_ROUND_CLOSEST(Rt, 256); } else { Rt = 0; } |