From patchwork Thu Nov 20 02:27:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Stefan_Br=C3=BCns?= X-Patchwork-Id: 5345551 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0C7809F387 for ; Thu, 20 Nov 2014 02:28:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 338C0201E4 for ; Thu, 20 Nov 2014 02:28:40 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 480072018E for ; Thu, 20 Nov 2014 02:28:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7587F6E405; Wed, 19 Nov 2014 18:28:38 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx-out-2.rwth-aachen.de (mx-out-2.rwth-aachen.de [134.130.5.187]) by gabe.freedesktop.org (Postfix) with ESMTP id 461BC6E405 for ; Wed, 19 Nov 2014 18:28:37 -0800 (PST) X-IronPort-AV: E=Sophos;i="5.07,421,1413237600"; d="scan'208";a="271403251" Received: from hub1.rwth-ad.de (HELO mail.rwth-aachen.de) ([134.130.26.142]) by mx-2.rz.rwth-aachen.de with ESMTP; 20 Nov 2014 03:28:36 +0100 Received: from pebbles.de (134.61.101.25) by mail.rwth-aachen.de (134.130.26.142) with Microsoft SMTP Server (TLS) id 14.3.210.2; Thu, 20 Nov 2014 03:28:33 +0100 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= To: Subject: [PATCH 3/3] drm/edid: Tighten checksum conditions for CEA blocks Date: Thu, 20 Nov 2014 03:27:40 +0100 X-Mailer: git-send-email 2.1.2 In-Reply-To: <1416450460-3692-1-git-send-email-stefan.bruens@rwth-aachen.de> References: <1416103472-16923-1-git-send-email-stefan.bruens@rwth-aachen.de> <1416450460-3692-1-git-send-email-stefan.bruens@rwth-aachen.de> MIME-Version: 1.0 X-PMWin-Version: 3.1.3.0, Antivirus-Engine: 3.53.0, Antivirus-Data: 5.08 Message-ID: <75b98802-5906-49c2-8c04-9f613d328ec2@HUB1.rwth-ad.de> Cc: stefan.bruens@rwth-aachen.de X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Checksumming was disabled for CEA blocks by commit 4a638b4e38234233f5c7e6705662fbc0b58d80c2 Author: Adam Jackson 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 --- drivers/gpu/drm/drm_edid.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 3a10f3f..55963d5 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1203,6 +1203,7 @@ drm_do_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter) { 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) @@ -1233,12 +1234,27 @@ drm_do_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter) 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 (drm_do_probe_ddc_edid(adapter, ext_block, j, EDID_LENGTH)) goto out; - if (drm_edid_block_valid(ext_block, j, print_bad_edid)) { + csum = drm_edid_block_csum(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; } } @@ -1249,6 +1265,9 @@ drm_do_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter) connector->bad_edid_counter++; } + + kfree(saved_block); + saved_block = NULL; } if (valid_extensions != block[0x7e]) { @@ -1270,6 +1289,7 @@ carp: connector->bad_edid_counter++; out: + kfree(saved_block); kfree(block); return NULL; }