xserver: Branch 'master'

Adam Jackson ajax at kemper.freedesktop.org
Fri Jul 15 15:08:23 UTC 2016


 hw/xfree86/common/xf86Config.c |   59 +++++++++++++++++++++++++++--------------
 1 file changed, 40 insertions(+), 19 deletions(-)

New commits:
commit 32a9504c69183485b0b796fa3966cd1e39992365
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 12 10:04:18 2016 -0400

    xfree86: Fix fallback driver sort order for Xorg -configure (v2)
    
    The intent here was that fallback drivers would be at the end of the
    list in order, but if a fallback driver happened to be at the end of the
    list already that's not what would happen. Rather than open-code
    something smarter, just use qsort.
    
    Note that qsort puts things in ascending order, so somewhat backwardsly
    fallbacks are greater than native drivers, and vesa is greater than
    modesetting.
    
    v2: Use strcmp to compare non-fallback drivers so we get a predictable
    result if your libc's qsort isn't stable (Keith Packard)
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 2dbefba..560e2ea 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -518,33 +518,54 @@ xf86InputDriverlistFromConfig(void)
     return modulearray;
 }
 
+static int
+is_fallback(const char *s)
+{
+    /* later entries are less preferred */
+    const char *fallback[5] = { "modesetting", "fbdev", "vesa",  "wsfb", NULL };
+    int i;
+
+    for (i = 0; fallback[i]; i++)
+	if (strstr(s, fallback[i]))
+	    return i;
+
+    return -1;
+}
+
+static int
+driver_sort(const void *_l, const void *_r)
+{
+    const char *l = *(const char **)_l;
+    const char *r = *(const char **)_r;
+    int left = is_fallback(l);
+    int right = is_fallback(r);
+
+    /* neither is a fallback, asciibetize */
+    if (left == -1 && right == -1)
+	return strcmp(l, r);
+
+    /* left is a fallback */
+    if (left >= 0)
+	return 1;
+
+    /* right is a fallback */
+    if (right >= 0)
+	return -1;
+
+    /* both are fallbacks, which is worse */
+    return left - right;
+}
+
 static void
 fixup_video_driver_list(const char **drivers)
 {
-    static const char *fallback[5] = { "modesetting", "fbdev", "vesa", "wsfb", NULL };
-    const char **end, **drv;
-    const char *x;
-    int i;
+    const char **end;
 
     /* walk to the end of the list */
     for (end = drivers; *end && **end; end++);
     end--;
 
-    /*
-     * for each of the fallback drivers, if we find it in the list,
-     * swap it with the last available non-fallback driver.
-     */
-    for (i = 0; fallback[i]; i++) {
-        for (drv = drivers; drv != end; drv++) {
-            if (strstr(*drv, fallback[i])) {
-                x = *drv;
-                *drv = *end;
-                *end = x;
-                end--;
-                break;
-            }
-        }
-    }
+    qsort(drivers, end - drivers, sizeof(const char *), driver_sort);
 }
 
 static const char **


More information about the xorg-commit mailing list