Re: [PATCH 4.19 062/125] ALSA: usb-audio: Fix possible NULL dereference at create_yamaha_midi_quirk()

From: Pavel Machek
Date: Mon Nov 18 2019 - 09:33:56 EST


Hi!

> > > Clearly code wants to allow at most one of them to be NULL.
> > >
> > > > - if (!snd_usb_validate_midi_desc(injd) ||
> > > > - !snd_usb_validate_midi_desc(outjd))
> > > > + if (!(injd && snd_usb_validate_midi_desc(injd)) ||
> > > > + !(outjd && snd_usb_validate_midi_desc(outjd)))
> > > > return -ENODEV;
> > >
> > > Yet it will return here if it is. Correct check would be
> > >
> > > + if (!(!injd || snd_usb_validate_midi_desc(injd)) ||
> > > + !(!outjd || snd_usb_validate_midi_desc(outjd)))
> > >
> > > AFAICT.
> >
> > Erm, right, but a better representation is:
> >
> > if ((injd && !snd_usb_validate_midi_desc(injd)) ||
> > (outjd && !snd_usb_validate_midi_desc(injd)))
>
> Of course, another typo:
>
> if ((injd && !snd_usb_validate_midi_desc(injd)) ||
> (outjd && !snd_usb_validate_midi_desc(outjd)))

Agreed, that is better. I was focusing on boolean algebra too much.

Best regards,
Pavel
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

Attachment: signature.asc
Description: PGP signature