[PATCH 01/12] vidmode: use appropriate API

Olivier Fourdan ofourdan at redhat.com
Fri Feb 5 08:48:15 UTC 2016


dixRegisterPrivateKey() can allocate memory that will be freed when the
screen is teared down.

No need to calloc() and free the memory ourself using a broken ref
counting method.

Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
---
 hw/xfree86/common/xf86VidMode.c | 25 ++++---------------------
 1 file changed, 4 insertions(+), 21 deletions(-)

diff --git a/hw/xfree86/common/xf86VidMode.c b/hw/xfree86/common/xf86VidMode.c
index 10c7b4b..b25fe26 100644
--- a/hw/xfree86/common/xf86VidMode.c
+++ b/hw/xfree86/common/xf86VidMode.c
@@ -48,8 +48,7 @@
 #include "xf86cmap.h"
 
 static DevPrivateKeyRec VidModeKeyRec;
-static DevPrivateKey VidModeKey;
-static int VidModeCount = 0;
+#define VidModeKey (&VidModeKeyRec)
 static Bool VidModeClose(ScreenPtr pScreen);
 
 #define VMPTR(p) ((VidModePtr)dixLookupPrivate(&(p)->devPrivates, VidModeKey))
@@ -67,22 +66,16 @@ VidModeExtensionInit(ScreenPtr pScreen)
         return FALSE;
     }
 
-    VidModeKey = &VidModeKeyRec;
-
-    if (!dixRegisterPrivateKey(&VidModeKeyRec, PRIVATE_SCREEN, 0))
+    if (!dixRegisterPrivateKey(&VidModeKeyRec, PRIVATE_SCREEN, sizeof(VidModeRec)))
         return FALSE;
 
-    pVidMode = calloc(sizeof(VidModeRec), 1);
-    if (!pVidMode)
-        return FALSE;
-
-    dixSetPrivate(&pScreen->devPrivates, VidModeKey, pVidMode);
+    pVidMode = VMPTR(pScreen);
 
     pVidMode->Flags = 0;
     pVidMode->Next = NULL;
     pVidMode->CloseScreen = pScreen->CloseScreen;
     pScreen->CloseScreen = VidModeClose;
-    VidModeCount++;
+
     return TRUE;
 #else
     DebugF("no vidmode extension\n");
@@ -103,11 +96,6 @@ VidModeClose(ScreenPtr pScreen)
 
     pScreen->CloseScreen = pVidMode->CloseScreen;
 
-    if (--VidModeCount == 0) {
-        free(dixLookupPrivate(&pScreen->devPrivates, VidModeKey));
-        dixSetPrivate(&pScreen->devPrivates, VidModeKey, NULL);
-        VidModeKey = NULL;
-    }
     return pScreen->CloseScreen(pScreen);
 }
 
@@ -117,11 +105,6 @@ VidModeAvailable(int scrnIndex)
     ScrnInfoPtr pScrn;
     VidModePtr pVidMode;
 
-    if (VidModeKey == NULL) {
-        DebugF("VidModeKey == NULL\n");
-        return FALSE;
-    }
-
     pScrn = xf86Screens[scrnIndex];
     if (pScrn == NULL) {
         DebugF("pScrn == NULL\n");
-- 
2.5.0



More information about the xorg-devel mailing list