From: Takashi Iwai <tiwai@suse.de>
To: Mark Brown <broonie@kernel.org>
Cc: alsa-devel@alsa-project.org, Robert Jarzmik <robert.jarzmik@free.fr>
Subject: Re: BUG: double free of PCM structure upon module removal
Date: Tue, 23 May 2017 20:14:07 +0200 [thread overview]
Message-ID: <s5hefvfo2z4.wl-tiwai@suse.de> (raw)
In-Reply-To: <20170523171405.iyahe4zfxerd7rn7@sirena.org.uk>
On Tue, 23 May 2017 19:14:05 +0200,
Mark Brown wrote:
>
> On Tue, May 23, 2017 at 06:46:58PM +0200, Robert Jarzmik wrote:
>
> > Did you notice the same behavior on other platforms, and if not would you have a
> > hint why it happens to me ?
>
> This is the only report I've seen, sorry. It's not ringing any bells
> immediately either - I'll have a think.
What's the problem? soc_free_pcm_runtime() just calls kfree() of rtd,
but it's not called in snd_pcm_free(), isn't it?
In anyway the calls there look in a wrong order. Basically we should
start with snd_card_free() to sync with the whole operation finishes,
then release everything. Below is an untested patch to do that.
Takashi
---
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2047,6 +2047,8 @@ int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
EXPORT_SYMBOL_GPL(snd_soc_set_dmi_name);
#endif /* CONFIG_DMI */
+static void soc_cleanup_card_resources(struct snd_card *scard);
+
static int snd_soc_instantiate_card(struct snd_soc_card *card)
{
struct snd_soc_codec *codec;
@@ -2228,6 +2230,8 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
}
card->instantiated = 1;
+ card->snd_card->private_data = card;
+ card->snd_card->private_free = soc_cleanup_card_resources;
snd_soc_dapm_sync(&card->dapm);
mutex_unlock(&card->mutex);
mutex_unlock(&client_mutex);
@@ -2278,8 +2282,9 @@ static int soc_probe(struct platform_device *pdev)
return snd_soc_register_card(card);
}
-static int soc_cleanup_card_resources(struct snd_soc_card *card)
+static void soc_cleanup_card_resources(struct snd_card *scard)
{
+ struct snd_soc_card *card = scard->private_data;
struct snd_soc_pcm_runtime *rtd;
/* make sure any delayed work runs */
@@ -2299,10 +2304,6 @@ static int soc_cleanup_card_resources(struct snd_soc_card *card)
/* remove the card */
if (card->remove)
card->remove(card);
-
- snd_card_free(card->snd_card);
- return 0;
-
}
/* removes a socdev */
@@ -2887,7 +2888,7 @@ int snd_soc_unregister_card(struct snd_soc_card *card)
if (card->instantiated) {
card->instantiated = false;
snd_soc_dapm_shutdown(card);
- soc_cleanup_card_resources(card);
+ snd_card_free(card->snd_card);
dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name);
}
next prev parent reply other threads:[~2017-05-23 18:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-23 16:46 BUG: double free of PCM structure upon module removal Robert Jarzmik
2017-05-23 17:14 ` Mark Brown
2017-05-23 18:14 ` Takashi Iwai [this message]
2017-05-24 6:31 ` Robert Jarzmik
2017-05-24 6:39 ` Takashi Iwai
2017-05-24 7:58 ` Robert Jarzmik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=s5hefvfo2z4.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=robert.jarzmik@free.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.