diff mbox series

[v2] ASoC: hda: fix unbalanced codec dev refcount for HDA_DEV_ASOC

Message ID 20190531160137.5603-1-ranjani.sridharan@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [v2] ASoC: hda: fix unbalanced codec dev refcount for HDA_DEV_ASOC | expand

Commit Message

Ranjani Sridharan May 31, 2019, 4:01 p.m. UTC
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.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
---
 sound/pci/hda/hda_codec.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Takashi Iwai May 31, 2019, 5:06 p.m. UTC | #1
On Fri, 31 May 2019 18:01:37 +0200,
Ranjani Sridharan wrote:
> 
> 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.
> 
> Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>

Reviewed-by: Takashi Iwai <tiwai@suse.de>

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
diff mbox series

Patch

diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index b20eb7fc83eb..fcdf2cd3783b 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -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;
 }