Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: joydev - do not report stale values on first open

Postpone axis initialization to the first open instead of doing it
in joydev_connect. This is to make sure the generated startup events
are representative of the current joystick state rather than what
it was when joydev_connect() was called, potentially much earlier.
Once the first user is connected to joydev node we'll be updating
joydev->abs[] values and subsequent clients will be getting correct
initial states as well.

This solves issues with joystick driven menus that start scrolling
up each time they are started, until the user moves the joystick to
generate events. In emulator menu setups where the menu program is
restarted every time the game exits, the repeated need to move the
joystick to stop the unintended scrolling gets old rather quickly...

Signed-off-by: Raphael Assenat <raph@raphnet.net>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Raphael Assenat and committed by
Dmitry Torokhov
45536d37 81dec809

+13 -5
+13 -5
drivers/input/joydev.c
··· 187 187 synchronize_rcu(); 188 188 } 189 189 190 + static void joydev_refresh_state(struct joydev *joydev) 191 + { 192 + struct input_dev *dev = joydev->handle.dev; 193 + int i, val; 194 + 195 + for (i = 0; i < joydev->nabs; i++) { 196 + val = input_abs_get_val(dev, joydev->abspam[i]); 197 + joydev->abs[i] = joydev_correct(val, &joydev->corr[i]); 198 + } 199 + } 200 + 190 201 static int joydev_open_device(struct joydev *joydev) 191 202 { 192 203 int retval; ··· 212 201 retval = input_open_device(&joydev->handle); 213 202 if (retval) 214 203 joydev->open--; 204 + else 205 + joydev_refresh_state(joydev); 215 206 } 216 207 217 208 mutex_unlock(&joydev->mutex); ··· 885 872 j = joydev->abspam[i]; 886 873 if (input_abs_get_max(dev, j) == input_abs_get_min(dev, j)) { 887 874 joydev->corr[i].type = JS_CORR_NONE; 888 - joydev->abs[i] = input_abs_get_val(dev, j); 889 875 continue; 890 876 } 891 877 joydev->corr[i].type = JS_CORR_BROKEN; ··· 899 887 if (t) { 900 888 joydev->corr[i].coef[2] = (1 << 29) / t; 901 889 joydev->corr[i].coef[3] = (1 << 29) / t; 902 - 903 - joydev->abs[i] = 904 - joydev_correct(input_abs_get_val(dev, j), 905 - joydev->corr + i); 906 890 } 907 891 } 908 892