ALSA: compress: Initialize mutex in snd_compress_new()
authorTakashi Iwai <tiwai@suse.de>
Wed, 14 Jul 2021 16:24:24 +0000 (18:24 +0200)
committerTakashi Iwai <tiwai@suse.de>
Thu, 15 Jul 2021 08:22:38 +0000 (10:22 +0200)
Currently the snd_compr.lock mutex isn't initialized in the API
functions although the lock is used many places in other code in
compress offload API.  It's because the object was expected to be
initialized via snd_compress_register(), but this was never used by
ASoC, which is the only user.  Instead, ASoC initializes the mutex by
itself, and this is error-prone.

This patch moves the mutex initialization into the more appropriate
place, snd_compress_new(), for avoiding the missing init.

Reviewed-by: Mark Brown <broonie@kernel.org>
Acked-by: Vinod Koul <vkoul@kernel.org>
Reviewed-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Link: https://lore.kernel.org/r/20210714162424.4412-3-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/compress_offload.c
sound/soc/soc-compress.c

index ed5546ae300a7fe219e04ee8195545974b051698..de514ec8c83d547ca798264079674110771dc0f9 100644 (file)
@@ -1177,6 +1177,7 @@ int snd_compress_new(struct snd_card *card, int device,
        compr->card = card;
        compr->device = device;
        compr->direction = dirn;
+       mutex_init(&compr->lock);
 
        snd_compress_set_id(compr, id);
 
index b4f59350a5a8a6dbd25077177cb41e304ed0eb54..36060800e9bd9752e06b309840e61acf22d0ec99 100644 (file)
@@ -604,7 +604,6 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
                break;
        }
 
-       mutex_init(&compr->lock);
        ret = snd_compress_new(rtd->card->snd_card, num, direction,
                                new_name, compr);
        if (ret < 0) {