From 341f3bccafde71754a9ed2303df9908e509c6d31 Mon Sep 17 00:00:00 2001 From: Olivier Fourdan Date: Fri, 5 Feb 2016 09:48:15 +0100 Subject: [PATCH] vidmode: use appropriate API 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. Reviewed-by: Adam Jackson Signed-off-by: Olivier Fourdan --- 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 10c7b4b40..b25fe26d5 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");