[v3,01/14] drm/i915/dp: use known correct array size in rate_to_index

Submitted by Jani Nikula on March 28, 2017, 2:59 p.m.

Details

Message ID ff5b08f45a72c2247f5326b080027e2f5d8cc4ee.1490712890.git.jani.nikula@intel.com
State New
Headers show
Series "drm/i915/dp: link rate and lane count refactoring" ( rev: 4 3 ) in Intel GFX

Not browsing as part of any series.

Commit Message

Jani Nikula March 28, 2017, 2:59 p.m.
I can't think of a real world bug this could cause now, but this will be
required in follow-up work. While at it, change the parameter order to
be slightly more sensible.

Cc: Manasi Navare <manasi.d.navare@intel.com>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 drivers/gpu/drm/i915/intel_dp.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index fd96a6cf7326..88c708b07c70 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -1538,12 +1538,12 @@  bool intel_dp_read_desc(struct intel_dp *intel_dp)
 	return true;
 }
 
-static int rate_to_index(int find, const int *rates)
+static int rate_to_index(const int *rates, int len, int rate)
 {
-	int i = 0;
+	int i;
 
-	for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
-		if (find == rates[i])
+	for (i = 0; i < len; i++)
+		if (rate == rates[i])
 			break;
 
 	return i;
@@ -1564,7 +1564,8 @@  intel_dp_max_link_rate(struct intel_dp *intel_dp)
 
 int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
 {
-	return rate_to_index(rate, intel_dp->sink_rates);
+	return rate_to_index(intel_dp->sink_rates, intel_dp->num_sink_rates,
+			     rate);
 }
 
 void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,

Comments

Looks good to me.

Reviewed-by: <manasi.d.navare@intel.com>

Manasi

On Tue, Mar 28, 2017 at 05:59:01PM +0300, Jani Nikula wrote:
> I can't think of a real world bug this could cause now, but this will be
> required in follow-up work. While at it, change the parameter order to
> be slightly more sensible.
> 
> Cc: Manasi Navare <manasi.d.navare@intel.com>
> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> ---
>  drivers/gpu/drm/i915/intel_dp.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
> index fd96a6cf7326..88c708b07c70 100644
> --- a/drivers/gpu/drm/i915/intel_dp.c
> +++ b/drivers/gpu/drm/i915/intel_dp.c
> @@ -1538,12 +1538,12 @@ bool intel_dp_read_desc(struct intel_dp *intel_dp)
>  	return true;
>  }
>  
> -static int rate_to_index(int find, const int *rates)
> +static int rate_to_index(const int *rates, int len, int rate)
>  {
> -	int i = 0;
> +	int i;
>  
> -	for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
> -		if (find == rates[i])
> +	for (i = 0; i < len; i++)
> +		if (rate == rates[i])
>  			break;
>  
>  	return i;
> @@ -1564,7 +1564,8 @@ intel_dp_max_link_rate(struct intel_dp *intel_dp)
>  
>  int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
>  {
> -	return rate_to_index(rate, intel_dp->sink_rates);
> +	return rate_to_index(intel_dp->sink_rates, intel_dp->num_sink_rates,
> +			     rate);
>  }
>  
>  void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
> -- 
> 2.1.4
>