diff mbox

[1/1] Input: joydev - fix axes values sent in initial js_event

Message ID 1344895914-32127-1-git-send-email-vbocek@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Vojtech Bocek Aug. 13, 2012, 10:11 p.m. UTC
Initial input event has not yet arrived in joydev_connect()
where values are set, which means default values of input_absinfo
are used for init event, not the actual values from joystick.

Signed-off-by: Vojtech Bocek <vbocek@gmail.com>
---
 drivers/input/joydev.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Dmitry Torokhov Sept. 5, 2012, 5:52 a.m. UTC | #1
Hi Vojtech,

On Tue, Aug 14, 2012 at 12:11:54AM +0200, Vojtech Bocek wrote:
> Initial input event has not yet arrived in joydev_connect()
> where values are set, which means default values of input_absinfo
> are used for init event, not the actual values from joystick.

So what guarantees that joystick events will arrive in time, before
joydev_generate_startup_event() is called? It looks like your solution
is racy...

I wonder if we should not generate the startup event until we have seen
at least one EV_SYN, i.e. entire device state has been transmitted to
us.
> 
> Signed-off-by: Vojtech Bocek <vbocek@gmail.com>
> ---
>  drivers/input/joydev.c |    9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
> index 26043cc..11f24b4 100644
> --- a/drivers/input/joydev.c
> +++ b/drivers/input/joydev.c
> @@ -318,9 +318,14 @@ static int joydev_generate_startup_event(struct joydev_client *client,
>  			event->value = !!test_bit(joydev->keypam[event->number],
>  						  input->key);
>  		} else {
> +			int evnum = client->startup - joydev->nkey;
> +			int val = input_abs_get_val(input, joydev->abspam[evnum]);
> +
> +			joydev->abs[evnum] = joydev_correct(val, &joydev->corr[evnum]);
> +
>  			event->type = JS_EVENT_AXIS | JS_EVENT_INIT;
> -			event->number = client->startup - joydev->nkey;
> -			event->value = joydev->abs[event->number];
> +			event->number = evnum;
> +			event->value = joydev->abs[evnum];
>  		}
>  		client->startup++;
>  	}
> -- 
> 1.7.10.4
> 

Thanks.
diff mbox

Patch

diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index 26043cc..11f24b4 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -318,9 +318,14 @@  static int joydev_generate_startup_event(struct joydev_client *client,
 			event->value = !!test_bit(joydev->keypam[event->number],
 						  input->key);
 		} else {
+			int evnum = client->startup - joydev->nkey;
+			int val = input_abs_get_val(input, joydev->abspam[evnum]);
+
+			joydev->abs[evnum] = joydev_correct(val, &joydev->corr[evnum]);
+
 			event->type = JS_EVENT_AXIS | JS_EVENT_INIT;
-			event->number = client->startup - joydev->nkey;
-			event->value = joydev->abs[event->number];
+			event->number = evnum;
+			event->value = joydev->abs[evnum];
 		}
 		client->startup++;
 	}