Skip to contentSkip to conversation

ASoC: hda: fix unbalanced codec dev refcount for HDA_DEV_ASOC

PATCH In review Ranjani Sridharan 3 participants 3 messages May 31, 2019 – Jun 3, 2019 Sound

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ASoC: hda: fix unbalanced codec dev refcount for HDA_DEV_ASOC

HDA_DEV_ASOC type codec device refcounts are managed differently from HDA_DEV_LEGACY devices. The refcount is released explicitly in snd_hdac_ext_bus_device_remove() for ASOC type devices. So, remove the put_device() call in snd_hda_codec_dev_free() for such devices to make the refcount balanced. This will prevent the NULL pointer exception when the codec driver is released after the card is freed.

---
 sound/pci/hda/hda_codec.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
sound/pci/hda/hda_codec.c +8 -1
index b20eb7fc83eb..fcdf2cd3783b 100644
@@ -840,7 +840,14 @@ static int snd_hda_codec_dev_free(struct snd_device *device)
 	if (codec->core.type == HDA_DEV_LEGACY)
 		snd_hdac_device_unregister(&codec->core);
 	codec_display_power(codec, false);
-	put_device(hda_codec_dev(codec));
+
+	/*
+	 * In the case of ASoC HD-audio bus, the device refcount is released in
+	 * snd_hdac_ext_bus_device_remove() explicitly.
+	 */
+	if (codec->core.type == HDA_DEV_LEGACY)
+		put_device(hda_codec_dev(codec));
+
 	return 0;
 }
 
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines · Ranjani Sridharan

HDA_DEV_ASOC type codec device refcounts are managed differently from HDA_DEV_LEGACY devices. The refcount is released explicitly in snd_hdac_ext_bus_device_remove() for ASOC type devices. So, remove the put_device() call in snd_hda_codec_dev_free() for such devices to make the refcount balanced. This will prevent the NULL pointer exception when the codec driver is released after the card is freed.

FWIW, snd_hdac_ext_bus_device_remove() is called at the machine driver remove callback that is called from soc_remove_dai_linkes() in soc_cleanup_card_resources(). There, the order is assured that snd_card_free() gets called at first, so this change should be correct -- the HD-audio codec object gets freed at a later point for ASoC.

thanks,

Takashi

#2 lore raw

Applied "ASoC: hda: fix unbalanced codec dev refcount for HDA_DEV_ASOC" to the asoc tree

In reply to Ranjani Sridharan

The patch

ASoC: hda: fix unbalanced codec dev refcount for HDA_DEV_ASOC

has been applied to the asoc tree at

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.2

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From d6947bb234dcc86e878d502516d0fb9d635aa2ae Mon Sep 17 00:00:00 2001

From: Ranjani Sridharan <[email protected]>
Date: Fri, 31 May 2019 09:01:37 -0700
Subject: [PATCH] ASoC: hda: fix unbalanced codec dev refcount for HDA_DEV_ASOC

HDA_DEV_ASOC type codec device refcounts are managed differently from HDA_DEV_LEGACY devices. The refcount is released explicitly in snd_hdac_ext_bus_device_remove() for ASOC type devices. So, remove the put_device() call in snd_hda_codec_dev_free() for such devices to make the refcount balanced. This will prevent the NULL pointer exception when the codec driver is released after the card is freed.

---
 sound/pci/hda/hda_codec.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
sound/pci/hda/hda_codec.c +8 -1
index ec0b8595eb4d..6cdec64dc68a 100644
@@ -834,7 +834,14 @@ static int snd_hda_codec_dev_free(struct snd_device *device)
 	codec->in_freeing = 1;
 	snd_hdac_device_unregister(&codec->core);
 	codec_display_power(codec, false);
-	put_device(hda_codec_dev(codec));
+
+	/*
+	 * In the case of ASoC HD-audio bus, the device refcount is released in
+	 * snd_hdac_ext_bus_device_remove() explicitly.
+	 */
+	if (codec->core.type == HDA_DEV_LEGACY)
+		put_device(hda_codec_dev(codec));
+
 	return 0;
 }
 
Signature · 1 line
2.20.1