From c697351655e4b5501f43dda11d02f6fa22fc70da Mon Sep 17 00:00:00 2001
From: Timothy Strelchun <Timothy.Strelchun@Intel.Com>
Date: Thu, 2 Jun 2011 12:14:58 -0700
Subject: [PATCH] Fixed gfx driver module loading for slave processes.
 Fixed dfb_gfxcard_load_driver in how graphics driver module
 loading for slaves processes is handled to address the scenario
 when there are multiple graphics drivers installed and the
 module entry that should be loaded is not the first entry found.
 It was found that a local reference to the next module link must
 be stored prior to a call to the direct_module_unref function
 because it will initialize the next field to NULL when there are
 no more references to the module.  This is the same approach used
 by the dfb_gfxcard_find_driver function used by the master
 process.

---
 src/core/gfxcard.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/core/gfxcard.c b/src/core/gfxcard.c
index 2b4ba75..1c2707c 100644
--- a/src/core/gfxcard.c
+++ b/src/core/gfxcard.c
@@ -3502,9 +3502,13 @@ static void dfb_gfxcard_load_driver( void )
      if (!card->shared->module_name)
           return;
 
-     direct_list_foreach (link, dfb_graphics_drivers.entries) {
+     link = dfb_graphics_drivers.entries;
+
+     while (direct_list_check_link( link )) {
           DirectModuleEntry *module = (DirectModuleEntry*) link;
 
+          link = link->next;
+
           const GraphicsDriverFuncs *funcs = direct_module_ref( module );
 
           if (!funcs)
@@ -3516,8 +3520,10 @@ static void dfb_gfxcard_load_driver( void )
                card->module       = module;
                card->driver_funcs = funcs;
           }
-          else
+          else {
+               /* can result in immediate removal, so "link" must already be on next */
                direct_module_unref( module );
+          }
      }
 }
 
-- 
1.6.0.6

