From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Gustavo A. R. Silva" Subject: [PATCH] drm/i915/dp: fix shifting by a negative number of bits Date: Wed, 12 Sep 2018 09:31:53 -0500 Message-ID: <20180912143153.GA27564@embeddedor.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org To: Paulo Zanoni , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" List-Id: dri-devel@lists.freedesktop.org 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. -- 2.7.4