[PATCH] Don't rely on reseting static variables after UnloadModule.

Michal Srb msrb at suse.com
Tue Jun 26 10:09:16 PDT 2012


If the module was unloaded it can be loaded again and the
setup has to be done again. We can't rely on setupDone being
reinitialized to zero after dlclose and dlopen.

(It's not reinitialized probably because of dlsym being called
on modesettingModuleData which keeps reference counter for the
library above zero and so prevents it to be ever freed.)

Register proper TearDown function and set setupDone variable
to zero when being unloaded.

diff --git a/src/driver.c b/src/driver.c
index 4e2cfa0..fd9e1c2 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -137,6 +137,7 @@ static const OptionInfoRec Options[] = {
 int modesettingEntityIndex = -1;
 
 static MODULESETUPPROTO(Setup);
+static MODULETEARDOWNPROTO(TearDown);
 
 static XF86ModuleVersionInfo VersRec = {
     "modesetting",
@@ -151,7 +152,7 @@ static XF86ModuleVersionInfo VersRec = {
     {0, 0, 0, 0}
 };
 
-_X_EXPORT XF86ModuleData modesettingModuleData = { &VersRec, Setup, NULL };
+_X_EXPORT XF86ModuleData modesettingModuleData = { &VersRec, Setup, TearDown 
};
 
 static pointer
 Setup(pointer module, pointer opts, int *errmaj, int *errmin)
@@ -168,7 +169,7 @@ Setup(pointer module, pointer opts, int *errmaj, int 
*errmin)
 	 * The return value must be non-NULL on success even though there
 	 * is no TearDownProc.
 	 */
-	return (pointer) 1;
+	return (pointer) &setupDone;
     } else {
 	if (errmaj)
 	    *errmaj = LDR_ONCEONLY;
@@ -176,6 +177,12 @@ Setup(pointer module, pointer opts, int *errmaj, int 
*errmin)
     }
 }
 
+static void
+TearDown(pointer p)
+{
+    *(Bool*)p = 0;
+}
+
 static Bool DriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op, pointer ptr)
 {
   switch(op) {



More information about the xorg-devel mailing list