[PATCH] input: abstract Xtst device lookup

Peter Hutterer peter.hutterer at who-t.net
Mon Jun 22 23:00:49 PDT 2009


The callers should need to use the dev privates key to look up xtest
devices.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
Acked-by: Benjamin Close <Benjamin.Close at clearchain.com>
---
This is patch1 to address the crashes when an xtest device is floating.

 Xi/xichangehierarchy.c |   28 +++++-----------------------
 dix/devices.c          |   13 +++++++++++++
 include/input.h        |    1 +
 3 files changed, 19 insertions(+), 23 deletions(-)

diff --git a/Xi/xichangehierarchy.c b/Xi/xichangehierarchy.c
index 5401554..a1dfcb2 100644
--- a/Xi/xichangehierarchy.c
+++ b/Xi/xichangehierarchy.c
@@ -54,8 +54,6 @@
 
 #include "xichangehierarchy.h"
 
-extern DevPrivateKey XTstDevicePrivateKey;
-
 /**
  * Send the current state of the device hierarchy to all clients.
  */
@@ -260,8 +258,7 @@ ProcXIChangeHierarchy(ClientPtr client)
                     }
 
                     for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
-                        if( !IsMaster(xtstdevice) && xtstdevice->u.master == ptr &&
-                            dixLookupPrivate(&xtstdevice->devPrivates, XTstDevicePrivateKey ))
+                        if (IsXtstDevice(xtstdevice, ptr))
                             break;
 
                     rc = dixLookupDevice(&xtstptr, xtstdevice->id, client,
@@ -297,10 +294,7 @@ ProcXIChangeHierarchy(ClientPtr client)
                     {
                         /* Search the matching keyboard */
                         for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
-                            if( !IsMaster(xtstdevice) &&
-                                xtstdevice->u.master == keybd &&
-                                IsKeyboardDevice(xtstdevice) &&
-                                dixLookupPrivate(&xtstdevice->devPrivates, XTstDevicePrivateKey ))
+                            if(IsKeyboardDevice(xtstdevice) && IsXtstDevice(xtstdevice, keybd))
                                 break;
 
                         rc = dixLookupDevice(&xtstkeybd,
@@ -316,11 +310,7 @@ ProcXIChangeHierarchy(ClientPtr client)
                         xtstkeybd = xtstptr;
                         /* Search the matching pointer */
                         for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
-                            if( !IsMaster(xtstdevice) &&
-                                xtstdevice->u.master == ptr &&
-                                IsPointerDevice(xtstdevice) &&
-                                dixLookupPrivate(&xtstdevice->devPrivates, XTstDevicePrivateKey )
-                              )
+                            if(IsPointerDevice(xtstdevice) && IsXtstDevice(xtstdevice, ptr))
                                 break;
                         rc = dixLookupDevice(&xtstptr,
                                              xtstdevice->id,
@@ -412,7 +402,6 @@ ProcXIChangeHierarchy(ClientPtr client)
             case XIDetachSlave:
                 {
                     xXIDetachSlaveInfo* c = (xXIDetachSlaveInfo*)any;
-                    DeviceIntPtr *xtstdevice;
 
                     rc = dixLookupDevice(&ptr, c->deviceid, client,
                                           DixWriteAccess);
@@ -426,11 +415,8 @@ ProcXIChangeHierarchy(ClientPtr client)
                         goto unwind;
                     }
 
-                    xtstdevice = dixLookupPrivate( &ptr->devPrivates,
-                                                   XTstDevicePrivateKey );
-
                     /* Don't allow changes to Xtst Devices, these are fixed */
-                    if( xtstdevice )
+                    if (IsXtstDevice(ptr, NULL))
                     {
                         client->errorValue = c->deviceid;
                         rc = BadDevice;
@@ -445,7 +431,6 @@ ProcXIChangeHierarchy(ClientPtr client)
                 {
                     xXIAttachSlaveInfo* c = (xXIAttachSlaveInfo*)any;
                     DeviceIntPtr newmaster;
-                    DeviceIntPtr *xtstdevice;
 
                     rc = dixLookupDevice(&ptr, c->deviceid, client,
                                           DixWriteAccess);
@@ -459,11 +444,8 @@ ProcXIChangeHierarchy(ClientPtr client)
                         goto unwind;
                     }
 
-                    xtstdevice = dixLookupPrivate( &ptr->devPrivates,
-                                                   XTstDevicePrivateKey );
-
                     /* Don't allow changes to Xtst Devices, these are fixed */
-                    if( xtstdevice )
+                    if (IsXtstDevice(ptr, NULL))
                     {
                         client->errorValue = c->deviceid;
                         rc = BadDevice;
diff --git a/dix/devices.c b/dix/devices.c
index b237e03..2d77657 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -2589,3 +2589,16 @@ int AllocXtstDevice (ClientPtr client, char* name,
 
     return retval;
 }
+
+/**
+ * If master is NULL, return TRUE if the given device is an xtest device or
+ * FALSE otherwise.
+ * If master is not NULL, return TRUE if the given device is this master's
+ * xtest device.
+ */
+BOOL
+IsXtstDevice(DeviceIntPtr dev, DeviceIntPtr master)
+{
+    return (!IsMaster(dev) && (!master || dev->u.master == master) &&
+           ( dixLookupPrivate(&dev->devPrivates, XTstDevicePrivateKey) != NULL));
+}
diff --git a/include/input.h b/include/input.h
index 9711fa8..1dfbbff 100644
--- a/include/input.h
+++ b/include/input.h
@@ -497,6 +497,7 @@ extern int AllocXtstDevice(ClientPtr client,
                              char* name,
                              DeviceIntPtr* ptr,
                              DeviceIntPtr* keybd);
+extern BOOL IsXtstDevice(DeviceIntPtr dev, DeviceIntPtr master);
 
 /* misc event helpers */
 extern Mask GetEventFilter(DeviceIntPtr dev, xEvent *event);
-- 
1.6.3.rc1.2.g0164.dirty



More information about the xorg-devel mailing list