Skip to content

Commit 59e1947

Browse files
sherllytiwai
authored andcommitted
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: 447d627 ("ALSA: usb-audio: Add sanity checks for endpoint accesses") Signed-off-by: Xiyu Yang <[email protected]> Signed-off-by: Xin Tan <[email protected]> Cc: <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent fef66ae commit 59e1947

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

sound/usb/mixer_quirks.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,11 +1509,15 @@ static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
15091509

15101510
/* use known values for that card: interface#1 altsetting#1 */
15111511
iface = usb_ifnum_to_if(chip->dev, 1);
1512-
if (!iface || iface->num_altsetting < 2)
1513-
return -EINVAL;
1512+
if (!iface || iface->num_altsetting < 2) {
1513+
err = -EINVAL;
1514+
goto end;
1515+
}
15141516
alts = &iface->altsetting[1];
1515-
if (get_iface_desc(alts)->bNumEndpoints < 1)
1516-
return -EINVAL;
1517+
if (get_iface_desc(alts)->bNumEndpoints < 1) {
1518+
err = -EINVAL;
1519+
goto end;
1520+
}
15171521
ep = get_endpoint(alts, 0)->bEndpointAddress;
15181522

15191523
err = snd_usb_ctl_msg(chip->dev,

0 commit comments

Comments
 (0)