diff mbox

[6/6] drm/edid: Tighten checksum conditions for CEA blocks

Message ID f1cfd7c1-f9c0-4e3a-83a9-3a83fc8c23d7@HUB1.rwth-ad.de (mailing list archive)
State New, archived
Headers show

Commit Message

Stefan Brüns Nov. 30, 2014, 6:57 p.m. UTC
Checksumming was disabled for CEA blocks by

commit 4a638b4e38234233f5c7e6705662fbc0b58d80c2
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue May 25 16:33:09 2010 -0400

    drm/edid: Allow non-fatal checksum errors in CEA blocks

If only the checksum is wrong, reading twice should result in identical
data, whereas a bad transfer will most likely corrupt different bytes.
Comparing checksums is not sufficient, as there is a considerable chance
of two bad transfers having the same checksum.

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
---
 drivers/gpu/drm/drm_edid.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 31988ca..0b20fc9 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -1224,6 +1224,7 @@  struct edid *drm_do_get_edid(struct drm_connector *connector,
 {
 	int i, j = 0, valid_extensions = 0;
 	u8 *block, *new;
+	u8 *saved_block = NULL;
 	bool print_bad_edid = !connector->bad_edid_counter || (drm_debug & DRM_UT_KMS);
 
 	if ((block = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
@@ -1254,13 +1255,30 @@  struct edid *drm_do_get_edid(struct drm_connector *connector,
 
 	for (j = 1; j <= block[0x7e]; j++) {
 		u8 *ext_block = block + (valid_extensions + 1) * EDID_LENGTH;
+		u8 csum, last_csum = 0;
 		for (i = 0; i < 4; i++) {
 			if (get_edid_block(data, ext_block, j, EDID_LENGTH))
 				goto out;
-			if (drm_edid_block_valid(ext_block, j, print_bad_edid)) {
+			csum = drm_edid_block_checksum(ext_block);
+			if (!csum) {
 				valid_extensions++;
 				break;
+			} else if (ext_block[0] == CEA_EXT) {
+			/*
+			 * Some switches mangle CEA contents without fixing the checksum.
+			 * Accept CEA blocks when two reads return identical data.
+			 */
+				if (saved_block && csum == last_csum &&
+				    !memcmp(ext_block, saved_block, EDID_LENGTH)) {
+					valid_extensions++;
+					break;
+				}
+				kfree(saved_block);
+				saved_block = kmemdup(ext_block, EDID_LENGTH, GFP_KERNEL);
+				last_csum = csum;
 			}
+			if (print_bad_edid)
+				drm_dump_edid(ext_block);
 		}
 
 		if (i == 4 && print_bad_edid) {
@@ -1270,6 +1288,9 @@  struct edid *drm_do_get_edid(struct drm_connector *connector,
 
 			connector->bad_edid_counter++;
 		}
+
+		kfree(saved_block);
+		saved_block = NULL;
 	}
 
 	if (valid_extensions != block[0x7e]) {
@@ -1291,6 +1312,7 @@  carp:
 	connector->bad_edid_counter++;
 
 out:
+	kfree(saved_block);
 	kfree(block);
 	return NULL;
 }