drmOpenByName() is called only by drmOpen(), so it's enough to call drmLoadKernelModule() only in drmOpen().
Signed-off-by: Wu Fengguang <fengguang...@intel.com> --- libdrm/xf86drm.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) --- drm.orig/libdrm/xf86drm.c +++ drm/libdrm/xf86drm.c @@ -439,6 +439,29 @@ int drmAvailable(void) return retval; } +static int drmLoadKernelModule(const char *name) +{ + if (drmAvailable()) + return 0; + + if (name == NULL) { + drmMsg("[drm] null kernel module name\n"); + return -1; + } + + if (!drm_server_info) { + drmMsg("[drm] too early to be able to load kernel module\n"); + return -1; + } + + /* try to load the kernel module now */ + if (drm_server_info->load_module(name)) + return 0; + + drmMsg("[drm] failed to load kernel module \"%s\"\n", name); + return -1; +} + /** * Open the device by bus ID. @@ -506,19 +529,6 @@ static int drmOpenByName(const char *nam drmVersionPtr version; char * id; - if (!drmAvailable()) { - if (!drm_server_info) { - return -1; - } - else { - /* try to load the kernel module now */ - if (!drm_server_info->load_module(name)) { - drmMsg("[drm] failed to load kernel module \"%s\"\n", name); - return -1; - } - } - } - /* * Open the first minor number that matches the driver name and isn't * already in use. If it's in use it will have a busid assigned already. @@ -598,13 +608,8 @@ static int drmOpenByName(const char *nam */ int drmOpen(const char *name, const char *busid) { - if (!drmAvailable() && name != NULL && drm_server_info) { - /* try to load the kernel */ - if (!drm_server_info->load_module(name)) { - drmMsg("[drm] failed to load kernel module \"%s\"\n", name); + if (drmLoadKernelModule(name)) return -1; - } - } if (busid) { int fd = drmOpenByBusid(busid); ------------------------------------------------------------------------------ Register Now & Save for Velocity, the Web Performance & Operations Conference from O'Reilly Media. Velocity features a full day of expert-led, hands-on workshops and two days of sessions from industry leaders in dedicated Performance & Operations tracks. Use code vel09scf and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf -- _______________________________________________ Dri-devel mailing list Dri-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/dri-devel