mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 03:01:39 -04:00
Input: ads7846 - fix integer overflow on Rt calculation
[ Upstream commit 820830ec918f6c3dcd77a54a1c6198ab57407916 ]
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: ffa458c1bd ("spi: ads7846 driver")
Co-developed-by: David Jander <[email protected]>
Signed-off-by: David Jander <[email protected]>
Signed-off-by: Oleksij Rempel <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Dmitry Torokhov <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
This commit is contained in:
parent
c7ac509273
commit
920c379029
1 changed files with 3 additions and 2 deletions
|
|
@ -801,10 +801,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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue