From patchwork Wed Aug 21 18:50:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 11108031 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9B37A1399 for ; Wed, 21 Aug 2019 18:50:24 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 19DBD2339F for ; Wed, 21 Aug 2019 18:50:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 19DBD2339F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D118A6E978; Wed, 21 Aug 2019 18:50:20 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by gabe.freedesktop.org (Postfix) with ESMTPS id 24BEC6E340 for ; Wed, 21 Aug 2019 18:50:16 +0000 (UTC) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7E1E453E; Wed, 21 Aug 2019 20:50:14 +0200 (CEST) From: Laurent Pinchart To: dri-devel@lists.freedesktop.org Subject: [PATCH/RFC 1/5] drm/edid: Reorganise the DisplayID parsing code Date: Wed, 21 Aug 2019 21:50:01 +0300 Message-Id: <20190821185005.9789-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190821185005.9789-1-laurent.pinchart@ideasonboard.com> References: <20190821185005.9789-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1566413414; bh=dVnry2/G2EkTmq1XUqRQHh0GbiJrokydgSf+hsK0jLk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cU6co3ZU9O22K+5GzcZ2l/wUyGflNkKPL+VIqfXrqtbf3b+huVblqpkgWqkxDfbvE XEM6jC52ZtzS2DAhhaB7WazWyhS7LYtacFtZqIPoGrFeHKdTPKGc9ce/9dkl2ZaRYX fUptBsjXTsahRV0NxjlstTcvLVYJcY9PNvfZ35bI= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomi Valkeinen Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This change started as an attempt to remove the forward declaration of validate_displayid(), and ended up reorganising the DisplayID parsing code to fix serial intertwined issues. The drm_parse_display_id() function, which parses a DisplayID block, is made aware of whether the DisplayID comes from an EDID extension block or is direct DisplayID data. This is a layering violation, this should be handled in the caller. Similarly, the validate_displayid() function should not take an offset in the data buffer, it should also receive a pointer to the DisplayID data. In order to simplify the callers of drm_find_displayid_extension(), the function is modified to return a pointer to the DisplayID data, not to the EDID extension block. The pointer can then be used directly for validation and parsing, without the need to add an offset. For consistency reasons the validate_displayid() function is renamed to drm_displayid_is_valid() and modified to return a bool, and the drm_parse_display_id() renamed to drm_parse_displayid(). Signed-off-by: Laurent Pinchart --- drivers/gpu/drm/drm_edid.c | 104 ++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 82a4ceed3fcf..7c6bc5183b60 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1342,7 +1342,6 @@ MODULE_PARM_DESC(edid_fixup, static void drm_get_displayid(struct drm_connector *connector, struct edid *edid); -static int validate_displayid(u8 *displayid, int length, int idx); static int drm_edid_block_checksum(const u8 *raw_edid) { @@ -2927,17 +2926,49 @@ static u8 *drm_find_edid_extension(const struct edid *edid, int ext_id) return edid_ext; } +static bool drm_displayid_is_valid(u8 *displayid, unsigned int length) +{ + struct displayid_hdr *base; + u8 csum = 0; + int i; + + base = (struct displayid_hdr *)displayid; + + 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) + return false; + + for (i = 0; i <= base->bytes + 5; i++) + csum += displayid[i]; + + if (csum) { + DRM_NOTE("DisplayID checksum invalid, remainder is %d\n", csum); + return false; + } + + return true; +} static u8 *drm_find_displayid_extension(const struct edid *edid) { - return drm_find_edid_extension(edid, DISPLAYID_EXT); + u8 *ext = drm_find_edid_extension(edid, DISPLAYID_EXT); + + if (!ext) + return NULL; + + /* + * Skip the EDID extension block tag number to return the DisplayID + * data. + */ + return ext + 1; } static u8 *drm_find_cea_extension(const struct edid *edid) { - int ret; - int idx = 1; - int length = EDID_LENGTH; + int idx; + int length = EDID_LENGTH - 1; struct displayid_block *block; u8 *cea; u8 *displayid; @@ -2952,11 +2983,10 @@ static u8 *drm_find_cea_extension(const struct edid *edid) if (!displayid) return NULL; - ret = validate_displayid(displayid, length, idx); - if (ret) + if (!drm_displayid_is_valid(displayid, length)) return NULL; - idx += sizeof(struct displayid_hdr); + idx = sizeof(struct displayid_hdr); for_each_displayid_db(displayid, block, idx, length) { if (block->tag == DATA_BLOCK_CTA) { cea = (u8 *)block; @@ -4711,29 +4741,6 @@ u32 drm_add_display_info(struct drm_connector *connector, const struct edid *edi return quirks; } -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_NOTE("DisplayID checksum invalid, remainder is %d\n", csum); - return -EINVAL; - } - return 0; -} - static struct drm_display_mode *drm_mode_displayid_detailed(struct drm_device *dev, struct displayid_detailed_timings_1 *timings) { @@ -4809,9 +4816,8 @@ static int add_displayid_detailed_modes(struct drm_connector *connector, struct edid *edid) { u8 *displayid; - int ret; - int idx = 1; - int length = EDID_LENGTH; + int idx; + int length = EDID_LENGTH - 1; struct displayid_block *block; int num_modes = 0; @@ -4819,11 +4825,10 @@ static int add_displayid_detailed_modes(struct drm_connector *connector, if (!displayid) return 0; - ret = validate_displayid(displayid, length, idx); - if (ret) + if (!drm_displayid_is_valid(displayid, length)) return 0; - idx += sizeof(struct displayid_hdr); + idx = sizeof(struct displayid_hdr); for_each_displayid_db(displayid, block, idx, length) { switch (block->tag) { case DATA_BLOCK_TYPE_1_DETAILED_TIMING: @@ -5424,23 +5429,17 @@ static int drm_parse_tiled_block(struct drm_connector *connector, return 0; } -static int drm_parse_display_id(struct drm_connector *connector, - u8 *displayid, int length, - bool is_edid_extension) +static int drm_parse_displayid(struct drm_connector *connector, + u8 *displayid, int length) { - /* if this is an EDID extension the first byte will be 0x70 */ - int idx = 0; struct displayid_block *block; + int idx; int ret; - if (is_edid_extension) - idx = 1; + if (!drm_displayid_is_valid(displayid, length)) + return -EINVAL; - ret = validate_displayid(displayid, length, idx); - if (ret) - return ret; - - idx += sizeof(struct displayid_hdr); + idx = sizeof(struct displayid_hdr); for_each_displayid_db(displayid, block, idx, length) { DRM_DEBUG_KMS("block id 0x%x, rev %d, len %d\n", block->tag, block->rev, block->num_bytes); @@ -5468,8 +5467,9 @@ static int drm_parse_display_id(struct drm_connector *connector, static void drm_get_displayid(struct drm_connector *connector, struct edid *edid) { - void *displayid = NULL; + void *displayid; int ret; + connector->has_tile = false; displayid = drm_find_displayid_extension(edid); if (!displayid) { @@ -5477,16 +5477,16 @@ static void drm_get_displayid(struct drm_connector *connector, goto out_drop_ref; } - ret = drm_parse_display_id(connector, displayid, EDID_LENGTH, true); + ret = drm_parse_displayid(connector, displayid, EDID_LENGTH - 1); if (ret < 0) goto out_drop_ref; if (!connector->has_tile) goto out_drop_ref; return; + out_drop_ref: if (connector->tile_group) { drm_mode_put_tile_group(connector->dev, connector->tile_group); connector->tile_group = NULL; } - return; }