staging: xgifb: eliminate string comparison from mode search
authorAaro Koskinen <aaro.koskinen@iki.fi>
Fri, 6 Apr 2012 22:13:55 +0000 (01:13 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 10 Apr 2012 17:19:08 +0000 (10:19 -0700)
Eliminate string comparison from the video mode search.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/xgifb/XGI_main_26.c

index 5982c0d6f1a3aef77c6b84f9e726c58a5c139078..85dbf32b1f6625866c131d543f72f178b03100b1 100644 (file)
@@ -390,19 +390,26 @@ static int XGIfb_GetXG21DefaultLVDSModeIdx(struct xgifb_video_info *xgifb_info)
 static void XGIfb_search_mode(struct xgifb_video_info *xgifb_info,
                              const char *name)
 {
-       int i = 0, j = 0, l;
+       unsigned int xres;
+       unsigned int yres;
+       unsigned int bpp;
+       int i;
 
-       while (XGIbios_mode[i].mode_no != 0) {
-               l = min(strlen(name), strlen(XGIbios_mode[i].name));
-               if (!strncmp(name, XGIbios_mode[i].name, l)) {
+       if (sscanf(name, "%ux%ux%u", &xres, &yres, &bpp) != 3)
+               goto invalid_mode;
+
+       if (bpp == 24)
+               bpp = 32; /* That's for people who mix up color and fb depth. */
+
+       for (i = 0; XGIbios_mode[i].mode_no != 0; i++)
+               if (XGIbios_mode[i].xres == xres &&
+                   XGIbios_mode[i].yres == yres &&
+                   XGIbios_mode[i].bpp == bpp) {
                        xgifb_info->mode_idx = i;
-                       j = 1;
-                       break;
+                       return;
                }
-               i++;
-       }
-       if (!j)
-               pr_info("Invalid mode '%s'\n", name);
+invalid_mode:
+       pr_info("Invalid mode '%s'\n", name);
 }
 
 static void XGIfb_search_vesamode(struct xgifb_video_info *xgifb_info,