summaryrefslogtreecommitdiff
path: root/hw/xfree86/common
diff options
context:
space:
mode:
authorAdam Jackson <ajax@redhat.com>2016-07-12 10:04:18 -0400
committerAdam Jackson <ajax@redhat.com>2016-07-15 11:08:01 -0400
commit32a9504c69183485b0b796fa3966cd1e39992365 (patch)
treee5ffdf962052e331ac33ee701331e94dd94404f1 /hw/xfree86/common
parent4926845a57fa8b53e18ea7d3434bf5539e9b7782 (diff)
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@keithp.com> Signed-off-by: Adam Jackson <ajax@redhat.com>
Diffstat (limited to 'hw/xfree86/common')
-rw-r--r--hw/xfree86/common/xf86Config.c59
1 files changed, 40 insertions, 19 deletions
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 2dbefbaf1..560e2ea4e 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 **