From patchwork Tue Mar 29 18:42:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12795172 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 61368C433F5 for ; Tue, 29 Mar 2022 18:42:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C737010E555; Tue, 29 Mar 2022 18:42:35 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3C5B610E4F2; Tue, 29 Mar 2022 18:42:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648579350; x=1680115350; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IawFGzewoI/wgYchdAT6tBttnoSfwlgiLKIghzsbea8=; b=m6Q55Iw7hvogDIf1LCJ0QINSxRTOSv4bV41Viv8yO5Z7Cgd5apBQN9za HDUWJNDBGPK5xLAKa9G/URACL8JouW3JW4kOPIqjPEV965eDyB4Y9ShL0 fS2bydJB5k841TMzXvP26zybwc0HSmprGDq2+esYrBl/D2bLxuTjiRmZn VFb6xnVNC4l1b+J1vx2QDmz7mgnUjT8y4wdQRtcfW4dX5+BMkjwntJlTa BrzeNP2Ujwj5Ve2qj8b/pwUGvGEPu20unwYJCj7f5zFZ0vAPQoHPPy39K HHC++NeDLFgDVdBx6EscWL8VAm/XEhnWA731BMM3qyRhRmHjlsW0cfLxG Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10301"; a="246827978" X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="246827978" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:42:30 -0700 X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="564858652" Received: from dmendyk-mobl.ger.corp.intel.com (HELO localhost) ([10.252.63.121]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:42:28 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Date: Tue, 29 Mar 2022 21:42:08 +0300 Message-Id: <380b903fb91b1e20a1a7af61db40b6c7c5617005.1648578814.git.jani.nikula@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Subject: [Intel-gfx] [PATCH 01/12] drm/edid: use struct edid * in drm_do_get_edid() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Mixing u8 * and struct edid * is confusing, switch to the latter. Cc: Ville Syrjälä Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index d79b06f7f34c..0650b9217aa2 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1991,29 +1991,28 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, void *data) { int i, j = 0, valid_extensions = 0; - u8 *edid, *new; - struct edid *override; + struct edid *edid, *new, *override; override = drm_get_override_edid(connector); if (override) return override; - edid = (u8 *)drm_do_get_edid_base_block(connector, get_edid_block, data); + edid = drm_do_get_edid_base_block(connector, get_edid_block, data); if (!edid) return NULL; /* if there's no extensions or no connector, we're done */ - valid_extensions = edid[0x7e]; + valid_extensions = edid->extensions; if (valid_extensions == 0) - return (struct edid *)edid; + return edid; new = krealloc(edid, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL); if (!new) goto out; edid = new; - for (j = 1; j <= edid[0x7e]; j++) { - u8 *block = edid + j * EDID_LENGTH; + for (j = 1; j <= edid->extensions; j++) { + void *block = edid + j; for (i = 0; i < 4; i++) { if (get_edid_block(data, block, j, EDID_LENGTH)) @@ -2026,13 +2025,13 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, valid_extensions--; } - if (valid_extensions != edid[0x7e]) { - u8 *base; + if (valid_extensions != edid->extensions) { + struct edid *base; - connector_bad_edid(connector, edid, edid[0x7e] + 1); + connector_bad_edid(connector, (u8 *)edid, edid->extensions + 1); - edid[EDID_LENGTH-1] += edid[0x7e] - valid_extensions; - edid[0x7e] = valid_extensions; + edid->checksum += edid->extensions - valid_extensions; + edid->extensions = valid_extensions; new = kmalloc_array(valid_extensions + 1, EDID_LENGTH, GFP_KERNEL); @@ -2040,21 +2039,21 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, goto out; base = new; - for (i = 0; i <= edid[0x7e]; i++) { - u8 *block = edid + i * EDID_LENGTH; + for (i = 0; i <= edid->extensions; i++) { + void *block = edid + i; if (!drm_edid_block_valid(block, i, false, NULL)) continue; memcpy(base, block, EDID_LENGTH); - base += EDID_LENGTH; + base++; } kfree(edid); edid = new; } - return (struct edid *)edid; + return edid; out: kfree(edid); From patchwork Tue Mar 29 18:42:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12795173 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1D3E7C433FE for ; Tue, 29 Mar 2022 18:42:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3D23A10E5A1; Tue, 29 Mar 2022 18:42:37 +0000 (UTC) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id B1D1010E4F3; Tue, 29 Mar 2022 18:42:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648579355; x=1680115355; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3RycmE4ovr1EMVNZ7h6DnLoZWXhNpYoq038PSWS3H6Q=; b=ApqLUauJiC6yz2jfL65/DgsftjaYJFP5nSeKxbTzQyyGRuLkI4zs8yBQ IU5x+3Zbk2o9Tup75nVWTXuEdAtdqZu1SIHUdarLl+eQlVhfW4HhyjPwI aDKgY3TIkrAH1QOaRnj/z53w+tb9zCe2zERpBzvGViZNBrQf+/SERt89W WVGvbskWLB3Mnv3eiLAPwMwhRFHLGg+6ChH0CLNJstfbnaT1FEO0Y2tXt B/YiFep0Wo/0lzClI0W4o9f5tuxGZs70LI8aL0L/Dbc72wHyFmUWmVvuU 7YcsBK21a2090Ul7XQUZiJ2t/sNJiNpFEkJNo2wHALC3xB2nYouih6wDk g==; X-IronPort-AV: E=McAfee;i="6200,9189,10301"; a="259521529" X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="259521529" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:42:35 -0700 X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="546510268" Received: from dmendyk-mobl.ger.corp.intel.com (HELO localhost) ([10.252.63.121]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:42:33 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Date: Tue, 29 Mar 2022 21:42:09 +0300 Message-Id: <91f2f89454a3c4220dd2afcea2f7455bfe70ada9.1648578814.git.jani.nikula@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Subject: [Intel-gfx] [PATCH 02/12] drm/edid: clean up EDID block checksum functions X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Have two clear functions, one to compute the checksum over the EDID, and another to get the checksum from the EDID. Throw away the diff function. Ditch the drm_ prefix for static functions, and accept const void * to help transition to struct edid * usage. Cc: Ville Syrjälä Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 0650b9217aa2..73f05e0363c0 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1597,25 +1597,25 @@ module_param_named(edid_fixup, edid_fixup, int, 0400); MODULE_PARM_DESC(edid_fixup, "Minimum number of valid EDID header bytes (0-8, default 6)"); -static int drm_edid_block_checksum(const u8 *raw_edid) +static int edid_block_compute_checksum(const void *_block) { + const u8 *block = _block; int i; u8 csum = 0, crc = 0; for (i = 0; i < EDID_LENGTH - 1; i++) - csum += raw_edid[i]; + csum += block[i]; crc = 0x100 - csum; return crc; } -static bool drm_edid_block_checksum_diff(const u8 *raw_edid, u8 real_checksum) +static int edid_block_get_checksum(const void *_block) { - if (raw_edid[EDID_LENGTH - 1] != real_checksum) - return true; - else - return false; + const struct edid *block = _block; + + return block->checksum; } static bool drm_edid_is_zero(const u8 *in_edid, int length) @@ -1704,8 +1704,8 @@ bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid, } } - csum = drm_edid_block_checksum(raw_edid); - if (drm_edid_block_checksum_diff(raw_edid, csum)) { + csum = edid_block_compute_checksum(raw_edid); + if (csum != edid_block_get_checksum(raw_edid)) { if (edid_corrupt) *edid_corrupt = true; @@ -1859,7 +1859,7 @@ static void connector_bad_edid(struct drm_connector *connector, /* Calculate real checksum for the last edid extension block data */ if (last_block < num_blocks) connector->real_edid_checksum = - drm_edid_block_checksum(edid + last_block * EDID_LENGTH); + edid_block_compute_checksum(edid + last_block * EDID_LENGTH); if (connector->bad_edid_counter++ && !drm_debug_enabled(DRM_UT_KMS)) return; From patchwork Tue Mar 29 18:42:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12795174 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3890CC433EF for ; Tue, 29 Mar 2022 18:42:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A3F5110E66C; Tue, 29 Mar 2022 18:42:44 +0000 (UTC) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1DB4C10E4F3; Tue, 29 Mar 2022 18:42:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648579360; x=1680115360; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=P+cGMuT1NpJwOQ0o3PAvSvjJP0jvql8YfL4ujjnOAXs=; b=D/vrVZ6KAnV9wQFeQAPaGLnwVy14GboYCbrXGFgDAfTQtb47P2fVlDw0 tuIG0qgamqgIhYMy/DaEhoTeKMvtaarnlQ83gFb/uyPbbsE1TKXEUBeff P1bwX4cy1Sp0mr0ZH60zUXp7cf4J/rRe6du8qmKJAnQhhNrtvGUMMVmdC bA1DfaGkC8iN+rU2xGCnb/qBBJwTd6Tg7Didok0peimq0Sh9h7deQiSBY /4BjnGFdQQMB7P416tnE/hQD4EUafW6bvlm3unfA9Dm/kVuKnhlxozxcD /kMqjQlvm1EYYVs72kGYQkuk/+eK3PMRFadACGmEDrXE9IQyEJ96Qp4ML A==; X-IronPort-AV: E=McAfee;i="6200,9189,10301"; a="259521544" X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="259521544" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:42:39 -0700 X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="546510304" Received: from dmendyk-mobl.ger.corp.intel.com (HELO localhost) ([10.252.63.121]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:42:37 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Date: Tue, 29 Mar 2022 21:42:10 +0300 Message-Id: <506aa8486c7dedf68f2c0d5a3b2d7388a1ab5610.1648578814.git.jani.nikula@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Subject: [Intel-gfx] [PATCH 03/12] drm/edid: add edid_block_tag() helper to get the EDID extension tag X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" The extension tag at offset 0 is not present in struct edid, add a helper for it to reduce the need to use u8 *. Cc: Ville Syrjälä Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 73f05e0363c0..95f0303bc63e 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1618,6 +1618,13 @@ static int edid_block_get_checksum(const void *_block) return block->checksum; } +static int edid_block_tag(const void *_block) +{ + const u8 *block = _block; + + return block[0]; +} + static bool drm_edid_is_zero(const u8 *in_edid, int length) { if (memchr_inv(in_edid, 0, length)) @@ -1710,7 +1717,7 @@ bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid, *edid_corrupt = true; /* allow CEA to slide through, switches mangle this */ - if (raw_edid[0] == CEA_EXT) { + if (edid_block_tag(raw_edid) == CEA_EXT) { DRM_DEBUG("EDID checksum is invalid, remainder is %d\n", csum); DRM_DEBUG("Assuming a KVM switch modified the CEA block but left the original checksum\n"); } else { @@ -1722,7 +1729,7 @@ bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid, } /* per-block-type checks */ - switch (raw_edid[0]) { + switch (edid_block_tag(raw_edid)) { case 0: /* base */ if (edid->version != 1) { DRM_NOTE("EDID has major version %d, instead of 1\n", edid->version); @@ -3366,7 +3373,7 @@ const u8 *drm_find_edid_extension(const struct edid *edid, /* Find CEA extension */ for (i = *ext_index; i < edid->extensions; i++) { edid_ext = (const u8 *)edid + EDID_LENGTH * (i + 1); - if (edid_ext[0] == ext_id) + if (edid_block_tag(edid_ext) == ext_id) break; } From patchwork Tue Mar 29 18:42:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12795175 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A7DCEC433F5 for ; Tue, 29 Mar 2022 18:42:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0D4FF10E6CE; Tue, 29 Mar 2022 18:42:47 +0000 (UTC) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id 59F7A10E6D5; Tue, 29 Mar 2022 18:42:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648579365; x=1680115365; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KgThcknXaTTQ1EGu621Q0QOsXxvGZn/fdQgmHfakQMU=; b=V+UBNZUfMcJqYkAzj0m01OmQdPIf6mc0XBUDB8CMtskyrVyrZ8gGZmcY eCa9a0WMQJELcxZI355fbaeeNBRqTQLJ7jkV2AHqhQXH6k8sgY2DX9itd KqAo7dnhgsoF4od4jcslOJqzbp5v96rgdy6AF41Hj9b0pciDVl4Pjer1B VtflwtfArVt415IxlsBZJbYXlRuYGyIhRo5NJicZjk3LUJfkrmQikGPhZ Eex2GDHzxjQ/u+qj4AXM+WfgAozS27w1c2TGNYl9P5sBqX4cuzzEYDy1E 5A4jk3lGmBpyLpv8vPi4G0kiRu2P4W18buia4PjdvN5b7y2Raltcbr3et A==; X-IronPort-AV: E=McAfee;i="6200,9189,10301"; a="259307863" X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="259307863" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:42:44 -0700 X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="521557943" Received: from dmendyk-mobl.ger.corp.intel.com (HELO localhost) ([10.252.63.121]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:42:42 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Date: Tue, 29 Mar 2022 21:42:11 +0300 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Subject: [Intel-gfx] [PATCH 04/12] drm/edid: make drm_edid_header_is_valid() accept void pointer X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" It will be useful to accept a struct edid *, but for compatibility with existing usage accept void *. Cc: Ville Syrjälä Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 8 +++++--- include/drm/drm_edid.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 95f0303bc63e..b5b21b50e476 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1580,13 +1580,15 @@ static const u8 edid_header[] = { * * Return: 8 if the header is perfect, down to 0 if it's totally wrong. */ -int drm_edid_header_is_valid(const u8 *raw_edid) +int drm_edid_header_is_valid(const void *_edid) { + const struct edid *edid = _edid; int i, score = 0; - for (i = 0; i < sizeof(edid_header); i++) - if (raw_edid[i] == edid_header[i]) + for (i = 0; i < sizeof(edid_header); i++) { + if (edid->header[i] == edid_header[i]) score++; + } return score; } diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index 48b1bf9c315a..b7e170584000 100644 --- a/include/drm/drm_edid.h +++ b/include/drm/drm_edid.h @@ -578,7 +578,7 @@ int drm_add_modes_noedid(struct drm_connector *connector, void drm_set_preferred_mode(struct drm_connector *connector, int hpref, int vpref); -int drm_edid_header_is_valid(const u8 *raw_edid); +int drm_edid_header_is_valid(const void *edid); bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid, bool *edid_corrupt); bool drm_edid_is_valid(struct edid *edid); From patchwork Tue Mar 29 18:42:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12795176 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 91CE8C433F5 for ; Tue, 29 Mar 2022 18:42:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0FEF510E5E6; Tue, 29 Mar 2022 18:42:52 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 607ED10E60A; Tue, 29 Mar 2022 18:42:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648579370; x=1680115370; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Kh2KS7UaT0XDUFCWdzs353K2T03bjA1CfSlyh2iV9j8=; b=PZKZ4R+gS6xk0K9ew3kvnGTg3yax5TkuhlvW/Glqsm72R1QcgtMssRZ3 XnU4S4CD/tY36IElGH18pciqCX+WTGLOErRyAhjaLWO6UQmkrsPv39YIY 5rG6PLB7HOnIYKhAJqkSagqLGaPJeV0k2+s/+WAVhENZ3EiSVCeZ+x4je BZDoGzcqPEmcw3cU2UlMlJ8Vub7h9wr+/FsI4vyB6rfr2Ss5FSVVrkPDS B2xJ71n7qmuV6jn+KnXJfqmApTycmplLZKuk2yTjkOV83pSOIwPW3KC1N pIfzaIhTQfRZbc0AFiRACzFREyb/GHAOIdc21AeAmbN+qWuAroIDOY/zP g==; X-IronPort-AV: E=McAfee;i="6200,9189,10301"; a="258163719" X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="258163719" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:42:49 -0700 X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="719650406" Received: from dmendyk-mobl.ger.corp.intel.com (HELO localhost) ([10.252.63.121]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:42:47 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Date: Tue, 29 Mar 2022 21:42:12 +0300 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Subject: [Intel-gfx] [PATCH 05/12] drm/edid: clean up edid_is_zero() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Simplify, rename, take void pointer. No need for the drm_ prefix for internal helpers. Cc: Ville Syrjälä Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index b5b21b50e476..422db8ae0ac1 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1627,12 +1627,9 @@ static int edid_block_tag(const void *_block) return block[0]; } -static bool drm_edid_is_zero(const u8 *in_edid, int length) +static bool edid_is_zero(const void *edid, int length) { - if (memchr_inv(in_edid, 0, length)) - return false; - - return true; + return !memchr_inv(edid, 0, length); } /** @@ -1750,7 +1747,7 @@ bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid, bad: if (print_bad_edid) { - if (drm_edid_is_zero(raw_edid, EDID_LENGTH)) { + if (edid_is_zero(raw_edid, EDID_LENGTH)) { pr_notice("EDID block is all zeroes\n"); } else { pr_notice("Raw EDID:\n"); @@ -1878,7 +1875,7 @@ static void connector_bad_edid(struct drm_connector *connector, u8 *block = edid + i * EDID_LENGTH; char prefix[20]; - if (drm_edid_is_zero(block, EDID_LENGTH)) + if (edid_is_zero(block, EDID_LENGTH)) sprintf(prefix, "\t[%02x] ZERO ", i); else if (!drm_edid_block_valid(block, i, false, NULL)) sprintf(prefix, "\t[%02x] BAD ", i); @@ -1955,7 +1952,7 @@ static struct edid *drm_do_get_edid_base_block(struct drm_connector *connector, goto out; if (drm_edid_block_valid(edid, 0, false, edid_corrupt)) break; - if (i == 0 && drm_edid_is_zero(edid, EDID_LENGTH)) { + if (i == 0 && edid_is_zero(edid, EDID_LENGTH)) { if (null_edid_counter) (*null_edid_counter)++; goto carp; From patchwork Tue Mar 29 18:42:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12795191 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 71EFEC433EF for ; Tue, 29 Mar 2022 18:43:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0302B10E6E9; Tue, 29 Mar 2022 18:43:01 +0000 (UTC) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9F1CB10E8A6; Tue, 29 Mar 2022 18:42:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648579374; x=1680115374; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VqXJmAw+gWYqx8dPtvcyNNk4CkGCYM1KBOisovvYHug=; b=MC+AA2l5bmoaublaTBTD41ySlLj1i/K/R9NsPykz28s1wwxM4TsmoMx1 YxfAjWKmCRt33lq1UfKS2Qg8IsHUp70nX0eJ7+np+5zlyDURG2CYOS2uw i5p0NtiBPRvshWrc05i7PeQaWagJTnQ+YGTGnWi1zD7Gr5GMyqFrWujLu X6eeCRCN1yK9wKg6RhiDhxTa2bJRyO2/MgGll0KRQfsEODaYHO0PMfwJu d2NG6gbNtV//idsYaNTNPIBZh5krHRmJ+fXry0fTc94GI8mtEpGGLj16c jO/wi2B60UZn0BZQtJ/lIgOVf/z8aXdO3o7p77t6uNQlGliCMATY3kVkZ A==; X-IronPort-AV: E=McAfee;i="6200,9189,10301"; a="259521600" X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="259521600" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:42:54 -0700 X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="653180691" Received: from dmendyk-mobl.ger.corp.intel.com (HELO localhost) ([10.252.63.121]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:42:52 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Date: Tue, 29 Mar 2022 21:42:13 +0300 Message-Id: <10c82b8582d8a706e0aaa9f24793b4c0861ac5c2.1648578814.git.jani.nikula@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Subject: [Intel-gfx] [PATCH 06/12] drm/edid: split out edid_header_fix() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Give a name to the EDID header fixup instead of having an inline memcpy. Cc: Ville Syrjälä Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 422db8ae0ac1..481643751d10 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1572,6 +1572,11 @@ static const u8 edid_header[] = { 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }; +static void edid_header_fix(void *edid) +{ + memcpy(edid, edid_header, sizeof(edid_header)); +} + /** * drm_edid_header_is_valid - sanity check the header of the base EDID block * @raw_edid: pointer to raw base EDID block @@ -1702,7 +1707,7 @@ bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid, if (edid_corrupt) *edid_corrupt = true; DRM_DEBUG("Fixing EDID header, your hardware may be failing\n"); - memcpy(raw_edid, edid_header, sizeof(edid_header)); + edid_header_fix(raw_edid); } else { if (edid_corrupt) *edid_corrupt = true; From patchwork Tue Mar 29 18:42:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12795192 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 10C88C433FE for ; Tue, 29 Mar 2022 18:43:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 659BB10E6F1; Tue, 29 Mar 2022 18:43:01 +0000 (UTC) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 741E910E6E9; Tue, 29 Mar 2022 18:42:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648579379; x=1680115379; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ShrDci8c/RvwqsE5LQt8r+aKymEQdgM83w3I8fsDIXw=; b=Bb/5b7Tf65rjfxaq+y5Rq43/v2UTtfFGda5TurUwKHcFzqQlSYllkwU/ v+GoSoS1yA1mi6+4C1QPGRnWw3HEcZi4xFisTA4nD2poWaGc4NDdR8qK5 b/ojYQCwezCx9e4XutolKKCcrY4wxMSy3xYZTmR9Ouz3/fUvgzVaXq8ov dsVdCWz04kk2V1BC67dgWWzbp9BEtrESkrIIpXs6mfWS3Fi5CQ0Cw5kup vzxIQsbXCtNNslXF/1HJthRkzrW5xWSA3zOX6pnGSkZmpvUydLirZcjrA Q2veKbDyMxIAnCagRYVlYlQ5PuoA0wwakHH+QWs/iOdMTwNlSX1ppAEFH A==; X-IronPort-AV: E=McAfee;i="6200,9189,10301"; a="239266667" X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="239266667" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:42:58 -0700 X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="503000508" Received: from dmendyk-mobl.ger.corp.intel.com (HELO localhost) ([10.252.63.121]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:42:56 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Date: Tue, 29 Mar 2022 21:42:14 +0300 Message-Id: <296443a99ce907b11d08ddc88407aa35d9bdc5a3.1648578814.git.jani.nikula@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Subject: [Intel-gfx] [PATCH 07/12] drm/edid: split drm_edid_block_valid() to check and act parts X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Add edid_block_check() that only checks the EDID block validity, without any actions. Turns out it's simple and crystal clear. Rewrite drm_edid_block_valid() around it, keeping all the functionality fairly closely the same, warts and all. Turns out it's incredibly complicated for a function you'd expect to be simple, with all the fixing and printing and special casing. (Maybe we'll want to simplify it in the future.) Cc: Ville Syrjälä Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 150 ++++++++++++++++++++++--------------- 1 file changed, 88 insertions(+), 62 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 481643751d10..04eb6949c9c8 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1668,10 +1668,55 @@ bool drm_edid_are_equal(const struct edid *edid1, const struct edid *edid2) } EXPORT_SYMBOL(drm_edid_are_equal); +enum edid_block_status { + EDID_BLOCK_OK = 0, + EDID_BLOCK_NULL, + EDID_BLOCK_HEADER_CORRUPT, + EDID_BLOCK_HEADER_REPAIR, + EDID_BLOCK_HEADER_FIXED, + EDID_BLOCK_CHECKSUM, + EDID_BLOCK_VERSION, +}; + +static enum edid_block_status edid_block_check(const void *_block, bool base) +{ + const struct edid *block = _block; + + if (!block) + return EDID_BLOCK_NULL; + + if (base) { + int score = drm_edid_header_is_valid(block); + + if (score < clamp(edid_fixup, 6, 8)) + return EDID_BLOCK_HEADER_CORRUPT; + + if (score < 8) + return EDID_BLOCK_HEADER_REPAIR; + } + + if (edid_block_compute_checksum(block) != edid_block_get_checksum(block)) + return EDID_BLOCK_CHECKSUM; + + if (base) { + if (block->version != 1) + return EDID_BLOCK_VERSION; + } + + return EDID_BLOCK_OK; +} + +static bool edid_block_status_valid(enum edid_block_status status, int tag) +{ + return status == EDID_BLOCK_OK || + status == EDID_BLOCK_HEADER_FIXED || + (status == EDID_BLOCK_CHECKSUM && tag == CEA_EXT); +} + /** * drm_edid_block_valid - Sanity check the EDID block (base or extension) * @raw_edid: pointer to raw EDID block - * @block: type of block to validate (0 for base, extension otherwise) + * @block_num: type of block to validate (0 for base, extension otherwise) * @print_bad_edid: if true, dump bad EDID blocks to the console * @edid_corrupt: if true, the header or checksum is invalid * @@ -1680,88 +1725,69 @@ EXPORT_SYMBOL(drm_edid_are_equal); * * Return: True if the block is valid, false otherwise. */ -bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid, +bool drm_edid_block_valid(u8 *_block, int block_num, bool print_bad_edid, bool *edid_corrupt) { - u8 csum; - struct edid *edid = (struct edid *)raw_edid; + struct edid *block = (struct edid *)_block; + enum edid_block_status status; + bool base = block_num == 0; + bool valid; - if (WARN_ON(!raw_edid)) + if (WARN_ON(!block)) return false; - if (edid_fixup > 8 || edid_fixup < 0) - edid_fixup = 6; - - if (block == 0) { - int score = drm_edid_header_is_valid(raw_edid); + status = edid_block_check(block, base); + if (status == EDID_BLOCK_HEADER_REPAIR) { + DRM_DEBUG("Fixing EDID header, your hardware may be failing\n"); + edid_header_fix(block); - if (score == 8) { - if (edid_corrupt) - *edid_corrupt = false; - } else if (score >= edid_fixup) { - /* Displayport Link CTS Core 1.2 rev1.1 test 4.2.2.6 - * The corrupt flag needs to be set here otherwise, the - * fix-up code here will correct the problem, the - * checksum is correct and the test fails - */ - if (edid_corrupt) - *edid_corrupt = true; - DRM_DEBUG("Fixing EDID header, your hardware may be failing\n"); - edid_header_fix(raw_edid); - } else { - if (edid_corrupt) - *edid_corrupt = true; - goto bad; - } + /* Retry with fixed header, update status if that worked. */ + status = edid_block_check(block, base); + if (status == EDID_BLOCK_OK) + status = EDID_BLOCK_HEADER_FIXED; } - csum = edid_block_compute_checksum(raw_edid); - if (csum != edid_block_get_checksum(raw_edid)) { - if (edid_corrupt) + if (edid_corrupt) { + /* + * Unknown major version isn't corrupt but we can't use it. Only + * the base block can reset edid_corrupt to false. + */ + if (base && (status == EDID_BLOCK_OK || status == EDID_BLOCK_VERSION)) + *edid_corrupt = false; + else if (status != EDID_BLOCK_OK) *edid_corrupt = true; - - /* allow CEA to slide through, switches mangle this */ - if (edid_block_tag(raw_edid) == CEA_EXT) { - DRM_DEBUG("EDID checksum is invalid, remainder is %d\n", csum); - DRM_DEBUG("Assuming a KVM switch modified the CEA block but left the original checksum\n"); - } else { - if (print_bad_edid) - DRM_NOTE("EDID checksum is invalid, remainder is %d\n", csum); - - goto bad; - } } - /* per-block-type checks */ - switch (edid_block_tag(raw_edid)) { - case 0: /* base */ - if (edid->version != 1) { - DRM_NOTE("EDID has major version %d, instead of 1\n", edid->version); - goto bad; + /* Determine whether we can use this block with this status. */ + valid = edid_block_status_valid(status, edid_block_tag(block)); + + /* Some fairly random status printouts. */ + if (status == EDID_BLOCK_CHECKSUM) { + if (valid) { + DRM_DEBUG("EDID block checksum is invalid, remainder is %d\n", + edid_block_compute_checksum(block)); + DRM_DEBUG("Assuming a KVM switch modified the block but left the original checksum\n"); + } else if (print_bad_edid) { + DRM_NOTE("EDID block checksum is invalid, remainder is %d\n", + edid_block_compute_checksum(block)); } - - if (edid->revision > 4) - DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n"); - break; - - default: - break; + } else if (status == EDID_BLOCK_VERSION) { + DRM_NOTE("EDID has major version %d, instead of 1\n", + block->version); } - return true; - -bad: - if (print_bad_edid) { - if (edid_is_zero(raw_edid, EDID_LENGTH)) { + if (!valid && print_bad_edid) { + if (edid_is_zero(block, EDID_LENGTH)) { pr_notice("EDID block is all zeroes\n"); } else { pr_notice("Raw EDID:\n"); print_hex_dump(KERN_NOTICE, " \t", DUMP_PREFIX_NONE, 16, 1, - raw_edid, EDID_LENGTH, false); + block, EDID_LENGTH, false); } } - return false; + + return valid; } EXPORT_SYMBOL(drm_edid_block_valid); From patchwork Tue Mar 29 18:42:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12795193 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5266AC433F5 for ; Tue, 29 Mar 2022 18:43:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C3EDB10E901; Tue, 29 Mar 2022 18:43:05 +0000 (UTC) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9F4F210E8A7; Tue, 29 Mar 2022 18:43:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648579383; x=1680115383; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=j4w2x7VTlOWm3C85HcLw4Z4iMsKmMJNxi9NS2aMcyRo=; b=cHyBDWOwvg/KhTgocvpDMMzBAR0ZVqy3mCeqedyIWZf0+gKBlxsKy+PV ZqNMt2UOWyeMsOXOFy/Cfc3ItdGH1Lf3F9VSq5YC3d7gxnY0IUFpIO9dY FCbJnlCCojWoZr+zoTrNX0YOcOa5aJhTUvnSxz4shie1RnJlRH117AIsg VPikqHp/rsq3Qq6tosgdwKTpriYin7Q6bh+w4m3R440xNjhyeVg6t9hIE nqfl0NEHizU6AMxmve63BhNW3Ln4GNt4Rusr2mOUKK3FB9yhwAfXUuHaZ D9FThuFXKDGKF4S96tqdpokzgixiNwx5wTTQbUVVl5aLtuRxZ0RIYK93z Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10301"; a="259521642" X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="259521642" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:43:02 -0700 X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="519128451" Received: from dmendyk-mobl.ger.corp.intel.com (HELO localhost) ([10.252.63.121]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:43:01 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Date: Tue, 29 Mar 2022 21:42:15 +0300 Message-Id: <5debef4cc1415504067e4fd69cd7be96f7077e06.1648578814.git.jani.nikula@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Subject: [Intel-gfx] [PATCH 08/12] drm/edid: use a better variable name for EDID block read retries X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Just i is a bit terse, clarify what it's about. Cc: Ville Syrjälä Signed-off-by: Jani Nikula Reviewed-by: Ville Syrjälä --- drivers/gpu/drm/drm_edid.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 04eb6949c9c8..235d3cde2e97 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1971,25 +1971,25 @@ static struct edid *drm_do_get_edid_base_block(struct drm_connector *connector, int *null_edid_counter = connector ? &connector->null_edid_counter : NULL; bool *edid_corrupt = connector ? &connector->edid_corrupt : NULL; void *edid; - int i; + int try; edid = kmalloc(EDID_LENGTH, GFP_KERNEL); if (edid == NULL) return NULL; /* base block fetch */ - for (i = 0; i < 4; i++) { + for (try = 0; try < 4; try++) { if (get_edid_block(data, edid, 0, EDID_LENGTH)) goto out; if (drm_edid_block_valid(edid, 0, false, edid_corrupt)) break; - if (i == 0 && edid_is_zero(edid, EDID_LENGTH)) { + if (try == 0 && edid_is_zero(edid, EDID_LENGTH)) { if (null_edid_counter) (*null_edid_counter)++; goto carp; } } - if (i == 4) + if (try == 4) goto carp; return edid; @@ -2027,7 +2027,7 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, size_t len), void *data) { - int i, j = 0, valid_extensions = 0; + int j, valid_extensions = 0; struct edid *edid, *new, *override; override = drm_get_override_edid(connector); @@ -2050,20 +2050,22 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, for (j = 1; j <= edid->extensions; j++) { void *block = edid + j; + int try; - for (i = 0; i < 4; i++) { + for (try = 0; try < 4; try++) { if (get_edid_block(data, block, j, EDID_LENGTH)) goto out; if (drm_edid_block_valid(block, j, false, NULL)) break; } - if (i == 4) + if (try == 4) valid_extensions--; } if (valid_extensions != edid->extensions) { struct edid *base; + int i; connector_bad_edid(connector, (u8 *)edid, edid->extensions + 1); From patchwork Tue Mar 29 18:42:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12795194 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 419D3C433F5 for ; Tue, 29 Mar 2022 18:43:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AEFC610E4EE; Tue, 29 Mar 2022 18:43:09 +0000 (UTC) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3709210E8A6; Tue, 29 Mar 2022 18:43:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648579388; x=1680115388; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eXgz2+gEsm3mvGtsWikpA1BanAbpn7y+ylqYifprRnU=; b=cIorL3HyrW1ShTiUzLaFN4NtN5b156y/9dCyaFFHppxHlTXu9iakfWrr valqTGR8/vftKkDOODXXNfnYJKy2ydwihM/X8P1manayBqfprm86WdhfV hcHUeULBpQRNirCR1qtCpmXMkq5kuIkx3Vzpu65yGwASON8RHHn7lSngX Q7Kdq5KHni+R71rrGYZtM/FAwrSxzHBVk+4ZceRgColpYL/4OfQaCK7p4 wtqC5Ky2CjtKFis/Fc8sNW6UI6H2W9c/9bxMKHcmfag2Snv/7S+dZmZHy cBAXaJHRxzgR0wONjN42fJkZfxOCreu2DpqTyvAmVdJmF2fxVRZkWFgfZ Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10301"; a="256912743" X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="256912743" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:43:07 -0700 X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="521558061" Received: from dmendyk-mobl.ger.corp.intel.com (HELO localhost) ([10.252.63.121]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:43:05 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Date: Tue, 29 Mar 2022 21:42:16 +0300 Message-Id: <40bbdfa892243e6602a8ba79418713c6c8d6fd07.1648578814.git.jani.nikula@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Subject: [Intel-gfx] [PATCH 09/12] drm/edid: simplify block check when filtering invalid blocks X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" There's no need to handle complicated scenarios or debug log when filtering blocks that have already been identified as invalid. Simplify by adding an edid_block_valid() helper that operates on const data and prints nothing. (Finally, here's the justification for the previously added separate edid_block_status_valid() function!) Cc: Ville Syrjälä Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 235d3cde2e97..a1be5c3a80e5 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1713,6 +1713,12 @@ static bool edid_block_status_valid(enum edid_block_status status, int tag) (status == EDID_BLOCK_CHECKSUM && tag == CEA_EXT); } +static bool edid_block_valid(const void *block, bool base) +{ + return edid_block_status_valid(edid_block_check(block, base), + edid_block_tag(block)); +} + /** * drm_edid_block_valid - Sanity check the EDID block (base or extension) * @raw_edid: pointer to raw EDID block @@ -2081,7 +2087,7 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, for (i = 0; i <= edid->extensions; i++) { void *block = edid + i; - if (!drm_edid_block_valid(block, i, false, NULL)) + if (!edid_block_valid(block, i == 0)) continue; memcpy(base, block, EDID_LENGTH); From patchwork Tue Mar 29 18:42:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12795195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8FBBEC433F5 for ; Tue, 29 Mar 2022 18:43:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1C6E110EE4E; Tue, 29 Mar 2022 18:43:26 +0000 (UTC) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id D1E6510E8A6; Tue, 29 Mar 2022 18:43:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648579393; x=1680115393; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=U5xS+XlqX8sY8sxm2AG/pE2+YgdTmUM6gq2p8jTqfKw=; b=VsbYm+tMOT5gxTn3QcyNNvpmvNTTKQ5EIZKgEUBYNWPE5I8TvZEi5wB7 0Mz2+IqHs9126/w2seh6I5eBKtRLlBmsAq+l2nFRcjTVj3Ye735vgVVr/ 6+O9Ga9f0t5AepaiN/jEFlAr5V83JvkncxCMVudEeXX5Xjj9MaiVSLYUD NCR0S0tj3SglMu+jmrOAZ7xVWWEuEr37J9m69byFhqOD+mmzF9q23bhnp Uedh50XKRXT5s9Y83+q1T0IDTunQ1jidFEv4Nb44E7S0cnEHe65dHIBtS VptZwiJf6IzqbzVevcJH3RUyjRXkDYXMbBQ5aJ0dnQjTKmxNGghgETlrg A==; X-IronPort-AV: E=McAfee;i="6200,9189,10301"; a="320034326" X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="320034326" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:43:12 -0700 X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="719650555" Received: from dmendyk-mobl.ger.corp.intel.com (HELO localhost) ([10.252.63.121]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:43:10 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Date: Tue, 29 Mar 2022 21:42:17 +0300 Message-Id: <04d5ad0bbb43267f32312bccbab8a1f4c80565a1.1648578814.git.jani.nikula@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Subject: [Intel-gfx] [PATCH 10/12] drm/edid: split out invalid block filtering to a separate function X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" It's such a special case there's no point in keeping it inline in the happy day scenario, confusing matters. Cc: Ville Syrjälä Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 52 ++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index a1be5c3a80e5..dee95332d7e1 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1821,6 +1821,33 @@ bool drm_edid_is_valid(struct edid *edid) } EXPORT_SYMBOL(drm_edid_is_valid); +static struct edid *edid_filter_invalid_blocks(const struct edid *edid, + int valid_extensions) +{ + struct edid *new, *base; + int i; + + new = kmalloc_array(valid_extensions + 1, EDID_LENGTH, GFP_KERNEL); + if (!new) + goto out; + + base = new; + for (i = 0; i <= edid->extensions; i++) { + const void *block = edid + i; + + if (edid_block_valid(block, i == 0)) + memcpy(base++, block, EDID_LENGTH); + } + + new->checksum += new->extensions - valid_extensions; + new->extensions = valid_extensions; + +out: + kfree(edid); + + return new; +} + #define DDC_SEGMENT_ADDR 0x30 /** * drm_do_probe_ddc_edid() - get EDID information via I2C @@ -2070,32 +2097,9 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, } if (valid_extensions != edid->extensions) { - struct edid *base; - int i; - connector_bad_edid(connector, (u8 *)edid, edid->extensions + 1); - edid->checksum += edid->extensions - valid_extensions; - edid->extensions = valid_extensions; - - new = kmalloc_array(valid_extensions + 1, EDID_LENGTH, - GFP_KERNEL); - if (!new) - goto out; - - base = new; - for (i = 0; i <= edid->extensions; i++) { - void *block = edid + i; - - if (!edid_block_valid(block, i == 0)) - continue; - - memcpy(base, block, EDID_LENGTH); - base++; - } - - kfree(edid); - edid = new; + edid = edid_filter_invalid_blocks(edid, valid_extensions); } return edid; From patchwork Tue Mar 29 18:42:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12795197 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B7322C433FE for ; Tue, 29 Mar 2022 18:43:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F289010EE50; Tue, 29 Mar 2022 18:43:27 +0000 (UTC) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id EA29410E8A7; Tue, 29 Mar 2022 18:43:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648579398; x=1680115398; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CWMsp6PMtY3HPqRPU8nhVENH4x5YiXre/xgjmr31Nbo=; b=fLSi3hdWowZDVjJ8yuto9GTegJIBxCb99/0Ua1ys1e2w7/cbJmX7yWie 3rLM1j+wgryak5cs3AqEy9L+0yebJ7RNBRT0raPpPGSPDiTnE/fI/YCVU TlrOgqcZ9/EntPCu6X42weGR9NBQk35xgu0i3sYEapbw8gEfZwvCUulX6 yNDWLH0vdBByV2QbIo/T1Omnt1m3RDCqM8XJpgothiIDlKuexIPoFCrze 63QlNthZ9lAY39zm0s2S9zvREHyR8hdLXjR03SMX21c8taM3SGhjChYXe LWsiGR88t0J2Yz885swiIWs73CYqe+r8WqDgkYo4W2oGDLbZmYyLNaccP g==; X-IronPort-AV: E=McAfee;i="6200,9189,10301"; a="322518379" X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="322518379" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:43:16 -0700 X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="585694743" Received: from dmendyk-mobl.ger.corp.intel.com (HELO localhost) ([10.252.63.121]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:43:14 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Date: Tue, 29 Mar 2022 21:42:18 +0300 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Subject: [Intel-gfx] [PATCH 11/12] drm/edid: track invalid blocks in drm_do_get_edid() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Track invalid blocks instead of valid extensions to minimize impact on the happy day scenario, and hide the details in the separate function. Cc: Ville Syrjälä Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index dee95332d7e1..d0a76781ed19 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1822,9 +1822,10 @@ bool drm_edid_is_valid(struct edid *edid) EXPORT_SYMBOL(drm_edid_is_valid); static struct edid *edid_filter_invalid_blocks(const struct edid *edid, - int valid_extensions) + int invalid_blocks) { struct edid *new, *base; + int valid_extensions = edid->extensions - invalid_blocks; int i; new = kmalloc_array(valid_extensions + 1, EDID_LENGTH, GFP_KERNEL); @@ -2060,7 +2061,7 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, size_t len), void *data) { - int j, valid_extensions = 0; + int j, invalid_blocks = 0; struct edid *edid, *new, *override; override = drm_get_override_edid(connector); @@ -2071,12 +2072,10 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, if (!edid) return NULL; - /* if there's no extensions or no connector, we're done */ - valid_extensions = edid->extensions; - if (valid_extensions == 0) + if (edid->extensions == 0) return edid; - new = krealloc(edid, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL); + new = krealloc(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL); if (!new) goto out; edid = new; @@ -2093,13 +2092,13 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, } if (try == 4) - valid_extensions--; + invalid_blocks++; } - if (valid_extensions != edid->extensions) { + if (invalid_blocks) { connector_bad_edid(connector, (u8 *)edid, edid->extensions + 1); - edid = edid_filter_invalid_blocks(edid, valid_extensions); + edid = edid_filter_invalid_blocks(edid, invalid_blocks); } return edid; From patchwork Tue Mar 29 18:42:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12795196 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D5ECBC433EF for ; Tue, 29 Mar 2022 18:43:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5DC6C10E555; Tue, 29 Mar 2022 18:43:27 +0000 (UTC) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6DB5D10EE4B; Tue, 29 Mar 2022 18:43:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648579401; x=1680115401; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AFETZEz5P2/j5Fp8KX76zGzvbKtMTCY7DmnZDIqTVGk=; b=U45YuGg0m+WcLMlLNYMoMvC9I0sWFOKnbWRPiE7yYVes6w4T7ZtZ901/ +6XUJJTple5BYH7vxoqxpanEW4SaUvissHFpl2rxuoHQR0JPjVdLYXNcV 4Ilbs4RmiJU9daVsgXfJ4jf4FIeT+MC3aPoBUOESt6vbG3S74Nk9+pugB AIEv3XpntEIjZKeoVjRSjL5LrjDHXKrZy8vSkAgLeGuzCO79LSbo6bNXH lSkRGU7m11TyBr0vf0ipISVl7ex8mjnXuiZjGiWlNI7HJ3whKdLQ0gKed LQpjxOnJ211d4GtJ1SSyEuiBLKfy9W4FzxC5LmSTyNMYkT2d1C0eHtMHk g==; X-IronPort-AV: E=McAfee;i="6200,9189,10301"; a="256912797" X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="256912797" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:43:21 -0700 X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="653180941" Received: from dmendyk-mobl.ger.corp.intel.com (HELO localhost) ([10.252.63.121]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 11:43:19 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Date: Tue, 29 Mar 2022 21:42:19 +0300 Message-Id: <0ec68aa82b4be2d46e442e74e341419d10c4c41b.1648578814.git.jani.nikula@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Subject: [Intel-gfx] [PATCH 12/12] drm/edid: reduce magic when updating the EDID block checksum X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" The code modifying the EDID block should not need to do tricks to fix the checksum. We have a function for computing the checksum, use it. Cc: Ville Syrjälä Signed-off-by: Jani Nikula Reviewed-by: Ville Syrjälä --- drivers/gpu/drm/drm_edid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index d0a76781ed19..d2dfab28b5b7 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1840,8 +1840,8 @@ static struct edid *edid_filter_invalid_blocks(const struct edid *edid, memcpy(base++, block, EDID_LENGTH); } - new->checksum += new->extensions - valid_extensions; new->extensions = valid_extensions; + new->checksum = edid_block_compute_checksum(new); out: kfree(edid);