Fix issue with integer overflow.

This commit is contained in:
littleguy77 2023-09-30 22:57:52 -04:00
parent 13bf681da2
commit fab07df97d

View file

@ -2652,7 +2652,7 @@ diff -rupN linux.orig/drivers/input/joystick/amlogic-saradc.h linux/drivers/inpu
diff -rupN linux.orig/drivers/input/joystick/odroid-gou-joypad.c linux/drivers/input/joystick/odroid-gou-joypad.c
--- linux.orig/drivers/input/joystick/odroid-gou-joypad.c 1970-01-01 00:00:00.000000000 +0000
+++ linux/drivers/input/joystick/odroid-gou-joypad.c 2023-09-12 12:03:27.490291628 +0000
@@ -0,0 +1,959 @@
@@ -0,0 +1,960 @@
+/*----------------------------------------------------------------------------*/
+#include <linux/kernel.h>
+#include <linux/module.h>
@ -3078,8 +3078,9 @@ diff -rupN linux.orig/drivers/input/joystick/odroid-gou-joypad.c linux/drivers/i
+ }
+ else {
+ /* Assumes adcx->max == -adcx->min == adcy->max == -adcy->min */
+ adcx->value = (adcx->max * adcx->value * (mag - joypad->bt_adc_deadzone)) / (mag * (adcx->max - joypad->bt_adc_deadzone));
+ adcy->value = (adcy->max * adcy->value * (mag - joypad->bt_adc_deadzone)) / (mag * (adcy->max - joypad->bt_adc_deadzone));
+ /* Order of operations is critical to avoid integer overflow */
+ adcx->value = (((adcx->max * adcx->value) / mag) * (mag - joypad->bt_adc_deadzone)) / (adcx->max - joypad->bt_adc_deadzone);
+ adcy->value = (((adcy->max * adcy->value) / mag) * (mag - joypad->bt_adc_deadzone)) / (adcy->max - joypad->bt_adc_deadzone);
+ }
+ }
+