mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/i915: avoid potential uninitialized variable use
@ 2017-10-05 12:08 Arnd Bergmann
  2017-10-05 13:32 ` Daniel Vetter
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2017-10-05 12:08 UTC (permalink / raw)
  To: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, David Airlie
  Cc: Arnd Bergmann, Ville Syrjälä,
	Ander Conselvan de Oliveira, Daniel Vetter, Maarten Lankhorst,
	Tvrtko Ursulin, Shashank Sharma, Paulo Zanoni, intel-gfx,
	dri-devel, linux-kernel

One of the recent changes introduced a warning about
undefined behavior in the sanity checking:

drivers/gpu/drm/i915/intel_ddi.c: In function 'intel_ddi_hdmi_level':
drivers/gpu/drm/i915/intel_ddi.c:654:6: error: 'n_hdmi_entries' may be used uninitialized in this function [-Werror=maybe-uninitialized]

It seems that the new cnl specific get_buf_trans functions
can return uninitialized data if the voltage level is set
to an unexpected value. This changes the code to always return
'1' in that error case, which seems like the safest choice
as we use one less than the number as an array index later on.

Fixes: cc9cabfdec38 ("drm/i915/cnl: Move voltage check into ddi buf trans functions.")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/gpu/drm/i915/intel_ddi.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_ddi.c b/drivers/gpu/drm/i915/intel_ddi.c
index 93cbbcbbc193..d0b786078bea 100644
--- a/drivers/gpu/drm/i915/intel_ddi.c
+++ b/drivers/gpu/drm/i915/intel_ddi.c
@@ -602,8 +602,10 @@ cnl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries)
 	} else if (voltage == VOLTAGE_INFO_1_05V) {
 		*n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_1_05V);
 		return cnl_ddi_translations_hdmi_1_05V;
-	} else
+	} else {
+		*n_entries = 1;
 		MISSING_CASE(voltage);
+	}
 	return NULL;
 }
 
@@ -621,8 +623,10 @@ cnl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
 	} else if (voltage == VOLTAGE_INFO_1_05V) {
 		*n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_1_05V);
 		return cnl_ddi_translations_dp_1_05V;
-	} else
+	} else {
+		*n_entries = 1;
 		MISSING_CASE(voltage);
+	}
 	return NULL;
 }
 
@@ -641,8 +645,10 @@ cnl_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
 		} else if (voltage == VOLTAGE_INFO_1_05V) {
 			*n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_1_05V);
 			return cnl_ddi_translations_edp_1_05V;
-		} else
+		} else {
+			*n_entries = 1;
 			MISSING_CASE(voltage);
+		}
 		return NULL;
 	} else {
 		return cnl_get_buf_trans_dp(dev_priv, n_entries);
-- 
2.9.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/i915: avoid potential uninitialized variable use
  2017-10-05 12:08 [PATCH] drm/i915: avoid potential uninitialized variable use Arnd Bergmann
@ 2017-10-05 13:32 ` Daniel Vetter
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Vetter @ 2017-10-05 13:32 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, David Airlie,
	Ville Syrjälä,
	Ander Conselvan de Oliveira, Daniel Vetter, Maarten Lankhorst,
	Tvrtko Ursulin, Shashank Sharma, Paulo Zanoni, intel-gfx,
	dri-devel, linux-kernel

On Thu, Oct 05, 2017 at 02:08:26PM +0200, Arnd Bergmann wrote:
> One of the recent changes introduced a warning about
> undefined behavior in the sanity checking:
> 
> drivers/gpu/drm/i915/intel_ddi.c: In function 'intel_ddi_hdmi_level':
> drivers/gpu/drm/i915/intel_ddi.c:654:6: error: 'n_hdmi_entries' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> 
> It seems that the new cnl specific get_buf_trans functions
> can return uninitialized data if the voltage level is set
> to an unexpected value. This changes the code to always return
> '1' in that error case, which seems like the safest choice
> as we use one less than the number as an array index later on.
> 
> Fixes: cc9cabfdec38 ("drm/i915/cnl: Move voltage check into ddi buf trans functions.")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/gpu/drm/i915/intel_ddi.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_ddi.c b/drivers/gpu/drm/i915/intel_ddi.c
> index 93cbbcbbc193..d0b786078bea 100644
> --- a/drivers/gpu/drm/i915/intel_ddi.c
> +++ b/drivers/gpu/drm/i915/intel_ddi.c
> @@ -602,8 +602,10 @@ cnl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries)
>  	} else if (voltage == VOLTAGE_INFO_1_05V) {
>  		*n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_1_05V);
>  		return cnl_ddi_translations_hdmi_1_05V;
> -	} else
> +	} else {
> +		*n_entries = 1;
>  		MISSING_CASE(voltage);
> +	}

Somewhat meh on this, so added a /* shut up gcc */ comment and merged.

Thanks, Daniel

>  	return NULL;
>  }
>  
> @@ -621,8 +623,10 @@ cnl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
>  	} else if (voltage == VOLTAGE_INFO_1_05V) {
>  		*n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_1_05V);
>  		return cnl_ddi_translations_dp_1_05V;
> -	} else
> +	} else {
> +		*n_entries = 1;
>  		MISSING_CASE(voltage);
> +	}
>  	return NULL;
>  }
>  
> @@ -641,8 +645,10 @@ cnl_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
>  		} else if (voltage == VOLTAGE_INFO_1_05V) {
>  			*n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_1_05V);
>  			return cnl_ddi_translations_edp_1_05V;
> -		} else
> +		} else {
> +			*n_entries = 1;
>  			MISSING_CASE(voltage);
> +		}
>  		return NULL;
>  	} else {
>  		return cnl_get_buf_trans_dp(dev_priv, n_entries);
> -- 
> 2.9.0
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-10-05 13:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-05 12:08 [PATCH] drm/i915: avoid potential uninitialized variable use Arnd Bergmann
2017-10-05 13:32 ` Daniel Vetter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®