UPSTREAM: drm/edid: move displayid validation to it's own function.
authorDave Airlie <airlied@redhat.com>
Tue, 3 May 2016 05:38:37 +0000 (15:38 +1000)
committerZheng Yang <zhengyang@rock-chips.com>
Tue, 20 Jun 2017 09:22:50 +0000 (17:22 +0800)
We need to use this for validating modeline additions.

Change-Id: Idda40c52ff9372433e8bf81e1df5af7b59ce9b4c
Signed-off-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Zheng Yang <zhengyang@rock-chips.com>
(cherry picked from commit c97291774c1b867b56c3d439ddaec9a965cf559e)

drivers/gpu/drm/drm_edid.c

index 200aa3997bc684169249abddfe0ec8ffcd2cf140..dafcfdbdb716ac5c3392fa2409f88286367fa556 100644 (file)
@@ -4269,6 +4269,29 @@ static void drm_add_display_info(struct edid *edid,
                info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
 }
 
+static int validate_displayid(u8 *displayid, int length, int idx)
+{
+       int i;
+       u8 csum = 0;
+       struct displayid_hdr *base;
+
+       base = (struct displayid_hdr *)&displayid[idx];
+
+       DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
+                     base->rev, base->bytes, base->prod_id, base->ext_count);
+
+       if (base->bytes + 5 > length - idx)
+               return -EINVAL;
+       for (i = idx; i <= base->bytes + 5; i++) {
+               csum += displayid[i];
+       }
+       if (csum) {
+               DRM_ERROR("DisplayID checksum invalid, remainder is %d\n", csum);
+               return -EINVAL;
+       }
+       return 0;
+}
+
 /**
  * drm_add_edid_modes - add modes from EDID data, if available
  * @connector: connector we're probing
@@ -4596,30 +4619,15 @@ static int drm_parse_display_id(struct drm_connector *connector,
 {
        /* if this is an EDID extension the first byte will be 0x70 */
        int idx = 0;
-       struct displayid_hdr *base;
        struct displayid_block *block;
-       u8 csum = 0;
-       int i;
        int ret;
 
        if (is_edid_extension)
                idx = 1;
 
-       base = (struct displayid_hdr *)&displayid[idx];
-
-       DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
-                     base->rev, base->bytes, base->prod_id, base->ext_count);
-
-       if (base->bytes + 5 > length - idx)
-               return -EINVAL;
-
-       for (i = idx; i <= base->bytes + 5; i++) {
-               csum += displayid[i];
-       }
-       if (csum) {
-               DRM_ERROR("DisplayID checksum invalid, remainder is %d\n", csum);
-               return -EINVAL;
-       }
+       ret = validate_displayid(displayid, length, idx);
+       if (ret)
+               return ret;
 
        idx += sizeof(struct displayid_hdr);
        while (block = (struct displayid_block *)&displayid[idx],