sna: Always assign a name to the modes
authorChris Wilson <chris@chris-wilson.co.uk>
Thu, 13 Feb 2014 01:06:41 +0000 (01:06 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Thu, 13 Feb 2014 01:10:48 +0000 (01:10 +0000)
In some cases, such as querying the mode from the CRTC, we may not have
a name associated with the mode. However, RandR always expects a valid
name. To satisfy this requirement, always generate the canonical mode
name if no other is specified.

References: https://bugs.freedesktop.org/show_bug.cgi?id=70132
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
src/sna/sna_display.c

index 9b05f74..32e74d0 100644 (file)
@@ -710,6 +710,32 @@ done:
 }
 #endif
 
+static char *canonical_kmode_name(const struct drm_mode_modeinfo *kmode)
+{
+       char tmp[32], *buf;
+       int len;
+
+       len = sprintf(tmp, "%dx%d%s",
+                     kmode->hdisplay, kmode->vdisplay,
+                     kmode->flags & V_INTERLACE ? "i" : "");
+       if ((unsigned)len >= sizeof(tmp))
+               return NULL;
+
+       buf = malloc(len + 1);
+       if (buf == NULL)
+               return NULL;
+
+       return memcpy(buf, tmp, len + 1);
+}
+
+static char *get_kmode_name(const struct drm_mode_modeinfo *kmode)
+{
+       if (*kmode->name == '\0')
+               return canonical_kmode_name(kmode);
+
+       return strdup(kmode->name);
+}
+
 static DisplayModePtr
 mode_from_kmode(ScrnInfoPtr scrn,
                const struct drm_mode_modeinfo *kmode,
@@ -738,7 +764,7 @@ mode_from_kmode(ScrnInfoPtr scrn,
        mode->VScan = kmode->vscan;
 
        mode->Flags = kmode->flags;
-       mode->name = strdup(kmode->name);
+       mode->name = get_kmode_name(kmode);
 
        if (kmode->type & DRM_MODE_TYPE_DRIVER)
                mode->type = M_T_DRIVER;
@@ -2360,24 +2386,6 @@ sna_output_panel_edid(xf86OutputPtr output, DisplayModePtr modes)
        return xf86ModesAdd(modes, m);
 }
 
-static char *canonical_mode_name(DisplayModePtr mode)
-{
-       char tmp[32], *buf;
-       int len;
-
-       len = sprintf(tmp, "%dx%d%s",
-                     mode->HDisplay, mode->VDisplay,
-                     mode->Flags & V_INTERLACE ? "i" : "");
-       if ((unsigned)len >= sizeof(tmp))
-               return NULL;
-
-       buf = malloc(len + 1);
-       if (buf == NULL)
-               return NULL;
-
-       return memcpy(buf, tmp, len + 1);
-}
-
 static DisplayModePtr
 sna_output_get_modes(xf86OutputPtr output)
 {
@@ -2426,6 +2434,7 @@ sna_output_get_modes(xf86OutputPtr output)
                                Modes = xf86ModesAdd(Modes, Mode);
                                Mode = NULL;
                        } else {
+                               free((void *)current->name);
                                current->name = strdup(Mode->name);
                                current->type = Mode->type;
                        }
@@ -2433,14 +2442,6 @@ sna_output_get_modes(xf86OutputPtr output)
        }
        free(Mode);
 
-       if (current && (current->name == NULL || *current->name == '\0')) {
-               char *str = canonical_mode_name(current);
-               if (str) {
-                       free((char *)current->name);
-                       current->name = str;
-               }
-       }
-
        /*
         * If the connector type is a panel, we will traverse the kernel mode to
         * get the panel limit. And then add all the standard modes to fake