Input: fix open count handling in input interfaces
If input_open_device() fails we should not leave interfaces marked
as opened.
Signed-off-by: Oliver Neukum <oneukum@suse.de>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index bfee4f9..d404aa8 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -192,8 +192,11 @@
if (!evdev->exist)
retval = -ENODEV;
- else if (!evdev->open++)
+ else if (!evdev->open++) {
retval = input_open_device(&evdev->handle);
+ if (retval)
+ evdev->open--;
+ }
mutex_unlock(&evdev->mutex);
return retval;
diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index a4272d6..f306c97 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -205,8 +205,11 @@
if (!joydev->exist)
retval = -ENODEV;
- else if (!joydev->open++)
+ else if (!joydev->open++) {
retval = input_open_device(&joydev->handle);
+ if (retval)
+ joydev->open--;
+ }
mutex_unlock(&joydev->mutex);
return retval;
diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index 715def7..cc36edb 100644
--- a/drivers/input/mousedev.c
+++ b/drivers/input/mousedev.c
@@ -428,8 +428,11 @@
mixdev_open_devices();
else if (!mousedev->exist)
retval = -ENODEV;
- else if (!mousedev->open++)
+ else if (!mousedev->open++) {
retval = input_open_device(&mousedev->handle);
+ if (retval)
+ mousedev->open--;
+ }
mutex_unlock(&mousedev->mutex);
return retval;
diff --git a/drivers/input/tsdev.c b/drivers/input/tsdev.c
index c189f1d..1202334 100644
--- a/drivers/input/tsdev.c
+++ b/drivers/input/tsdev.c
@@ -185,8 +185,11 @@
if (!tsdev->exist)
retval = -ENODEV;
- else if (!tsdev->open++)
+ else if (!tsdev->open++) {
retval = input_open_device(&tsdev->handle);
+ if (retval)
+ tsdev->open--;
+ }
mutex_unlock(&tsdev->mutex);
return retval;