xserver: Branch 'master' - 11 commits

Keith Packard keithp at kemper.freedesktop.org
Wed Nov 10 16:59:42 PST 2010


 Xi/xichangehierarchy.c               |  522 ++++++++++++++++++-----------------
 config/x11-input.fdi                 |    5 
 dix/grabs.c                          |    7 
 dix/ptrveloc.c                       |    8 
 glx/glxdri.c                         |    4 
 glx/glxdri2.c                        |    4 
 glx/single2.c                        |    7 
 hw/dmx/glxProxy/glxcmds.c            |    2 
 hw/dmx/glxProxy/glxext.c             |   18 -
 hw/kdrive/fake/fake.c                |    7 
 hw/xfree86/common/xf86Config.c       |   11 
 hw/xfree86/doc/man/xorg.conf.man.pre |    9 
 hw/xfree86/modes/xf86Crtc.c          |    3 
 hw/xwin/glx/indirect.c               |    5 
 hw/xwin/wincmap.c                    |    7 
 hw/xwin/winpixmap.c                  |    7 
 mi/mispans.c                         |    2 
 miext/rootless/rootlessScreen.c      |    3 
 miext/rootless/rootlessWindow.c      |    6 
 os/log.c                             |    6 
 os/strlcat.c                         |    4 
 os/strlcpy.c                         |    4 
 render/miindex.c                     |   14 
 render/picture.c                     |    7 
 xkb/XKBAlloc.c                       |    6 
 xkb/XKBGAlloc.c                      |   30 --
 xkb/XKBMAlloc.c                      |   40 --
 xkb/ddxLoad.c                        |    6 
 28 files changed, 355 insertions(+), 399 deletions(-)

New commits:
commit 4ed4915bc0fbe9b4419ca4a0d4e43c2fee032ae9
Merge: 291c39d... ec1bfbc...
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Nov 10 16:58:21 2010 -0800

    Merge remote branch 'whot/for-keith'

commit ec1bfbc66926130e1153facc3b92ee175f1cb6b6
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Nov 9 15:27:26 2010 +1000

    xfree86: remove user-configured AllowEmptyInput
    
    An estimated 100% (rounded down to the nearest percent) of the people who
    have this in their configuration don't actually know what this option does.
    Protect the users from themselves.
    
    IIRC, AEI on was useful for some time between 1.4 and 1.5 and never since.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Dan Nicholson <dbn.lists at gmail.com>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index e3b2831..88e2e8d 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -742,8 +742,6 @@ static OptionInfoRec FlagOptions[] = {
 	{0}, FALSE },
   { FLAG_AIGLX,			"AIGLX",			OPTV_BOOLEAN,
 	{0}, FALSE },
-  { FLAG_ALLOW_EMPTY_INPUT,     "AllowEmptyInput",              OPTV_BOOLEAN,
-        {0}, FALSE },
   { FLAG_IGNORE_ABI,		"IgnoreABI",			OPTV_BOOLEAN,
 	{0}, FALSE },
   { FLAG_USE_DEFAULT_FONT_PATH,  "UseDefaultFontPath",		OPTV_BOOLEAN,
@@ -956,7 +954,6 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
 
     /* AllowEmptyInput is automatically true if we're hotplugging */
     xf86Info.allowEmptyInput = (xf86Info.autoAddDevices && xf86Info.autoEnableDevices);
-    xf86GetOptValBool(FlagOptions, FLAG_ALLOW_EMPTY_INPUT, &xf86Info.allowEmptyInput);
 
     /* AEI on? Then we're not using kbd, so use the evdev rules set. */
 #if defined(linux)
@@ -1437,8 +1434,10 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 	                "reconfigure %s or disable AutoAddDevices.\n",
 			config_backend, config_backend);
 #else
-	xf86Msg(X_INFO, "Hotplugging is disabled and no input devices were configured.\n"
-			"\tTry disabling AllowEmptyInput.\n");
+	xf86Msg(X_WARNING, "Hotplugging requested but the server was "
+			   "compiled without a config backend. "
+			   "No input devices were configured, the server "
+			   "will start without any input devices.\n");
 #endif
     }
 
@@ -2353,7 +2352,7 @@ checkInput(serverLayoutPtr layout, Bool implicit_layout) {
                 IDevPtr *current;
                 if (!warned)
                 {
-                    xf86Msg(X_WARNING, "AllowEmptyInput is on, devices using "
+                    xf86Msg(X_WARNING, "Hotplugging is on, devices using "
                             "drivers 'kbd', 'mouse' or 'vmmouse' will be disabled.\n");
                     warned = TRUE;
                 }
diff --git a/hw/xfree86/doc/man/xorg.conf.man.pre b/hw/xfree86/doc/man/xorg.conf.man.pre
index cbfea7d..a7259fb 100644
--- a/hw/xfree86/doc/man/xorg.conf.man.pre
+++ b/hw/xfree86/doc/man/xorg.conf.man.pre
@@ -558,9 +558,6 @@ Default: off.
 This tells the mousedrv(__drivermansuffix__) and vmmouse(__drivermansuffix__)
 drivers to not report failure if the mouse device can't be opened/initialised.
 It has no effect on the evdev(__drivermansuffix__) or other drivers.
-The previous functionality of allowing the server to start up even if
-the mouse device can't be opened/initialised is now handled by the
-AllowEmptyInput option.
 Default: false.
 .TP 7
 .BI "Option \*qVTSysReq\*q  \*q" boolean \*q
@@ -677,12 +674,6 @@ default.
 Allow modules built for a different, potentially incompatible version of
 the X server to load. Disabled by default.
 .TP 7
-.BI "Option \*qAllowEmptyInput\*q \*q" boolean \*q
-If enabled, don't add the standard keyboard and mouse drivers, if there are no
-input devices in the config file.  Enabled by default if AutoAddDevices and
-AutoEnableDevices is enabled, otherwise disabled.
-If AllowEmptyInput is on, devices using the kbd, mouse or vmmouse driver are ignored.
-.TP 7
 .BI "Option \*qAutoAddDevices\*q \*q" boolean \*q
 If this option is disabled, then no devices will be added from HAL events.
 Enabled by default.
commit cbaa6a66e0f9e3b7e305606924ecda0147b59e96
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Nov 9 15:21:23 2010 +1000

    config: remove mention of AllowEmptyInput
    
    "You will probably want to add the following option to the ServerFlags of
    your xorg.conf:
             Option "AllowEmptyInput" "True""
    
    I can't imagine why you would want to do that. My life is painful enough
    already.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Reviewed-by: Dan Nicholson <dbn.lists at gmail.com>

diff --git a/config/x11-input.fdi b/config/x11-input.fdi
index 9e629cb..b263f36 100644
--- a/config/x11-input.fdi
+++ b/config/x11-input.fdi
@@ -45,11 +45,6 @@
 
 	    See the evdev documentation for more information. 
     
-    You will probably want to add the following option to the ServerFlags of 
-    your xorg.conf:
-    
-        Option "AllowEmptyInput" "True"
-        
     FIXME: Support tablets too. 
     TODO: I think its fixed, can't test
     
commit 69e8e1b0b95a325da3e3a2d76d092e7131baa9ad
Author: Julien Cristau <jcristau at debian.org>
Date:   Mon May 17 19:39:54 2010 +0200

    os: include dix-config.h, not xorg-config.h
    
    os/strlc{at,py}.c were trying to include xorg-config.h, which is not
    available in dix.
    
    Signed-off-by: Julien Cristau <jcristau at debian.org>
    Acked-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/os/strlcat.c b/os/strlcat.c
index 91ceabb..7d53b0a 100644
--- a/os/strlcat.c
+++ b/os/strlcat.c
@@ -15,8 +15,8 @@
  */
 
 
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
 #endif
 
 #include <sys/types.h>
diff --git a/os/strlcpy.c b/os/strlcpy.c
index e8e1b02..2e55b2e 100644
--- a/os/strlcpy.c
+++ b/os/strlcpy.c
@@ -14,8 +14,8 @@
  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
 #endif
 
 #include <sys/types.h>
commit 68e4a628d65312df93cc71f3e76241584c4bbd23
Author: Cyril Brulebois <kibi at debian.org>
Date:   Wed Nov 10 15:28:29 2010 +0100

    Remove more superfluous if(p!=NULL) checks around free(p).
    
    This patch has been generated by the following Coccinelle semantic patch:
    
    @@
    expression E;
    @@
    - if (E != NULL) {
    -   free(E);
    - }
    + free(E);
    
    Signed-off-by: Cyril Brulebois <kibi at debian.org>
    Reviewed-by: Mark Kettenis <kettenis at openbsd.org>
    Reviewed-by: Matt Turner <mattst88 at gmail.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/glx/glxdri.c b/glx/glxdri.c
index 41482c9..ec93434 100644
--- a/glx/glxdri.c
+++ b/glx/glxdri.c
@@ -1160,9 +1160,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
      */
     buffer_size = __glXGetExtensionString(screen->glx_enable_bits, NULL);
     if (buffer_size > 0) {
-	if (screen->base.GLXextensions != NULL) {
-	    free(screen->base.GLXextensions);
-	}
+	free(screen->base.GLXextensions);
 
 	screen->base.GLXextensions = xnfalloc(buffer_size);
 	(void) __glXGetExtensionString(screen->glx_enable_bits, 
diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index c2305ad..0b69201 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -792,9 +792,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
      */
     buffer_size = __glXGetExtensionString(screen->glx_enable_bits, NULL);
     if (buffer_size > 0) {
-	if (screen->base.GLXextensions != NULL) {
-	    free(screen->base.GLXextensions);
-	}
+	free(screen->base.GLXextensions);
 
 	screen->base.GLXextensions = xnfalloc(buffer_size);
 	(void) __glXGetExtensionString(screen->glx_enable_bits, 
diff --git a/glx/single2.c b/glx/single2.c
index f93ce6e..07b89a8 100644
--- a/glx/single2.c
+++ b/glx/single2.c
@@ -346,9 +346,7 @@ int DoGetString(__GLXclientState *cl, GLbyte *pc, GLboolean need_swap)
 				      cl->GLClientextensions);
 	buf = __glXcombine_strings(buf1,
 				      cx->pGlxScreen->GLextensions);
-	if (buf1 != NULL) {
-	    free(buf1);
-	}
+	free(buf1);
 	string = buf;
     }
     else if ( name == GL_VERSION ) {
diff --git a/hw/xwin/glx/indirect.c b/hw/xwin/glx/indirect.c
index 3891885..5d7391d 100644
--- a/hw/xwin/glx/indirect.c
+++ b/hw/xwin/glx/indirect.c
@@ -682,10 +682,7 @@ glxWinScreenProbe(ScreenPtr pScreen)
         unsigned int buffer_size = __glXGetExtensionString(screen->glx_enable_bits, NULL);
         if (buffer_size > 0)
           {
-            if (screen->base.GLXextensions != NULL)
-              {
-                free(screen->base.GLXextensions);
-              }
+            free(screen->base.GLXextensions);
 
             screen->base.GLXextensions = xnfalloc(buffer_size);
             __glXGetExtensionString(screen->glx_enable_bits, screen->base.GLXextensions);
commit b142b0d27442191d628762604f4eb1f65263d717
Author: Cyril Brulebois <kibi at debian.org>
Date:   Mon Nov 8 23:35:33 2010 +0100

    Remove more superfluous if(p!=NULL) checks around free(p).
    
    This patch has been generated by the following Coccinelle semantic patch:
    
    @@
    expression E;
    @@
    - if (E != NULL)
    -   free(E);
    + free(E);
    
    Signed-off-by: Cyril Brulebois <kibi at debian.org>
    Reviewed-by: Matt Turner <mattst88 at gmail.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/grabs.c b/dix/grabs.c
index f850e3d..69c58df 100644
--- a/dix/grabs.c
+++ b/dix/grabs.c
@@ -117,11 +117,8 @@ CreateGrab(
 static void
 FreeGrab(GrabPtr pGrab)
 {
-    if (pGrab->modifiersDetail.pMask != NULL)
-	free(pGrab->modifiersDetail.pMask);
-
-    if (pGrab->detail.pMask != NULL)
-	free(pGrab->detail.pMask);
+    free(pGrab->modifiersDetail.pMask);
+    free(pGrab->detail.pMask);
 
     if (pGrab->cursor)
 	FreeCursor(pGrab->cursor, (Cursor)0);
diff --git a/glx/single2.c b/glx/single2.c
index 56ad86d..f93ce6e 100644
--- a/glx/single2.c
+++ b/glx/single2.c
@@ -377,8 +377,7 @@ int DoGetString(__GLXclientState *cl, GLbyte *pc, GLboolean need_swap)
 
     __GLX_SEND_HEADER();
     WriteToClient(client, length, (char *) string); 
-    if (buf != NULL)
-	free(buf);
+    free(buf);
 
     return Success;
 }
diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index b2daec7..7fc2a60 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -2964,8 +2964,7 @@ xf86OutputSetEDID (xf86OutputPtr output, xf86MonPtr edid_mon)
     int			size;
 #endif
     
-    if (output->MonInfo != NULL)
-	free(output->MonInfo);
+    free(output->MonInfo);
     
     output->MonInfo = edid_mon;
 
diff --git a/mi/mispans.c b/mi/mispans.c
index 9f56e3c..53539e5 100644
--- a/mi/mispans.c
+++ b/mi/mispans.c
@@ -215,7 +215,7 @@ void miAppendSpans(SpanGroup *spanGroup, SpanGroup *otherGroup, Spans *spans)
 
 void miFreeSpanGroup(SpanGroup *spanGroup)
 {
-    if (spanGroup->group != NULL) free(spanGroup->group);
+    free(spanGroup->group);
 }
 
 static void QuickSortSpansX(
diff --git a/miext/rootless/rootlessScreen.c b/miext/rootless/rootlessScreen.c
index 43b9cbb..61d2f5d 100644
--- a/miext/rootless/rootlessScreen.c
+++ b/miext/rootless/rootlessScreen.c
@@ -92,8 +92,7 @@ RootlessUpdateScreenPixmap(ScreenPtr pScreen)
     rowbytes = PixmapBytePad(pScreen->width, pScreen->rootDepth);
 
     if (s->pixmap_data_size < rowbytes) {
-        if (s->pixmap_data != NULL)
-            free(s->pixmap_data);
+        free(s->pixmap_data);
 
         s->pixmap_data_size = rowbytes;
         s->pixmap_data = malloc(s->pixmap_data_size);
diff --git a/os/log.c b/os/log.c
index ee4b45f..7d10783 100644
--- a/os/log.c
+++ b/os/log.c
@@ -489,8 +489,7 @@ AuditFlush(OsTimerPtr timer, CARD32 now, pointer arg)
 	ErrorF("%slast message repeated %d times\n",
 	       prefix != NULL ? prefix : "", nrepeat);
 	nrepeat = 0;
-	if (prefix != NULL)
-	    free(prefix);
+	free(prefix);
 	return AUDIT_TIMEOUT;
     } else {
 	/* if the timer expires without anything to print, flush the message */
@@ -523,8 +522,7 @@ VAuditF(const char *f, va_list args)
 	nrepeat = 0;
 	auditTimer = TimerSet(auditTimer, 0, AUDIT_TIMEOUT, AuditFlush, NULL);
     }
-    if (prefix != NULL)
-	free(prefix);
+    free(prefix);
 }
 
 void
diff --git a/xkb/XKBMAlloc.c b/xkb/XKBMAlloc.c
index e85a8af..2681ba3 100644
--- a/xkb/XKBMAlloc.c
+++ b/xkb/XKBMAlloc.c
@@ -292,11 +292,9 @@ KeyCode		matchingKeys[XkbMaxKeyCount],nMatchingKeys;
     }
     type= &xkb->map->types[type_ndx];
     if (map_count==0) {
-	if (type->map!=NULL)
-	    free(type->map);
+	free(type->map);
 	type->map= NULL;
-	if (type->preserve!=NULL)
-	    free(type->preserve);
+	free(type->preserve);
 	type->preserve= NULL;
 	type->map_count= 0;
     }
diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c
index 5e6ab87..cfc6198 100644
--- a/xkb/ddxLoad.c
+++ b/xkb/ddxLoad.c
@@ -267,8 +267,7 @@ XkbDDXCompileKeymapByNames(	XkbDescPtr		xkb,
 		strncpy(nameRtrn,keymap,nameRtrnLen);
 		nameRtrn[nameRtrnLen-1]= '\0';
 	    }
-            if (buf != NULL)
-                free(buf);
+            free(buf);
 	    return TRUE;
 	}
 	else
@@ -287,8 +286,7 @@ XkbDDXCompileKeymapByNames(	XkbDescPtr		xkb,
     }
     if (nameRtrn)
 	nameRtrn[0]= '\0';
-    if (buf != NULL)
-        free(buf);
+    free(buf);
     return FALSE;
 }
 
commit 0649ac0afdb3f8ed11c2634563d6b9df161cb9ec
Author: Cyril Brulebois <kibi at debian.org>
Date:   Mon Nov 8 23:35:32 2010 +0100

    Remove more superfluous if(p) checks around free(p).
    
    This patch has been generated by the following Coccinelle semantic patch:
    
    @@
    expression E;
    @@
    - if (E)
    -   free(E);
    + free(E);
    
    Signed-off-by: Cyril Brulebois <kibi at debian.org>
    Reviewed-by: Matt Turner <mattst88 at gmail.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/dmx/glxProxy/glxcmds.c b/hw/dmx/glxProxy/glxcmds.c
index a9744e1..7602128 100644
--- a/hw/dmx/glxProxy/glxcmds.c
+++ b/hw/dmx/glxProxy/glxcmds.c
@@ -2565,7 +2565,7 @@ int __glXClientInfo(__GLXclientState *cl, GLbyte *pc)
    
     cl->GLClientmajorVersion = req->major;
     cl->GLClientminorVersion = req->minor;
-    if (cl->GLClientextensions) free(cl->GLClientextensions);
+    free(cl->GLClientextensions);
     buf = (const char *)(req+1);
     cl->GLClientextensions = strdup(buf);
 
diff --git a/hw/dmx/glxProxy/glxext.c b/hw/dmx/glxProxy/glxext.c
index a8fc0a8..886b317 100644
--- a/hw/dmx/glxProxy/glxext.c
+++ b/hw/dmx/glxProxy/glxext.c
@@ -77,10 +77,10 @@ static void ResetClientState(int clientIndex)
     Display **keep_be_displays;
     int i;
 
-    if (cl->returnBuf) free(cl->returnBuf);
-    if (cl->currentContexts) free(cl->currentContexts);
-    if (cl->currentDrawables) free(cl->currentDrawables);
-    if (cl->largeCmdBuf) free(cl->largeCmdBuf);
+    free(cl->returnBuf);
+    free(cl->currentContexts);
+    free(cl->currentDrawables);
+    free(cl->largeCmdBuf);
 
     for (i=0; i< screenInfo.numScreens; i++) {
        if (cl->be_displays[i])
@@ -97,7 +97,7 @@ static void ResetClientState(int clientIndex)
     */
     cl->GLClientmajorVersion = 1;
     cl->GLClientminorVersion = 0;
-    if (cl->GLClientextensions) free(cl->GLClientextensions);
+    free(cl->GLClientextensions);
 
     memset(cl->be_displays, 0, screenInfo.numScreens * sizeof(Display *));
 }
@@ -222,10 +222,10 @@ GLboolean __glXFreeContext(__GLXcontext *cx)
 {
     if (cx->idExists || cx->isCurrent) return GL_FALSE;
     
-    if (cx->feedbackBuf) free(cx->feedbackBuf);
-    if (cx->selectBuf) free(cx->selectBuf);
-    if (cx->real_ids) free(cx->real_ids);
-    if (cx->real_vids) free(cx->real_vids);
+    free(cx->feedbackBuf);
+    free(cx->selectBuf);
+    free(cx->real_ids);
+    free(cx->real_vids);
 
     if (cx->pGlxPixmap) {
        /*
commit 99275ad2fa99778afaefc54b62c8638afc59e755
Author: Cyril Brulebois <kibi at debian.org>
Date:   Wed Nov 10 16:06:10 2010 +0100

    Remove superfluous if(p!=NULL) checks around free(p); p=NULL;
    
    This patch has been generated by the following Coccinelle semantic patch:
    
    @@
    expression E;
    @@
    -  if (E != NULL) {
    -   free(E);
    (
    -   E = NULL;
    |
    -   E = 0;
    )
    -  }
    + free(E);
    + E = NULL;
    
    Signed-off-by: Cyril Brulebois <kibi at debian.org>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index 30e14b1..8f03321 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -952,11 +952,9 @@ SetAccelerationProfile(
     if(profile == NULL && profile_num != PROFILE_UNINITIALIZE)
 	return FALSE;
 
-    if(vel->profile_private != NULL){
-        /* Here one could free old profile-private data */
-        free(vel->profile_private);
-        vel->profile_private = NULL;
-    }
+    /* Here one could free old profile-private data */
+    free(vel->profile_private);
+    vel->profile_private = NULL;
     /* Here one could init profile-private data */
     vel->Profile = profile;
     vel->statistics.profile_number = profile_num;
diff --git a/hw/kdrive/fake/fake.c b/hw/kdrive/fake/fake.c
index b8306db..ba05234 100644
--- a/hw/kdrive/fake/fake.c
+++ b/hw/kdrive/fake/fake.c
@@ -215,11 +215,8 @@ fakeUnmapFramebuffer (KdScreenInfo *screen)
 {
     FakePriv		*priv = screen->card->driver;
     KdShadowFbFree (screen);
-    if (priv->base)
-    {
-	free (priv->base);
-	priv->base = 0;
-    }
+    free(priv->base);
+    priv->base = NULL;
     return TRUE;
 }
 
diff --git a/hw/xwin/wincmap.c b/hw/xwin/wincmap.c
index 9da0388..d526a92 100644
--- a/hw/xwin/wincmap.c
+++ b/hw/xwin/wincmap.c
@@ -516,11 +516,8 @@ winGetPaletteDD (ScreenPtr pScreen, ColormapPtr pcmap)
   pScreen->blackPixel = 0;
 
   /* Free colormap */
-  if (ppeColors != NULL)
-    {
-      free (ppeColors);
-      ppeColors = NULL;
-    }
+  free(ppeColors);
+  ppeColors = NULL;
 
   /* Free the DC */
   if (hdc != NULL)
diff --git a/hw/xwin/winpixmap.c b/hw/xwin/winpixmap.c
index 050c71a..8bd8e34 100644
--- a/hw/xwin/winpixmap.c
+++ b/hw/xwin/winpixmap.c
@@ -163,11 +163,8 @@ winDestroyPixmapNativeGDI (PixmapPtr pPixmap)
   if (pPixmapPriv->hBitmap) DeleteObject (pPixmapPriv->hBitmap);
   
   /* Free the bitmap info header memory */
-  if (pPixmapPriv->pbmih != NULL)
-    {
-      free (pPixmapPriv->pbmih);
-      pPixmapPriv->pbmih = NULL;
-    }
+  free(pPixmapPriv->pbmih);
+  pPixmapPriv->pbmih = NULL;
 
   /* Free the pixmap memory */
   free (pPixmap);
diff --git a/miext/rootless/rootlessWindow.c b/miext/rootless/rootlessWindow.c
index 42ab8da..c4a32aa 100644
--- a/miext/rootless/rootlessWindow.c
+++ b/miext/rootless/rootlessWindow.c
@@ -1140,10 +1140,8 @@ FinishFrameResize(WindowPtr pWin, Bool gravity, int oldX, int oldY,
         }
     }
 
-    if (gResizeDeathBits != NULL) {
-        free(gResizeDeathBits);
-        gResizeDeathBits = NULL;
-    }
+    free(gResizeDeathBits);
+    gResizeDeathBits = NULL;
 
     if (gravity) {
         pScreen->CopyWindow = gResizeOldCopyWindowProc;
diff --git a/render/miindex.c b/render/miindex.c
index 5e2e06c..4603136 100644
--- a/render/miindex.c
+++ b/render/miindex.c
@@ -322,16 +322,10 @@ void
 miCloseIndexed (ScreenPtr	pScreen,
 		PictFormatPtr	pFormat)
 {
-    if (pFormat->index.devPrivate)
-    {
-	free(pFormat->index.devPrivate);
-	pFormat->index.devPrivate = 0;
-    }
-    if (pFormat->index.pValues)
-    {
-	free(pFormat->index.pValues);
-	pFormat->index.pValues = 0;
-    }
+    free(pFormat->index.devPrivate);
+    pFormat->index.devPrivate = NULL;
+    free(pFormat->index.pValues);
+    pFormat->index.pValues = NULL;
 }
 
 void
diff --git a/render/picture.c b/render/picture.c
index 7fda6b9..896eaa7 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -1391,11 +1391,8 @@ SetPictureTransform (PicturePtr	    pPicture,
     }
     else
     {
-	if (pPicture->transform)
-	{
-	    free(pPicture->transform);
-	    pPicture->transform = 0;
-	}
+	free(pPicture->transform);
+	pPicture->transform = NULL;
     }
     pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT;
 
diff --git a/xkb/XKBAlloc.c b/xkb/XKBAlloc.c
index c52e091..bffd60f 100644
--- a/xkb/XKBAlloc.c
+++ b/xkb/XKBAlloc.c
@@ -212,10 +212,8 @@ XkbNamesPtr	names;
 	    register XkbKeyTypePtr	type;
 	    type= map->types;
 	    for (i=0;i<map->num_types;i++,type++) {
-		if (type->level_names!=NULL) {
-		    free(type->level_names);
-		    type->level_names= NULL;
-		}
+		free(type->level_names);
+		type->level_names = NULL;
 	    }
 	}
     }
diff --git a/xkb/XKBGAlloc.c b/xkb/XKBGAlloc.c
index d1adea3..3ec9eda 100644
--- a/xkb/XKBGAlloc.c
+++ b/xkb/XKBGAlloc.c
@@ -50,10 +50,8 @@ _XkbFreeGeomLeafElems(	Bool			freeAll,
 {
     if ((freeAll)||(*elems==NULL)) {
 	*num_inout= *sz_inout= 0;
-	if (*elems!=NULL) {
-	    free(*elems);
-	    *elems= NULL;
-	}	
+	free(*elems);
+	*elems = NULL;
 	return;
     }
 
@@ -373,22 +371,16 @@ XkbDoodadPtr	doodad= (XkbDoodadPtr)doodad_in;
     switch (doodad->any.type) {
    	case XkbTextDoodad: 
 	    {
-		if (doodad->text.text!=NULL) {
-		    free(doodad->text.text);
-		    doodad->text.text= NULL;
-		}
-		if (doodad->text.font!=NULL) {
-		    free(doodad->text.font);
-		    doodad->text.font= NULL;
-		}
+		free(doodad->text.text);
+		doodad->text.text = NULL;
+		free(doodad->text.font);
+		doodad->text.font = NULL;
 	    }
 	    break;
    	case XkbLogoDoodad: 
 	    {
-		if (doodad->logo.logo_name!=NULL) {
-		    free(doodad->logo.logo_name);
-		    doodad->logo.logo_name= NULL;
-		}
+		free(doodad->logo.logo_name);
+		doodad->logo.logo_name = NULL;
 	    }
 	    break;
     }
@@ -434,10 +426,8 @@ XkbFreeGeometry(XkbGeometryPtr geom,unsigned which,Bool freeMap)
     if ((which&XkbGeomKeyAliasesMask)&&(geom->key_aliases!=NULL))
 	XkbFreeGeomKeyAliases(geom,0,geom->num_key_aliases,TRUE);
     if (freeMap) {
-	if (geom->label_font!=NULL) {
-	    free(geom->label_font);
-	    geom->label_font= NULL;
-	}
+	free(geom->label_font);
+	geom->label_font = NULL;
 	free(geom);
     }
     return;
diff --git a/xkb/XKBMAlloc.c b/xkb/XKBMAlloc.c
index 6b186c1..e85a8af 100644
--- a/xkb/XKBMAlloc.c
+++ b/xkb/XKBMAlloc.c
@@ -321,9 +321,9 @@ KeyCode		matchingKeys[XkbMaxKeyCount],nMatchingKeys;
 		return BadAlloc;
 	    }
 	}
-	else if (type->preserve!=NULL) {
+	else {
 	    free(type->preserve);
-	    type->preserve= NULL;
+	    type->preserve = NULL;
 	}
 	type->map_count= map_count;
     }
@@ -807,19 +807,13 @@ XkbClientMapPtr	map;
 		register int 	i;
 		XkbKeyTypePtr	type;
 		for (i=0,type=map->types;i<map->num_types;i++,type++) {
-		    if (type->map!=NULL) {
-			free(type->map);
-			type->map= NULL;
-		    }
-		    if (type->preserve!=NULL) {
-			free(type->preserve);
-			type->preserve= NULL;
-		    }
+		    free(type->map);
+		    type->map = NULL;
+		    free(type->preserve);
+		    type->preserve = NULL;
 		    type->map_count= 0;
-		    if (type->level_names!=NULL) {
-			free(type->level_names);
-			type->level_names= NULL;
-		    }
+		    free(type->level_names);
+		    type->level_names = NULL;
 		}
 	    }
 	    free(map->types);
@@ -828,10 +822,8 @@ XkbClientMapPtr	map;
 	}
     }
     if (what&XkbKeySymsMask) {
-	if (map->key_sym_map!=NULL) {
-	    free(map->key_sym_map);
-	    map->key_sym_map= NULL;
-	}
+	free(map->key_sym_map);
+	map->key_sym_map = NULL;
 	if (map->syms!=NULL) {
 	    free(map->syms);
 	    map->size_syms= map->num_syms= 0;
@@ -864,10 +856,8 @@ XkbServerMapPtr	map;
 	map->explicit= NULL;
     }
     if (what&XkbKeyActionsMask) {
-	if (map->key_acts!=NULL) {
-	    free(map->key_acts);
-	    map->key_acts= NULL;
-	}
+	free(map->key_acts);
+	map->key_acts = NULL;
 	if (map->acts!=NULL) {
 	    free(map->acts);
 	    map->num_acts= map->size_acts= 0;
commit 9e999d18b004b8ead9c6c5d79b4a3d4bbf0e3152
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Nov 5 12:08:11 2010 +1000

    Xi: if XTEST device creation fails, fail the master devices.
    
    When getting close to the MAXDEVICES limit, the creation of XTEST devices
    may fail due to device id exhaustion. In that case, fail the creation of
    master devices too and return an error to the client.
    
    Theoretically, we could alloc the MDs without the XTEST devices but that
    will get interesting when a client starts sending XTEST events through those
    devices.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/Xi/xichangehierarchy.c b/Xi/xichangehierarchy.c
index b7140d5..b9cdedf 100644
--- a/Xi/xichangehierarchy.c
+++ b/Xi/xichangehierarchy.c
@@ -157,7 +157,11 @@ add_master(ClientPtr client, xXIAddMasterInfo *c, int flags[MAXDEVICES])
     /* Allocate virtual slave devices for xtest events */
     rc = AllocXTestDevice(client, name, &XTestptr, &XTestkeybd, ptr, keybd);
     if (rc != Success)
+    {
+        DeleteInputDeviceRequest(ptr);
+        DeleteInputDeviceRequest(keybd);
         goto unwind;
+    }
 
     ActivateDevice(ptr, FALSE);
     ActivateDevice(keybd, FALSE);
commit 5a455e0c80d433adc4109ebf313fd92afa194545
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Nov 5 11:49:12 2010 +1000

    Xi: rename two variables from ptr to dev.
    
    They were named ptr when everything was in one function to save one more
    variable. Now that the stuff is split out, "dev" makes more sense.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/Xi/xichangehierarchy.c b/Xi/xichangehierarchy.c
index 5818d2c..b7140d5 100644
--- a/Xi/xichangehierarchy.c
+++ b/Xi/xichangehierarchy.c
@@ -325,14 +325,14 @@ unwind:
 static int
 detach_slave(ClientPtr client, xXIDetachSlaveInfo *c, int flags[MAXDEVICES])
 {
-    DeviceIntPtr ptr;
+    DeviceIntPtr dev;
     int rc;
 
-    rc = dixLookupDevice(&ptr, c->deviceid, client, DixManageAccess);
+    rc = dixLookupDevice(&dev, c->deviceid, client, DixManageAccess);
     if (rc != Success)
         goto unwind;
 
-    if (IsMaster(ptr))
+    if (IsMaster(dev))
     {
         client->errorValue = c->deviceid;
         rc = BadDevice;
@@ -340,15 +340,15 @@ detach_slave(ClientPtr client, xXIDetachSlaveInfo *c, int flags[MAXDEVICES])
     }
 
     /* Don't allow changes to XTest Devices, these are fixed */
-    if (IsXTestDevice(ptr, NULL))
+    if (IsXTestDevice(dev, NULL))
     {
         client->errorValue = c->deviceid;
         rc = BadDevice;
         goto unwind;
     }
 
-    AttachDevice(client, ptr, NULL);
-    flags[ptr->id] |= XISlaveDetached;
+    AttachDevice(client, dev, NULL);
+    flags[dev->id] |= XISlaveDetached;
 
 unwind:
     return rc;
@@ -358,15 +358,15 @@ static int
 attach_slave(ClientPtr client, xXIAttachSlaveInfo *c,
              int flags[MAXDEVICES])
 {
-    DeviceIntPtr ptr;
+    DeviceIntPtr dev;
     DeviceIntPtr newmaster;
     int rc;
 
-    rc = dixLookupDevice(&ptr, c->deviceid, client, DixManageAccess);
+    rc = dixLookupDevice(&dev, c->deviceid, client, DixManageAccess);
     if (rc != Success)
         goto unwind;
 
-    if (IsMaster(ptr))
+    if (IsMaster(dev))
     {
         client->errorValue = c->deviceid;
         rc = BadDevice;
@@ -374,7 +374,7 @@ attach_slave(ClientPtr client, xXIAttachSlaveInfo *c,
     }
 
     /* Don't allow changes to XTest Devices, these are fixed */
-    if (IsXTestDevice(ptr, NULL))
+    if (IsXTestDevice(dev, NULL))
     {
         client->errorValue = c->deviceid;
         rc = BadDevice;
@@ -391,15 +391,15 @@ attach_slave(ClientPtr client, xXIAttachSlaveInfo *c,
         goto unwind;
     }
 
-    if (!((IsPointerDevice(newmaster) && IsPointerDevice(ptr)) ||
-        (IsKeyboardDevice(newmaster) && IsKeyboardDevice(ptr))))
+    if (!((IsPointerDevice(newmaster) && IsPointerDevice(dev)) ||
+        (IsKeyboardDevice(newmaster) && IsKeyboardDevice(dev))))
     {
         rc = BadDevice;
         goto unwind;
     }
 
-    AttachDevice(client, ptr, newmaster);
-    flags[ptr->id] |= XISlaveAttached;
+    AttachDevice(client, dev, newmaster);
+    flags[dev->id] |= XISlaveAttached;
 
 unwind:
     return rc;
commit 9b89b91c685426c9944f7fc8890f436c18b7583c
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Nov 5 11:47:43 2010 +1000

    Xi: split hierarchy manipulation into static functions.
    
    No functional changes, just code cleanup to improve readability.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/Xi/xichangehierarchy.c b/Xi/xichangehierarchy.c
index c1899e1..5818d2c 100644
--- a/Xi/xichangehierarchy.c
+++ b/Xi/xichangehierarchy.c
@@ -136,12 +136,282 @@ int SProcXIChangeHierarchy(ClientPtr client)
     return (ProcXIChangeHierarchy(client));
 }
 
+static int
+add_master(ClientPtr client, xXIAddMasterInfo *c, int flags[MAXDEVICES])
+{
+    DeviceIntPtr ptr, keybd, XTestptr, XTestkeybd;
+    char* name;
+    int rc;
+
+    name = calloc(c->name_len + 1, sizeof(char));
+    strncpy(name, (char*)&c[1], c->name_len);
+
+    rc = AllocDevicePair(client, name, &ptr, &keybd,
+                         CorePointerProc, CoreKeyboardProc, TRUE);
+    if (rc != Success)
+        goto unwind;
+
+    if (!c->send_core)
+        ptr->coreEvents = keybd->coreEvents =  FALSE;
+
+    /* Allocate virtual slave devices for xtest events */
+    rc = AllocXTestDevice(client, name, &XTestptr, &XTestkeybd, ptr, keybd);
+    if (rc != Success)
+        goto unwind;
+
+    ActivateDevice(ptr, FALSE);
+    ActivateDevice(keybd, FALSE);
+    flags[ptr->id] |= XIMasterAdded;
+    flags[keybd->id] |= XIMasterAdded;
+
+    ActivateDevice(XTestptr, FALSE);
+    ActivateDevice(XTestkeybd, FALSE);
+    flags[XTestptr->id] |= XISlaveAdded;
+    flags[XTestkeybd->id] |= XISlaveAdded;
+
+    if (c->enable)
+    {
+        EnableDevice(ptr, FALSE);
+        EnableDevice(keybd, FALSE);
+        flags[ptr->id] |= XIDeviceEnabled;
+        flags[keybd->id] |= XIDeviceEnabled;
+
+        EnableDevice(XTestptr, FALSE);
+        EnableDevice(XTestkeybd, FALSE);
+        flags[XTestptr->id] |= XIDeviceEnabled;
+        flags[XTestkeybd->id] |= XIDeviceEnabled;
+    }
+
+    /* Attach the XTest virtual devices to the newly
+       created master device */
+    AttachDevice(NULL, XTestptr, ptr);
+    AttachDevice(NULL, XTestkeybd, keybd);
+    flags[XTestptr->id] |= XISlaveAttached;
+    flags[XTestkeybd->id] |= XISlaveAttached;
+
+unwind:
+    free(name);
+    return rc;
+}
+
+static int
+remove_master(ClientPtr client, xXIRemoveMasterInfo *r,
+              int flags[MAXDEVICES])
+{
+    DeviceIntPtr ptr, keybd, XTestptr, XTestkeybd;
+    int rc = Success;
+
+    if (r->return_mode != XIAttachToMaster &&
+        r->return_mode != XIFloating)
+        return BadValue;
+
+    rc = dixLookupDevice(&ptr, r->deviceid, client, DixDestroyAccess);
+    if (rc != Success)
+        goto unwind;
+
+    if (!IsMaster(ptr))
+    {
+        client->errorValue = r->deviceid;
+        rc = BadDevice;
+        goto unwind;
+    }
+
+    /* XXX: For now, don't allow removal of VCP, VCK */
+    if (ptr == inputInfo.pointer || ptr == inputInfo.keyboard)
+    {
+        rc = BadDevice;
+        goto unwind;
+    }
+
+
+    ptr = GetMaster(ptr, MASTER_POINTER);
+    rc = dixLookupDevice(&ptr, ptr->id, client, DixDestroyAccess);
+    if (rc != Success)
+        goto unwind;
+    keybd = GetMaster(ptr, MASTER_KEYBOARD);
+    rc = dixLookupDevice(&keybd, keybd->id, client, DixDestroyAccess);
+    if (rc != Success)
+        goto unwind;
+
+    XTestptr = GetXTestDevice(ptr);
+    rc = dixLookupDevice(&XTestptr, XTestptr->id, client, DixDestroyAccess);
+    if (rc != Success)
+        goto unwind;
+
+    XTestkeybd = GetXTestDevice(keybd);
+    rc = dixLookupDevice(&XTestkeybd, XTestkeybd->id, client,
+                         DixDestroyAccess);
+    if (rc != Success)
+        goto unwind;
+
+    /* Disabling sends the devices floating, reattach them if
+     * desired. */
+    if (r->return_mode == XIAttachToMaster)
+    {
+        DeviceIntPtr attached,
+                     newptr,
+                     newkeybd;
+
+        rc = dixLookupDevice(&newptr, r->return_pointer, client, DixAddAccess);
+        if (rc != Success)
+            goto unwind;
+
+        if (!IsMaster(newptr))
+        {
+            client->errorValue = r->return_pointer;
+            rc = BadDevice;
+            goto unwind;
+        }
+
+        rc = dixLookupDevice(&newkeybd, r->return_keyboard,
+                             client, DixAddAccess);
+        if (rc != Success)
+            goto unwind;
+
+        if (!IsMaster(newkeybd))
+        {
+            client->errorValue = r->return_keyboard;
+            rc = BadDevice;
+            goto unwind;
+        }
+
+        for (attached = inputInfo.devices; attached; attached = attached->next)
+        {
+            if (!IsMaster(attached)) {
+                if (attached->u.master == ptr)
+                {
+                    AttachDevice(client, attached, newptr);
+                    flags[attached->id] |= XISlaveAttached;
+                }
+                if (attached->u.master == keybd)
+                {
+                    AttachDevice(client, attached, newkeybd);
+                    flags[attached->id] |= XISlaveAttached;
+                }
+            }
+        }
+    }
+
+    /* can't disable until we removed pairing */
+    keybd->spriteInfo->paired = NULL;
+    ptr->spriteInfo->paired = NULL;
+    XTestptr->spriteInfo->paired = NULL;
+    XTestkeybd->spriteInfo->paired = NULL;
+
+    /* disable the remove the devices, XTest devices must be done first
+       else the sprites they rely on will be destroyed  */
+    DisableDevice(XTestptr, FALSE);
+    DisableDevice(XTestkeybd, FALSE);
+    DisableDevice(keybd, FALSE);
+    DisableDevice(ptr, FALSE);
+    flags[XTestptr->id] |= XIDeviceDisabled | XISlaveDetached;
+    flags[XTestkeybd->id] |= XIDeviceDisabled | XISlaveDetached;
+    flags[keybd->id] |= XIDeviceDisabled;
+    flags[ptr->id] |= XIDeviceDisabled;
+
+    RemoveDevice(XTestptr, FALSE);
+    RemoveDevice(XTestkeybd, FALSE);
+    RemoveDevice(keybd, FALSE);
+    RemoveDevice(ptr, FALSE);
+    flags[XTestptr->id] |= XISlaveRemoved;
+    flags[XTestkeybd->id] |= XISlaveRemoved;
+    flags[keybd->id] |= XIMasterRemoved;
+    flags[ptr->id] |= XIMasterRemoved;
+
+unwind:
+    return rc;
+}
+
+static int
+detach_slave(ClientPtr client, xXIDetachSlaveInfo *c, int flags[MAXDEVICES])
+{
+    DeviceIntPtr ptr;
+    int rc;
+
+    rc = dixLookupDevice(&ptr, c->deviceid, client, DixManageAccess);
+    if (rc != Success)
+        goto unwind;
+
+    if (IsMaster(ptr))
+    {
+        client->errorValue = c->deviceid;
+        rc = BadDevice;
+        goto unwind;
+    }
+
+    /* Don't allow changes to XTest Devices, these are fixed */
+    if (IsXTestDevice(ptr, NULL))
+    {
+        client->errorValue = c->deviceid;
+        rc = BadDevice;
+        goto unwind;
+    }
+
+    AttachDevice(client, ptr, NULL);
+    flags[ptr->id] |= XISlaveDetached;
+
+unwind:
+    return rc;
+}
+
+static int
+attach_slave(ClientPtr client, xXIAttachSlaveInfo *c,
+             int flags[MAXDEVICES])
+{
+    DeviceIntPtr ptr;
+    DeviceIntPtr newmaster;
+    int rc;
+
+    rc = dixLookupDevice(&ptr, c->deviceid, client, DixManageAccess);
+    if (rc != Success)
+        goto unwind;
+
+    if (IsMaster(ptr))
+    {
+        client->errorValue = c->deviceid;
+        rc = BadDevice;
+        goto unwind;
+    }
+
+    /* Don't allow changes to XTest Devices, these are fixed */
+    if (IsXTestDevice(ptr, NULL))
+    {
+        client->errorValue = c->deviceid;
+        rc = BadDevice;
+        goto unwind;
+    }
+
+    rc = dixLookupDevice(&newmaster, c->new_master, client, DixAddAccess);
+    if (rc != Success)
+        goto unwind;
+    if (!IsMaster(newmaster))
+    {
+        client->errorValue = c->new_master;
+        rc = BadDevice;
+        goto unwind;
+    }
+
+    if (!((IsPointerDevice(newmaster) && IsPointerDevice(ptr)) ||
+        (IsKeyboardDevice(newmaster) && IsKeyboardDevice(ptr))))
+    {
+        rc = BadDevice;
+        goto unwind;
+    }
+
+    AttachDevice(client, ptr, newmaster);
+    flags[ptr->id] |= XISlaveAttached;
+
+unwind:
+    return rc;
+}
+
+
+
 #define SWAPIF(cmd) if (client->swapped) { cmd; }
 
 int
 ProcXIChangeHierarchy(ClientPtr client)
 {
-    DeviceIntPtr ptr, keybd, XTestptr, XTestkeybd;
     xXIAnyHierarchyChangeInfo *any;
     int required_len = sizeof(xXIChangeHierarchyReq);
     char n;
@@ -169,276 +439,38 @@ ProcXIChangeHierarchy(ClientPtr client)
             case XIAddMaster:
                 {
                     xXIAddMasterInfo* c = (xXIAddMasterInfo*)any;
-                    char* name;
-
                     SWAPIF(swaps(&c->name_len, n));
-                    name = calloc(c->name_len + 1, sizeof(char));
-                    strncpy(name, (char*)&c[1], c->name_len);
-
-
-                    rc = AllocDevicePair(client, name, &ptr, &keybd,
-                                         CorePointerProc, CoreKeyboardProc,
-                                         TRUE);
-                    if (rc != Success)
-                    {
-                        free(name);
-                        goto unwind;
-                    }
 
-                    if (!c->send_core)
-                        ptr->coreEvents = keybd->coreEvents =  FALSE;
-
-                    /* Allocate virtual slave devices for xtest events */
-                    rc = AllocXTestDevice(client, name, &XTestptr, &XTestkeybd,
-                                         ptr, keybd);
+                    rc = add_master(client, c, flags);
                     if (rc != Success)
-                    {
-
-                        free(name);
                         goto unwind;
-                    }
-
-                    ActivateDevice(ptr, FALSE);
-                    ActivateDevice(keybd, FALSE);
-                    flags[ptr->id] |= XIMasterAdded;
-                    flags[keybd->id] |= XIMasterAdded;
-
-                    ActivateDevice(XTestptr, FALSE);
-                    ActivateDevice(XTestkeybd, FALSE);
-                    flags[XTestptr->id] |= XISlaveAdded;
-                    flags[XTestkeybd->id] |= XISlaveAdded;
-
-                    if (c->enable)
-                    {
-                        EnableDevice(ptr, FALSE);
-                        EnableDevice(keybd, FALSE);
-                        flags[ptr->id] |= XIDeviceEnabled;
-                        flags[keybd->id] |= XIDeviceEnabled;
-
-                        EnableDevice(XTestptr, FALSE);
-                        EnableDevice(XTestkeybd, FALSE);
-                        flags[XTestptr->id] |= XIDeviceEnabled;
-                        flags[XTestkeybd->id] |= XIDeviceEnabled;
-                    }
-
-                    /* Attach the XTest virtual devices to the newly
-                       created master device */
-                    AttachDevice(NULL, XTestptr, ptr);
-                    AttachDevice(NULL, XTestkeybd, keybd);
-                    flags[XTestptr->id] |= XISlaveAttached;
-                    flags[XTestkeybd->id] |= XISlaveAttached;
-
-                    free(name);
                 }
                 break;
             case XIRemoveMaster:
                 {
                     xXIRemoveMasterInfo* r = (xXIRemoveMasterInfo*)any;
 
-                    if (r->return_mode != XIAttachToMaster &&
-                            r->return_mode != XIFloating)
-                        return BadValue;
-
-                    rc = dixLookupDevice(&ptr, r->deviceid, client,
-                                         DixDestroyAccess);
-                    if (rc != Success)
-                        goto unwind;
-
-                    if (!IsMaster(ptr))
-                    {
-                        client->errorValue = r->deviceid;
-                        rc = BadDevice;
-                        goto unwind;
-                    }
-
-                    /* XXX: For now, don't allow removal of VCP, VCK */
-                    if (ptr == inputInfo.pointer ||
-                            ptr == inputInfo.keyboard)
-                    {
-                        rc = BadDevice;
-                        goto unwind;
-                    }
-
-
-                    ptr = GetMaster(ptr, MASTER_POINTER);
-                    rc = dixLookupDevice(&ptr,
-                                         ptr->id,
-                                         client,
-                                         DixDestroyAccess);
-                    if (rc != Success)
-                        goto unwind;
-                    keybd = GetMaster(ptr, MASTER_KEYBOARD);
-                    rc = dixLookupDevice(&keybd,
-                                         keybd->id,
-                                         client,
-                                         DixDestroyAccess);
-                    if (rc != Success)
-                        goto unwind;
-
-                    XTestptr = GetXTestDevice(ptr);
-                    rc = dixLookupDevice(&XTestptr, XTestptr->id, client,
-                                         DixDestroyAccess);
-                    if (rc != Success)
-                        goto unwind;
-
-                    XTestkeybd = GetXTestDevice(keybd);
-                    rc = dixLookupDevice(&XTestkeybd, XTestkeybd->id, client,
-                                         DixDestroyAccess);
+                    rc = remove_master(client, r, flags);
                     if (rc != Success)
                         goto unwind;
-
-                    /* Disabling sends the devices floating, reattach them if
-                     * desired. */
-                    if (r->return_mode == XIAttachToMaster)
-                    {
-                        DeviceIntPtr attached,
-                                     newptr,
-                                     newkeybd;
-
-                        rc = dixLookupDevice(&newptr, r->return_pointer,
-                                             client, DixAddAccess);
-                        if (rc != Success)
-                            goto unwind;
-
-                        if (!IsMaster(newptr))
-                        {
-                            client->errorValue = r->return_pointer;
-                            rc = BadDevice;
-                            goto unwind;
-                        }
-
-                        rc = dixLookupDevice(&newkeybd, r->return_keyboard,
-                                             client, DixAddAccess);
-                        if (rc != Success)
-                            goto unwind;
-
-                        if (!IsMaster(newkeybd))
-                        {
-                            client->errorValue = r->return_keyboard;
-                            rc = BadDevice;
-                            goto unwind;
-                        }
-
-                        for (attached = inputInfo.devices;
-                                attached;
-                                attached = attached->next)
-                        {
-                            if (!IsMaster(attached)) {
-                                if (attached->u.master == ptr)
-                                {
-                                    AttachDevice(client, attached, newptr);
-                                    flags[attached->id] |= XISlaveAttached;
-                                }
-                                if (attached->u.master == keybd)
-                                {
-                                    AttachDevice(client, attached, newkeybd);
-                                    flags[attached->id] |= XISlaveAttached;
-                                }
-                            }
-                        }
-                    }
-
-                    /* can't disable until we removed pairing */
-                    keybd->spriteInfo->paired = NULL;
-                    ptr->spriteInfo->paired = NULL;
-                    XTestptr->spriteInfo->paired = NULL;
-                    XTestkeybd->spriteInfo->paired = NULL;
-
-                    /* disable the remove the devices, XTest devices must be done first
-                       else the sprites they rely on will be destroyed  */
-                    DisableDevice(XTestptr, FALSE);
-                    DisableDevice(XTestkeybd, FALSE);
-                    DisableDevice(keybd, FALSE);
-                    DisableDevice(ptr, FALSE);
-                    flags[XTestptr->id] |= XIDeviceDisabled | XISlaveDetached;
-                    flags[XTestkeybd->id] |= XIDeviceDisabled | XISlaveDetached;
-                    flags[keybd->id] |= XIDeviceDisabled;
-                    flags[ptr->id] |= XIDeviceDisabled;
-
-                    RemoveDevice(XTestptr, FALSE);
-                    RemoveDevice(XTestkeybd, FALSE);
-                    RemoveDevice(keybd, FALSE);
-                    RemoveDevice(ptr, FALSE);
-                    flags[XTestptr->id] |= XISlaveRemoved;
-                    flags[XTestkeybd->id] |= XISlaveRemoved;
-                    flags[keybd->id] |= XIMasterRemoved;
-                    flags[ptr->id] |= XIMasterRemoved;
                 }
                 break;
             case XIDetachSlave:
                 {
                     xXIDetachSlaveInfo* c = (xXIDetachSlaveInfo*)any;
 
-                    rc = dixLookupDevice(&ptr, c->deviceid, client,
-                                          DixManageAccess);
+                    rc = detach_slave(client, c, flags);
                     if (rc != Success)
                        goto unwind;
-
-                    if (IsMaster(ptr))
-                    {
-                        client->errorValue = c->deviceid;
-                        rc = BadDevice;
-                        goto unwind;
-                    }
-
-                    /* Don't allow changes to XTest Devices, these are fixed */
-                    if (IsXTestDevice(ptr, NULL))
-                    {
-                        client->errorValue = c->deviceid;
-                        rc = BadDevice;
-                        goto unwind;
-                    }
-
-                    AttachDevice(client, ptr, NULL);
-                    flags[ptr->id] |= XISlaveDetached;
                 }
                 break;
             case XIAttachSlave:
                 {
                     xXIAttachSlaveInfo* c = (xXIAttachSlaveInfo*)any;
-                    DeviceIntPtr newmaster;
 
-                    rc = dixLookupDevice(&ptr, c->deviceid, client,
-                                          DixManageAccess);
+                    rc = attach_slave(client, c, flags);
                     if (rc != Success)
                        goto unwind;
-
-                    if (IsMaster(ptr))
-                    {
-                        client->errorValue = c->deviceid;
-                        rc = BadDevice;
-                        goto unwind;
-                    }
-
-                    /* Don't allow changes to XTest Devices, these are fixed */
-                    if (IsXTestDevice(ptr, NULL))
-                    {
-                        client->errorValue = c->deviceid;
-                        rc = BadDevice;
-                        goto unwind;
-                    }
-
-                    rc = dixLookupDevice(&newmaster, c->new_master,
-                            client, DixAddAccess);
-                    if (rc != Success)
-                        goto unwind;
-                    if (!IsMaster(newmaster))
-                    {
-                        client->errorValue = c->new_master;
-                        rc = BadDevice;
-                        goto unwind;
-                    }
-
-                    if (!((IsPointerDevice(newmaster) &&
-                                    IsPointerDevice(ptr)) ||
-                                (IsKeyboardDevice(newmaster) &&
-                                 IsKeyboardDevice(ptr))))
-                    {
-                        rc = BadDevice;
-                        goto unwind;
-                    }
-                    AttachDevice(client, ptr, newmaster);
-                    flags[ptr->id] |= XISlaveAttached;
                 }
                 break;
         }


More information about the xorg-commit mailing list