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: 10598773 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 A8FE4920 for ; Thu, 13 Sep 2018 07:25:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E5012A5D8 for ; Thu, 13 Sep 2018 07:25:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 824822A5DE; Thu, 13 Sep 2018 07:25:28 +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=unavailable 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 2A4F22A5D8 for ; Thu, 13 Sep 2018 07:25:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 520E56E61B; Thu, 13 Sep 2018 07:23:54 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org X-Greylist: delayed 1314 seconds by postgrey-1.36 at gabe; Wed, 12 Sep 2018 14:54:09 UTC Received: from gateway33.websitewelcome.com (gateway33.websitewelcome.com [192.185.146.130]) by gabe.freedesktop.org (Postfix) with ESMTPS id 699836E3CF for ; Wed, 12 Sep 2018 14:54:09 +0000 (UTC) Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 2C688365BC for ; Wed, 12 Sep 2018 09:32:14 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id 06BRgqw7KBcCX06BagHP7X; 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 Subject: [PATCH] drm/i915/dp: fix shifting by a negative number of bits 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: 7 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes X-Mailman-Approved-At: Thu, 13 Sep 2018 07:23:44 +0000 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: intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, "Gustavo A. R. Silva" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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.