ALSA: usx2y: Fix potential memory leaks
authorTakashi Iwai <tiwai@suse.de>
Mon, 17 May 2021 13:15:40 +0000 (15:15 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 17 May 2021 14:04:40 +0000 (16:04 +0200)
commit02d382af1c4e321acbea1c25b97ee13f52b9ac7d
treefb3cca599b57c244879a96cdf4166bbe77424dbf
parenta11aa8537e13dd1082c85b102b98afc2a156a815
ALSA: usx2y: Fix potential memory leaks

Theoretically the initialization functions in usx2y drivers may be
called multiple times as the driver gets initialized via hwpdep
ioctl.  Meanwhile, those functions including memory allocations don't
check whether they are called twice, and they forget the old
resources, which would lead to memory leaks.

This patch adds the sanity checks about the doubly initializations to
give kernel WARNING, and returns an error in such a case.  Also, each
allocation assures to release the resources at its error path
properly.

Link: https://lore.kernel.org/r/20210517131545.27252-7-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/usb/usx2y/usbusx2y.c