--- x/sound/core/init.c +++ y/sound/core/init.c @@ -577,9 +577,13 @@ void snd_card_disconnect_sync(struct snd } EXPORT_SYMBOL_GPL(snd_card_disconnect_sync); +static DEFINE_SPINLOCK(release_sl); + static int snd_card_do_free(struct snd_card *card) { + spin_lock(&release_sl); card->releasing = true; + spin_unlock(&release_sl); #if IS_ENABLED(CONFIG_SND_MIXER_OSS) if (snd_mixer_oss_notify_callback) snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_FREE); @@ -591,8 +595,10 @@ static int snd_card_do_free(struct snd_c dev_warn(card->dev, "unable to free card info\n"); /* Not fatal error */ } + spin_lock(&release_sl); if (card->release_completion) complete(card->release_completion); + spin_unlock(&release_sl); if (!card->managed) kfree(card); return 0; @@ -637,16 +643,20 @@ void snd_card_free(struct snd_card *card { DECLARE_COMPLETION_ONSTACK(released); + spin_lock(&release_sl); /* The call of snd_card_free() is allowed from various code paths; * a manual call from the driver and the call via devres_free, and * we need to avoid double-free. Moreover, the release via devres * may call snd_card_free() twice due to its nature, we need to have * the check here at the beginning. */ - if (card->releasing) + if (card->releasing) { + spin_unlock(&release_sl); return; + } card->release_completion = &released; + spin_unlock(&release_sl); snd_card_free_when_closed(card); /* wait, until all devices are ready for the free operation */