Skip to contentSkip to conversation

ALSA: core: Make sure to call snd_card_disconnect() at freeing

PATCH In review Takashi Iwai 1 participant 2 messages Oct 1 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: core: Make sure to call snd_card_disconnect() at freeing

When a card object gets freed via devres, it might be freed without calling snd_card_disconnect(), and it might forget to release some resources such as the procfs that gets deleted at the disconnect call.

Add an explicit call of snd_card_disconnect() at snd_card_do_free() for assuring the preparation for cleanup.

Fixes e8ad415b7a55 ("ALSA: core: Add managed card creation")

---

This patch is required as a prerequisite for the recent cleanup series to use auto-cleanup:
http://lore.kernel.org/[email protected]

 sound/core/init.c | 4 ++++
 1 file changed, 4 insertions(+)
sound/core/init.c +4 -0
index 0897b3a11617..764d3d1073e7 100644
@@ -564,6 +564,10 @@ static int snd_card_do_free(struct snd_card *card)
 	bool managed = card->managed;
 
 	card->releasing = true;
+
+	/* for case without explicit disconnect call (e.g. via devres) */
+	snd_card_disconnect(card);
+
 #if IS_ENABLED(CONFIG_SND_MIXER_OSS)
 	if (snd_mixer_oss_notify_callback)
 		snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_FREE);
Signature · 1 line
2.55.0
#1 lore raw
Quoted 8 lines · Takashi Iwai

When a card object gets freed via devres, it might be freed without calling snd_card_disconnect(), and it might forget to release some resources such as the procfs that gets deleted at the disconnect call.

Add an explicit call of snd_card_disconnect() at snd_card_do_free() for assuring the preparation for cleanup.

Quoted 7 lines
Fixes e8ad415b7a55 ("ALSA: core: Add managed card creation")

---

This patch is required as a prerequisite for the recent cleanup series to use auto-cleanup:
http://lore.kernel.org/[email protected]

Scratch this (and the series above).

It turned out that this can be problematic in another subtle way. Namely, when snd_card_disconnect() is called from the card_dev's destructor, it can double-free the card_dev via device_del(). Skipping this call doesn't suffice as dpm_list may be still unbalanced without the explicit call of device_del() beforehand...

A new fix and another series of cleanups will come up later.

Takashi