Commit 59e1947c authored by Xiyu Yang's avatar Xiyu Yang Committed by Takashi Iwai

ALSA: usb-audio: Fix usb audio refcnt leak when getting spdif

snd_microii_spdif_default_get() invokes snd_usb_lock_shutdown(), which
increases the refcount of the snd_usb_audio object "chip".

When snd_microii_spdif_default_get() returns, local variable "chip"
becomes invalid, so the refcount should be decreased to keep refcount
balanced.

The reference counting issue happens in several exception handling paths
of snd_microii_spdif_default_get(). When those error scenarios occur
such as usb_ifnum_to_if() returns NULL, the function forgets to decrease
the refcnt increased by snd_usb_lock_shutdown(), causing a refcnt leak.

Fix this issue by jumping to "end" label when those error scenarios
occur.

Fixes: 447d6275 ("ALSA: usb-audio: Add sanity checks for endpoint accesses")
Signed-off-by: default avatarXiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: default avatarXin Tan <tanxin.ctf@gmail.com>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/1587617711-13200-1-git-send-email-xiyuyang19@fudan.edu.cnSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent fef66ae7
......@@ -1509,11 +1509,15 @@ static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
/* use known values for that card: interface#1 altsetting#1 */
iface = usb_ifnum_to_if(chip->dev, 1);
if (!iface || iface->num_altsetting < 2)
return -EINVAL;
if (!iface || iface->num_altsetting < 2) {
err = -EINVAL;
goto end;
}
alts = &iface->altsetting[1];
if (get_iface_desc(alts)->bNumEndpoints < 1)
return -EINVAL;
if (get_iface_desc(alts)->bNumEndpoints < 1) {
err = -EINVAL;
goto end;
}
ep = get_endpoint(alts, 0)->bEndpointAddress;
err = snd_usb_ctl_msg(chip->dev,
......
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