diff mbox series

drm/i915: Add check for null dereference

Message ID 20220927091625.2127039-1-mika.kahola@intel.com (mailing list archive)
State New, archived
Headers show
Series drm/i915: Add check for null dereference | expand

Commit Message

Mika Kahola Sept. 27, 2022, 9:16 a.m. UTC
fixed_mode in intel_edp_add_properties() function may be NULL
which is used later on in the function. Return early, in case of
fixed_mode is NULL to avoid NULL dereference.

Discovered by klockwork static analysis.

Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Jani Nikula <jani.nikula@intel.com>

Signed-off-by: Mika Kahola <mika.kahola@intel.com>
---
 drivers/gpu/drm/i915/display/intel_dp.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Ville Syrjälä Sept. 27, 2022, 9:27 a.m. UTC | #1
On Tue, Sep 27, 2022 at 12:16:25PM +0300, Mika Kahola wrote:
> fixed_mode in intel_edp_add_properties() function may be NULL
> which is used later on in the function. Return early, in case of
> fixed_mode is NULL to avoid NULL dereference.

Should no longer be possible:
commit bde544e1d701 ("drm/i915: Don't init eDP if we can't find a fixed mode")

> 
> Discovered by klockwork static analysis.
> 
> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Cc: Jani Nikula <jani.nikula@intel.com>
> 
> Signed-off-by: Mika Kahola <mika.kahola@intel.com>
> ---
>  drivers/gpu/drm/i915/display/intel_dp.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_dp.c b/drivers/gpu/drm/i915/display/intel_dp.c
> index 6ebd6e104b2c..db2541873f9d 100644
> --- a/drivers/gpu/drm/i915/display/intel_dp.c
> +++ b/drivers/gpu/drm/i915/display/intel_dp.c
> @@ -5188,6 +5188,9 @@ intel_edp_add_properties(struct intel_dp *intel_dp)
>  	const struct drm_display_mode *fixed_mode =
>  		intel_panel_preferred_fixed_mode(connector);
>  
> +	if (!fixed_mode)
> +		return;
> +
>  	intel_attach_scaling_mode_property(&connector->base);
>  
>  	drm_connector_set_panel_orientation_with_quirk(&connector->base,
> -- 
> 2.34.1
Mika Kahola Sept. 27, 2022, 9:32 a.m. UTC | #2
> -----Original Message-----
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Sent: Tuesday, September 27, 2022 12:27 PM
> To: Kahola, Mika <mika.kahola@intel.com>
> Cc: intel-gfx@lists.freedesktop.org; Nikula, Jani <jani.nikula@intel.com>
> Subject: Re: [PATCH] drm/i915: Add check for null dereference
> 
> On Tue, Sep 27, 2022 at 12:16:25PM +0300, Mika Kahola wrote:
> > fixed_mode in intel_edp_add_properties() function may be NULL which is
> > used later on in the function. Return early, in case of fixed_mode is
> > NULL to avoid NULL dereference.
> 
> Should no longer be possible:
> commit bde544e1d701 ("drm/i915: Don't init eDP if we can't find a fixed mode")

Ok. This one can then be marked as "not a problem" in clockwork.

-Mika-

> 
> >
> > Discovered by klockwork static analysis.
> >
> > Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > Cc: Jani Nikula <jani.nikula@intel.com>
> >
> > Signed-off-by: Mika Kahola <mika.kahola@intel.com>
> > ---
> >  drivers/gpu/drm/i915/display/intel_dp.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/i915/display/intel_dp.c
> > b/drivers/gpu/drm/i915/display/intel_dp.c
> > index 6ebd6e104b2c..db2541873f9d 100644
> > --- a/drivers/gpu/drm/i915/display/intel_dp.c
> > +++ b/drivers/gpu/drm/i915/display/intel_dp.c
> > @@ -5188,6 +5188,9 @@ intel_edp_add_properties(struct intel_dp *intel_dp)
> >  	const struct drm_display_mode *fixed_mode =
> >  		intel_panel_preferred_fixed_mode(connector);
> >
> > +	if (!fixed_mode)
> > +		return;
> > +
> >  	intel_attach_scaling_mode_property(&connector->base);
> >
> >  	drm_connector_set_panel_orientation_with_quirk(&connector->base,
> > --
> > 2.34.1
> 
> --
> Ville Syrjälä
> Intel
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/display/intel_dp.c b/drivers/gpu/drm/i915/display/intel_dp.c
index 6ebd6e104b2c..db2541873f9d 100644
--- a/drivers/gpu/drm/i915/display/intel_dp.c
+++ b/drivers/gpu/drm/i915/display/intel_dp.c
@@ -5188,6 +5188,9 @@  intel_edp_add_properties(struct intel_dp *intel_dp)
 	const struct drm_display_mode *fixed_mode =
 		intel_panel_preferred_fixed_mode(connector);
 
+	if (!fixed_mode)
+		return;
+
 	intel_attach_scaling_mode_property(&connector->base);
 
 	drm_connector_set_panel_orientation_with_quirk(&connector->base,