Re: [PATCH] drm/i915: Skip pixel multiplier x-check if we fail to send the command

Daniel Vetter
2013-07-12T12:11:54Z

On Thu, Jul 11, 2013 at 09:35:17PM +0100, Damien Lespiau wrote:
> On Thu, Jul 11, 2013 at 09:52:33PM +0200, Daniel Vetter wrote:
> > On Thu, Jul 11, 2013 at 07:46:00PM +0100, Damien Lespiau wrote:
> > > If intel_sdvo_get_value() fails here, val is unitialized and the cross
> > > check won't check anything.
> > >
> > > Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
> > > ---
> > > drivers/gpu/drm/i915/intel_sdvo.c | 5 ++++-
> > > 1 file changed, 4 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
> > > index b8e1623..4481f6a 100644
> > > --- a/drivers/gpu/drm/i915/intel_sdvo.c
> > > +++ b/drivers/gpu/drm/i915/intel_sdvo.c
> > > @@ -1357,7 +1357,10 @@ static void intel_sdvo_get_config(struct intel_encoder *encoder,
> > > }
> > >
> > > /* Cross check the port pixel multiplier with the sdvo encoder state. */
> > > - intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT, &val, 1);
> > > + if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT,
> > > + &val, 1))
> > > + return;
> >
> > But now it fails silently instead of being paranoid ... Can we just shut
> > up the tool instead?
>
> We absolutely can! (and it's done).

On second thought we could shovel the switch into an if block so that val
is only read when written. Since pixel_multiplier is already set to 0 (in
case the sdvo device returns garbage) we'll correctly WARN even when
get_value fails (and per chance the stack garbage in val is the right
value for the pixel multiplier).