From patchwork Wed Sep 12 14:31:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 10597683 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 D025B14BD for ; Wed, 12 Sep 2018 14:56:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDBEA299E2 for ; Wed, 12 Sep 2018 14:56:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B143F29F14; Wed, 12 Sep 2018 14:56:36 +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 EA5F7299E2 for ; Wed, 12 Sep 2018 14:56:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2C0936E564; Wed, 12 Sep 2018 14:56:35 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org X-Greylist: delayed 1459 seconds by postgrey-1.36 at gabe; Wed, 12 Sep 2018 14:56:34 UTC Received: from gateway24.websitewelcome.com (gateway24.websitewelcome.com [192.185.50.73]) by gabe.freedesktop.org (Postfix) with ESMTPS id 16CBD6E564 for ; Wed, 12 Sep 2018 14:56:34 +0000 (UTC) Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 277E094170 for ; Wed, 12 Sep 2018 09:32:14 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id 06BRgqw7LBcCX06BagHP7Y; Wed, 12 Sep 2018 09:32:13 -0500 X-Authority-Reason: nr=8 Received: from [189.250.106.191] (port=46028 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1g06BQ-002trA-Mf; Wed, 12 Sep 2018 09:31:57 -0500 Date: Wed, 12 Sep 2018 09:31:53 -0500 From: "Gustavo A. R. Silva" To: Paulo Zanoni , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie Message-ID: <20180912143153.GA27564@embeddedor.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - lists.freedesktop.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.250.106.191 X-Source-L: No X-Exim-ID: 1g06BQ-002trA-Mf X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.106.191]:46028 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 6 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Subject: [Intel-gfx] [PATCH] drm/i915/dp: fix shifting by a negative number of bits X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, "Gustavo A. R. Silva" Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Function intel_port_to_tc() returns PORT_TC_NONE on error, which is a negative value -1. In case PORT_TC_NONE is returned, there is an undefined behavior when shifting by a negative number of bits in both DP_PHY_MODE_STATUS_NOT_SAFE and P_PHY_MODE_STATUS_COMPLETED macros. Fix this by adding sanity checks on intel_port_to_tc return value, before using macros DP_PHY_MODE_STATUS_NOT_SAFE and P_PHY_MODE_STATUS_COMPLETED. Addresses-Coverity-ID: 1473324 ("Bad bit shift operation") Addresses-Coverity-ID: 1473325 ("Bad bit shift operation") Fixes: 39d1e234e1e1 ("drm/i915/icl: implement the tc/legacy HPD {dis,}connect flows") Signed-off-by: Gustavo A. R. Silva --- drivers/gpu/drm/i915/intel_dp.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c index 436c22d..e34b7b1 100644 --- a/drivers/gpu/drm/i915/intel_dp.c +++ b/drivers/gpu/drm/i915/intel_dp.c @@ -4811,6 +4811,11 @@ static bool icl_tc_phy_connect(struct drm_i915_private *dev_priv, dig_port->tc_type != TC_PORT_TYPEC) return true; + if (tc_port < 0) { + DRM_DEBUG_KMS("Bad TC port %d\n", tc_port); + return false; + } + val = I915_READ(PORT_TX_DFLEXDPPMS); if (!(val & DP_PHY_MODE_STATUS_COMPLETED(tc_port))) { DRM_DEBUG_KMS("DP PHY for TC port %d not ready\n", tc_port); @@ -4857,6 +4862,10 @@ static void icl_tc_phy_disconnect(struct drm_i915_private *dev_priv, dig_port->tc_type != TC_PORT_TYPEC) return; + if (tc_port < 0) { + DRM_DEBUG_KMS("Bad TC port %d\n", tc_port); + return; + } /* * This function may be called many times in a row without an HPD event * in between, so try to avoid the write when we can.