All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paulo Zanoni <paulo.r.zanoni@intel.com>
To: "Gustavo A. R. Silva" <gustavo@embeddedor.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	David Airlie <airlied@linux.ie>
Cc: intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org, "Vivi,
	Rodrigo" <rodrigo.vivi@intel.com>
Subject: Re: [PATCH] drm/i915/dp: fix shifting by a negative number of bits
Date: Wed, 12 Sep 2018 15:02:30 -0700	[thread overview]
Message-ID: <1536789750.2958.17.camel@intel.com> (raw)
In-Reply-To: <20180912143153.GA27564@embeddedor.com>

Em Qua, 2018-09-12 às 09:31 -0500, Gustavo A. R. Silva escreveu:
> 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.

This was just discussed yesterday in a patch by Rodrigo:

https://patchwork.freedesktop.org/patch/246903/

I would personally prefer his version because it avoids passing -1 to
register macros that Coverity doesn't seem to care about, it's a single
check and it prints WARN() instead of DRM_DEBUG_KMS().

Although I do prefer your commit message explanation :).

Perhaps I should reconsider my vote to not merge it. Or we could
actually go and test what happens when intel_port_to_tc() is broken,
fixing all the issues instead of just the ones reported by Coverity.

Anyway, Rodrigo's patch with an improved commit message could receive
my R-B tag now.

> 
> 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 <gustavo@embeddedor.com>
> ---
>  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.
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

WARNING: multiple messages have this Message-ID (diff)
From: Paulo Zanoni <paulo.r.zanoni@intel.com>
To: "Gustavo A. R. Silva" <gustavo@embeddedor.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	David Airlie <airlied@linux.ie>
Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, "Vivi,
	Rodrigo" <rodrigo.vivi@intel.com>
Subject: Re: [PATCH] drm/i915/dp: fix shifting by a negative number of bits
Date: Wed, 12 Sep 2018 15:02:30 -0700	[thread overview]
Message-ID: <1536789750.2958.17.camel@intel.com> (raw)
In-Reply-To: <20180912143153.GA27564@embeddedor.com>

Em Qua, 2018-09-12 às 09:31 -0500, Gustavo A. R. Silva escreveu:
> 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.

This was just discussed yesterday in a patch by Rodrigo:

https://patchwork.freedesktop.org/patch/246903/

I would personally prefer his version because it avoids passing -1 to
register macros that Coverity doesn't seem to care about, it's a single
check and it prints WARN() instead of DRM_DEBUG_KMS().

Although I do prefer your commit message explanation :).

Perhaps I should reconsider my vote to not merge it. Or we could
actually go and test what happens when intel_port_to_tc() is broken,
fixing all the issues instead of just the ones reported by Coverity.

Anyway, Rodrigo's patch with an improved commit message could receive
my R-B tag now.

> 
> 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 <gustavo@embeddedor.com>
> ---
>  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.

  parent reply	other threads:[~2018-09-12 22:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-12 14:31 [PATCH] drm/i915/dp: fix shifting by a negative number of bits Gustavo A. R. Silva
2018-09-12 15:24 ` ✓ Fi.CI.BAT: success for " Patchwork
2018-09-12 21:04 ` ✓ Fi.CI.IGT: " Patchwork
2018-09-12 22:02 ` Paulo Zanoni [this message]
2018-09-12 22:02   ` [PATCH] " Paulo Zanoni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1536789750.2958.17.camel@intel.com \
    --to=paulo.r.zanoni@intel.com \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gustavo@embeddedor.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rodrigo.vivi@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.