From patchwork Wed Mar 13 18:38:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Tarasov X-Patchwork-Id: 10852361 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5CC5914DE for ; Thu, 14 Mar 2019 08:25:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5AEAC2870C for ; Thu, 14 Mar 2019 08:25:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BB28289CB; Thu, 14 Mar 2019 08:25:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CAA632870C for ; Thu, 14 Mar 2019 08:25:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 946A76E194; Thu, 14 Mar 2019 08:23:41 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3620D895C1 for ; Wed, 13 Mar 2019 18:39:03 +0000 (UTC) Received: by mail-pg1-x542.google.com with SMTP id u9so2130091pgo.7 for ; Wed, 13 Mar 2019 11:39:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=NYF1MqD9O75oMyimzBC5AKNKNxpWn+L7PHnPbsBUVsQ=; b=IwEYBriyS6GHqQKn0RBaDmPITFVigpbfH/MNqHHWUdUo3VpaQdyXEkKUahqU9FCkep TlO4UwoPP/DxCTgUuc6UWoCK2dBzTFl4jfiZb7+OJjX6OsjmhMHx3mTiMeRp6rxvQh7f 3DEgZiAykquEwt4mGIBEaSh+VKodC3gxCrBgEbvHRV2OMZ66WJBJ928XPNf7WEGiNQ2x W7RbBd4+bjIkIkOkXAUdenZvzYS6rSJ+82+0gs9dATBq+XW2IQ0+LUz1usj1KCThS3R+ YxEkgufJRJuAcn6e2jYGKF08kKYHBPdxf0YtrOzz8HTKLHQOJ+mvWy8GA0L7UI4aknQz faPQ== X-Gm-Message-State: APjAAAW/0uex8YTuM9cnZ6DOYL87OKDKMIjDZDnD/1MECwkusBghu7gG ACV0RO4bjD4cvVTcZ5AcFfDHGknt3yw= X-Google-Smtp-Source: APXvYqwUHYogXIF2JUjGeIGl/Pbbz+13xNko/udyMBy/xlqLh9/xDbmaEE7HqHjdpyFHFMaJhw8mhA== X-Received: by 2002:a63:4826:: with SMTP id v38mr12918246pga.370.1552502342683; Wed, 13 Mar 2019 11:39:02 -0700 (PDT) Received: from tutans-desktop.mtv.corp.google.com ([2620:15c:202:201:e582:7f1e:f786:e00c]) by smtp.gmail.com with ESMTPSA id g188sm25854983pfc.24.2019.03.13.11.39.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Mar 2019 11:39:02 -0700 (PDT) From: Robert Tarasov To: airlied@redhat.com Subject: [PATCH] drm/udl: Refactor edid retreiving in UDL driver Date: Wed, 13 Mar 2019 11:38:58 -0700 Message-Id: <20190313183858.157667-1-tutankhamen@chromium.org> X-Mailer: git-send-email 2.21.0.360.g471c308f928-goog MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 14 Mar 2019 08:23:35 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=NYF1MqD9O75oMyimzBC5AKNKNxpWn+L7PHnPbsBUVsQ=; b=lVzAVf4JneMzsLcUwidYZQPANcl0kLUz0hO2PPUnkg9v/fRnAiFRakwBniZ5fzye0T z7Q3OySOc1DPiPs0nHH5k+Pz7Yycm9h4fXWGJfxlCOYPmVoL+mV9SvFOT3eWOwuMS/c9 2uxuejUzBRFLcS04bga28qmnk4CYIeSoKapq8= 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: Robert Tarasov , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now drm/udl driver uses drm_do_get_edid() function to retreive and validate all blocks of EDID data. Old approach had insufficient validation routine and had problems with retreiving of extra blocks Signed-off-by: Robert Tarasov Reviewed-by: Dave Airlie --- drivers/gpu/drm/udl/udl_connector.c | 72 +++++------------------------ 1 file changed, 11 insertions(+), 61 deletions(-) diff --git a/drivers/gpu/drm/udl/udl_connector.c b/drivers/gpu/drm/udl/udl_connector.c index c3dc1fd20cb4..c7f8ac2cdbe5 100644 --- a/drivers/gpu/drm/udl/udl_connector.c +++ b/drivers/gpu/drm/udl/udl_connector.c @@ -17,18 +17,19 @@ #include "udl_connector.h" #include "udl_drv.h" -static bool udl_get_edid_block(struct udl_device *udl, int block_idx, - u8 *buff) +static int udl_get_edid_block(void *data, u8 *buf, unsigned int block, + size_t len) { int ret, i; u8 *read_buff; + struct udl_device *udl = data; read_buff = kmalloc(2, GFP_KERNEL); if (!read_buff) - return false; + return -1; - for (i = 0; i < EDID_LENGTH; i++) { - int bval = (i + block_idx * EDID_LENGTH) << 8; + for (i = 0; i < len; i++) { + int bval = (i + block * EDID_LENGTH) << 8; ret = usb_control_msg(udl->udev, usb_rcvctrlpipe(udl->udev, 0), (0x02), (0x80 | (0x02 << 5)), bval, @@ -36,60 +37,13 @@ static bool udl_get_edid_block(struct udl_device *udl, int block_idx, if (ret < 1) { DRM_ERROR("Read EDID byte %d failed err %x\n", i, ret); kfree(read_buff); - return false; + return -1; } - buff[i] = read_buff[1]; + buf[i] = read_buff[1]; } kfree(read_buff); - return true; -} - -static bool udl_get_edid(struct udl_device *udl, u8 **result_buff, - int *result_buff_size) -{ - int i, extensions; - u8 *block_buff = NULL, *buff_ptr; - - block_buff = kmalloc(EDID_LENGTH, GFP_KERNEL); - if (block_buff == NULL) - return false; - - if (udl_get_edid_block(udl, 0, block_buff) && - memchr_inv(block_buff, 0, EDID_LENGTH)) { - extensions = ((struct edid *)block_buff)->extensions; - if (extensions > 0) { - /* we have to read all extensions one by one */ - *result_buff_size = EDID_LENGTH * (extensions + 1); - *result_buff = kmalloc(*result_buff_size, GFP_KERNEL); - buff_ptr = *result_buff; - if (buff_ptr == NULL) { - kfree(block_buff); - return false; - } - memcpy(buff_ptr, block_buff, EDID_LENGTH); - kfree(block_buff); - buff_ptr += EDID_LENGTH; - for (i = 1; i < extensions; ++i) { - if (udl_get_edid_block(udl, i, buff_ptr)) { - buff_ptr += EDID_LENGTH; - } else { - kfree(*result_buff); - *result_buff = NULL; - return false; - } - } - return true; - } - /* we have only base edid block */ - *result_buff = block_buff; - *result_buff_size = EDID_LENGTH; - return true; - } - - kfree(block_buff); - - return false; + return 0; } static int udl_get_modes(struct drm_connector *connector) @@ -121,8 +75,6 @@ static int udl_mode_valid(struct drm_connector *connector, static enum drm_connector_status udl_detect(struct drm_connector *connector, bool force) { - u8 *edid_buff = NULL; - int edid_buff_size = 0; struct udl_device *udl = connector->dev->dev_private; struct udl_drm_connector *udl_connector = container_of(connector, @@ -135,12 +87,10 @@ udl_detect(struct drm_connector *connector, bool force) udl_connector->edid = NULL; } - - if (!udl_get_edid(udl, &edid_buff, &edid_buff_size)) + udl_connector->edid = drm_do_get_edid(connector, udl_get_edid_block, udl); + if (!udl_connector->edid) return connector_status_disconnected; - udl_connector->edid = (struct edid *)edid_buff; - return connector_status_connected; }