Commit 0141254b authored by Johan Hovold's avatar Johan Hovold Committed by Takashi Iwai

ALSA: usb-audio: fix set_format altsetting sanity check

Make sure to check the return value of usb_altnum_to_altsetting() to
avoid dereferencing a NULL pointer when the requested alternate settings
is missing.

The format altsetting number may come from a quirk table and there does
not seem to be any other validation of it (the corresponding index is
checked however).

Fixes: b099b969 ("ALSA: usb-audio: Avoid superfluous usb_set_interface() calls")
Cc: stable <stable@vger.kernel.org>     # 4.18
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20191220093134.1248-1-johan@kernel.orgSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 66c5d718
...@@ -506,9 +506,9 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) ...@@ -506,9 +506,9 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
if (WARN_ON(!iface)) if (WARN_ON(!iface))
return -EINVAL; return -EINVAL;
alts = usb_altnum_to_altsetting(iface, fmt->altsetting); alts = usb_altnum_to_altsetting(iface, fmt->altsetting);
altsd = get_iface_desc(alts); if (WARN_ON(!alts))
if (WARN_ON(altsd->bAlternateSetting != fmt->altsetting))
return -EINVAL; return -EINVAL;
altsd = get_iface_desc(alts);
if (fmt == subs->cur_audiofmt && !subs->need_setup_fmt) if (fmt == subs->cur_audiofmt && !subs->need_setup_fmt)
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment