]> git.karo-electronics.de Git - linux-beck.git/commitdiff
drm: Perform basic sanity checks on probed modes
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Wed, 17 Dec 2014 11:56:23 +0000 (13:56 +0200)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Wed, 17 Dec 2014 17:29:35 +0000 (18:29 +0100)
Make sure the timings of probed modes at least pass some very basic
sanity checks.

The checks include:
 - clock,hdisplay,vdisplay are non zero
 - sync pulse fits within the blanking period
 - htotal,vtotal are big enough

I have not checked all the drivers to see if the modes the generate
might violate these constraints. I'm hoping not, because that would mean
either abandoning the idea of doing this from the core code, or fixing
the drivers.

I'm not entirely sure about limiting the sync pulse to the blanking
period. Intel hardware doesn't support such things, but some other
hardware might. However at least HDMI doesn't allow having sync pulse
edges within the active period, so I'm thinking the check is probably
OK to have in the common code.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
drivers/gpu/drm/drm_modes.c
drivers/gpu/drm/drm_probe_helper.c
include/drm/drm_modes.h

index 19188667f9287d4702da95b50525acfd2a423e10..11cc4deca55b89c782202c1b9e7b4e412d61f614 100644 (file)
@@ -905,6 +905,38 @@ bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1,
 }
 EXPORT_SYMBOL(drm_mode_equal_no_clocks_no_stereo);
 
+/**
+ * drm_mode_validate_basic - make sure the mode is somewhat sane
+ * @mode: mode to check
+ *
+ * Check that the mode timings are at least somewhat reasonable.
+ * Any hardware specific limits are left up for each driver to check.
+ *
+ * Returns:
+ * The mode status
+ */
+enum drm_mode_status
+drm_mode_validate_basic(const struct drm_display_mode *mode)
+{
+       if (mode->clock == 0)
+               return MODE_CLOCK_LOW;
+
+       if (mode->hdisplay == 0 ||
+           mode->hsync_start < mode->hdisplay ||
+           mode->hsync_end < mode->hsync_start ||
+           mode->htotal < mode->hsync_end)
+               return MODE_H_ILLEGAL;
+
+       if (mode->vdisplay == 0 ||
+           mode->vsync_start < mode->vdisplay ||
+           mode->vsync_end < mode->vsync_start ||
+           mode->vtotal < mode->vsync_end)
+               return MODE_V_ILLEGAL;
+
+       return MODE_OK;
+}
+EXPORT_SYMBOL(drm_mode_validate_basic);
+
 /**
  * drm_mode_validate_size - make sure modes adhere to size constraints
  * @mode: mode to check
index 2161d8ed7c6583ab44079de3fc70b58c06b3269f..2fbdcca7ca9a7eaa53df5685d76e52443ad9ea89 100644 (file)
@@ -167,7 +167,10 @@ static int drm_helper_probe_single_connector_modes_merge_bits(struct drm_connect
                mode_flags |= DRM_MODE_FLAG_3D_MASK;
 
        list_for_each_entry(mode, &connector->modes, head) {
-               mode->status = drm_mode_validate_size(mode, maxX, maxY);
+               mode->status = drm_mode_validate_basic(mode);
+
+               if (mode->status == MODE_OK)
+                       mode->status = drm_mode_validate_size(mode, maxX, maxY);
 
                if (mode->status == MODE_OK)
                        mode->status = drm_mode_validate_flag(mode, mode_flags);
index 6c531140d4584b25f0fc2ebea7120f18fdfd23cf..a36a5bfce2f52bbcd9461c9434cef60d025145f5 100644 (file)
@@ -217,6 +217,7 @@ bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1,
                                        const struct drm_display_mode *mode2);
 
 /* for use by the crtc helper probe functions */
+enum drm_mode_status drm_mode_validate_basic(const struct drm_display_mode *mode);
 enum drm_mode_status drm_mode_validate_size(const struct drm_display_mode *mode,
                                            int maxX, int maxY);
 void drm_mode_prune_invalid(struct drm_device *dev,