[PATCH] Add a "flags" field to DeleteInputDeviceRequest.

Peter Hutterer peter.hutterer at who-t.net
Thu May 20 01:07:12 PDT 2010


Some input drivers need to implement an internal hotplugging scheme for
dependent devices to provide multiple X devices off one kernel device file.
Such dependent devices can be added with NewInputDeviceRequest() but they are
not removed when the config backend calls DeleteInputDeviceRequest(),
leaving the original device to clean up.

Example of the wacom driver:

config/udev calls NewInputDeviceRequest("stylus")

wacom PreInit calls
        NewInputDeviceRequest("eraser")
        NewInputDeviceRequest("pad")
        NewInputDeviceRequest("cursor")
        PreInit finishes.

When the device is removed, the config backend only calls
DeleteInputDeviceRequest for "stylus". The driver needs to call
DeleteInputDeviceRequest for the dependent devices eraser, pad and cursor to
clean up properly.
However, when the server terminates, DeleteInputDeviceRequest is called for
all devices - the driver must not remove the dependent devices to avoid
double-frees. There is no method for the driver to detect why a device is
being removed, leading to elaborate guesswork and some amount of wishful
thinking.

Though the input driver's UnInit already supports flags, they are unused.
This patch uses the flags to supply information where the
DeleteInputDeviceRequest request originates from, allowing a driver to
selectively call DeleteInputDeviceRequest when necessary.

Also bumps XINPUT ABI.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
For extra fun, look at the wacom source code to see how we're working around
this now. It depends on the device order, not pretty...

Keith, don't take this patch please. I'd like to have it in my tree to keep
the ABI/API breakers close together for future bisecting.

 Xi/stubs.c                     |    2 +-
 config/config.c                |    2 +-
 config/dbus.c                  |    2 +-
 dix/devices.c                  |    2 +-
 hw/dmx/dmxinput.c              |    2 +-
 hw/kdrive/linux/evdev.c        |    4 ++--
 hw/xfree86/common/xf86Module.h |    2 +-
 hw/xfree86/common/xf86Xinput.c |    8 ++++----
 hw/xquartz/darwinXinput.c      |    2 +-
 include/input.h                |    6 +++++-
 10 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/Xi/stubs.c b/Xi/stubs.c
index 04ba976..8285549 100644
--- a/Xi/stubs.c
+++ b/Xi/stubs.c
@@ -241,6 +241,6 @@ NewInputDeviceRequest(InputOption *options, InputAttributes *attrs,
  *
  */
 void
-DeleteInputDeviceRequest(DeviceIntPtr dev)
+DeleteInputDeviceRequest(DeviceIntPtr dev, int flags)
 {
 }
diff --git a/config/config.c b/config/config.c
index 65ef679..f49420d 100644
--- a/config/config.c
+++ b/config/config.c
@@ -81,7 +81,7 @@ remove_device(const char *backend, DeviceIntPtr dev)
      * already been removed. */
     OsBlockSignals();
     ProcessInputEvents();
-    DeleteInputDeviceRequest(dev);
+    DeleteInputDeviceRequest(dev, 0);
     OsReleaseSignals();
 }
 
diff --git a/config/dbus.c b/config/dbus.c
index 72a0a05..511908a 100644
--- a/config/dbus.c
+++ b/config/dbus.c
@@ -226,7 +226,7 @@ remove_device(DBusMessage *message, DBusMessage *reply, DBusError *error)
      * already been removed. */
     OsBlockSignals();
     ProcessInputEvents();
-    DeleteInputDeviceRequest(dev);
+    DeleteInputDeviceRequest(dev, 0);
     OsReleaseSignals();
 
     ret = Success;
diff --git a/dix/devices.c b/dix/devices.c
index 57b7a9b..6f7c584 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -957,7 +957,7 @@ CloseDeviceList(DeviceIntPtr *listHead)
     while (dev != NULL)
     {
         freedIds[dev->id] = TRUE;
-        DeleteInputDeviceRequest(dev);
+        DeleteInputDeviceRequest(dev, DEVICE_REMOVE_ALL);
 
         dev = *listHead;
         while (dev != NULL && freedIds[dev->id])
diff --git a/hw/dmx/dmxinput.c b/hw/dmx/dmxinput.c
index 568bb88..eceb251 100644
--- a/hw/dmx/dmxinput.c
+++ b/hw/dmx/dmxinput.c
@@ -114,6 +114,6 @@ NewInputDeviceRequest (InputOption *options, InputAttributes *attrs,
 }
 
 void
-DeleteInputDeviceRequest(DeviceIntPtr pDev)
+DeleteInputDeviceRequest(DeviceIntPtr pDev, int flags)
 {
 }
diff --git a/hw/kdrive/linux/evdev.c b/hw/kdrive/linux/evdev.c
index 3797f09..cb16176 100644
--- a/hw/kdrive/linux/evdev.c
+++ b/hw/kdrive/linux/evdev.c
@@ -165,7 +165,7 @@ EvdevPtrRead (int evdevPort, void *closure)
     n = read (evdevPort, &events, NUM_EVENTS * sizeof (struct input_event));
     if (n <= 0) {
         if (errno == ENODEV)
-            DeleteInputDeviceRequest(pi->dixdev);
+            DeleteInputDeviceRequest(pi->dixdev, 0);
         return;
     }
 
@@ -375,7 +375,7 @@ EvdevKbdRead (int evdevPort, void *closure)
     n = read (evdevPort, &events, NUM_EVENTS * sizeof (struct input_event));
     if (n <= 0) {
         if (errno == ENODEV)
-            DeleteInputDeviceRequest(ki->dixdev);
+            DeleteInputDeviceRequest(ki->dixdev, 0);
         return;
     }
 
diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index d61758f..51b9b16 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -83,7 +83,7 @@ typedef enum {
  */
 #define ABI_ANSIC_VERSION	SET_ABI_VERSION(0, 4)
 #define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(8, 0)
-#define ABI_XINPUT_VERSION	SET_ABI_VERSION(10, 0)
+#define ABI_XINPUT_VERSION	SET_ABI_VERSION(11, 0)
 #define ABI_EXTENSION_VERSION	SET_ABI_VERSION(4, 0)
 #define ABI_FONT_VERSION	SET_ABI_VERSION(0, 6)
 
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index ac287aa..9374b08 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -853,7 +853,7 @@ unwind:
 }
 
 void
-DeleteInputDeviceRequest(DeviceIntPtr pDev)
+DeleteInputDeviceRequest(DeviceIntPtr pDev, int flags)
 {
     LocalDevicePtr pInfo = (LocalDevicePtr) pDev->public.devicePrivate;
     InputDriverPtr drv = NULL;
@@ -873,9 +873,9 @@ DeleteInputDeviceRequest(DeviceIntPtr pDev)
     if (!isMaster && pInfo != NULL)
     {
         if(drv->UnInit)
-            drv->UnInit(drv, pInfo, 0);
+            drv->UnInit(drv, pInfo, flags);
         else
-            xf86DeleteInput(pInfo, 0);
+            xf86DeleteInput(pInfo, flags);
 
         /* devices added through HAL aren't in the config layout */
         it = xf86ConfigLayout.inputs;
@@ -1266,7 +1266,7 @@ xf86DisableDevice(DeviceIntPtr dev, Bool panic)
     } else
     {
         SendDevicePresenceEvent(dev->id, DeviceUnrecoverable);
-        DeleteInputDeviceRequest(dev);
+        DeleteInputDeviceRequest(dev, 0);
     }
 }
 
diff --git a/hw/xquartz/darwinXinput.c b/hw/xquartz/darwinXinput.c
index 90e440e..59ca627 100644
--- a/hw/xquartz/darwinXinput.c
+++ b/hw/xquartz/darwinXinput.c
@@ -245,7 +245,7 @@ NewInputDeviceRequest(InputOption *options, InputAttributes *attrs,
  *
  */
 void
-DeleteInputDeviceRequest(DeviceIntPtr dev)
+DeleteInputDeviceRequest(DeviceIntPtr dev, int flags)
 {
   DEBUG_LOG("DeleteInputDeviceRequest(%p)\n", dev);
 }
diff --git a/include/input.h b/include/input.h
index 63f981e..0f7c215 100644
--- a/include/input.h
+++ b/include/input.h
@@ -62,6 +62,9 @@ SOFTWARE.
 #define DEVICE_OFF	2
 #define DEVICE_CLOSE	3
 
+/* DeleteInputDeviceRequest flags */
+#define DEVICE_REMOVE_ALL    (1 << 0) /* all devices will be removed */
+
 #define POINTER_RELATIVE (1 << 1)
 #define POINTER_ABSOLUTE (1 << 2)
 #define POINTER_ACCELERATE (1 << 3)
@@ -534,7 +537,8 @@ extern _X_EXPORT int NewInputDeviceRequest(
     InputAttributes *attrs,
     DeviceIntPtr *dev);
 extern  _X_EXPORT void DeleteInputDeviceRequest(
-    DeviceIntPtr dev);
+    DeviceIntPtr dev,
+    int flags);
 
 extern _X_EXPORT void DDXRingBell(
     int volume,
-- 
1.7.0.1


More information about the xorg-devel mailing list