diff options
author | Takashi Iwai <tiwai@suse.de> | 2021-05-17 15:15:41 +0200 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2021-05-17 16:04:55 +0200 |
commit | c1f24841683f5ce902e49d35ba84abc3e3886427 (patch) | |
tree | 2222963d2a0c485326bdd402f5b5e19b9615a082 /sound/usb/usx2y/usx2yhwdeppcm.c | |
parent | ALSA: usx2y: Fix potential memory leaks (diff) | |
download | linux-c1f24841683f5ce902e49d35ba84abc3e3886427.tar.xz linux-c1f24841683f5ce902e49d35ba84abc3e3886427.zip |
ALSA: usxy2: Fix potential doubly allocations
The PCM shmem pages are allocated in snd_usx2y_usbpcm_prepare().
Theoretically the prepare callback may be called simultaneously for
both playback and capture, hence this allocation can be racy.
Make sure that the allocation is performed exclusively by extending
the pcm_mutex lock to cover the allocation code, too.
Link: https://lore.kernel.org/r/20210517131545.27252-8-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to '')
-rw-r--r-- | sound/usb/usx2y/usx2yhwdeppcm.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/sound/usb/usx2y/usx2yhwdeppcm.c b/sound/usb/usx2y/usx2yhwdeppcm.c index b988a4870de4..da643c2dbb12 100644 --- a/sound/usb/usx2y/usx2yhwdeppcm.c +++ b/sound/usb/usx2y/usx2yhwdeppcm.c @@ -503,15 +503,18 @@ static int snd_usx2y_usbpcm_prepare(struct snd_pcm_substream *substream) snd_printdd("snd_usx2y_pcm_prepare(%p)\n", substream); + mutex_lock(&usx2y->pcm_mutex); + if (!usx2y->hwdep_pcm_shm) { usx2y->hwdep_pcm_shm = alloc_pages_exact(USX2Y_HWDEP_PCM_PAGES, GFP_KERNEL); - if (!usx2y->hwdep_pcm_shm) - return -ENOMEM; + if (!usx2y->hwdep_pcm_shm) { + err = -ENOMEM; + goto up_prepare_mutex; + } memset(usx2y->hwdep_pcm_shm, 0, USX2Y_HWDEP_PCM_PAGES); } - mutex_lock(&usx2y->pcm_mutex); usx2y_subs_prepare(subs); // Start hardware streams // SyncStream first.... |