hdac_hda_codec_remove() disables runtime PM of the codec device before releasing the HDA link and calling the codec driver's remove callback, so that no runtime resume can race with the teardown and access the link or the already freed codec driver data. snd_hda_codec_cleanup_for_unbind() then disables runtime PM again. On the next probe snd_hda_codec_register() enables runtime PM only once, leaving it disabled after the ASoC card or the codec driver has been unbound and bound again: the codec stays powered and runtime_status reads 'unsupported'. Re-enable runtime PM at the end of hdac_hda_codec_remove() to balance its own disable. The codec remains disabled until it is registered again. With runtime PM enabled again the codec still does not suspend: the runtime status is RPM_SUSPENDED after the remove, while snd_hda_codec_device_new() powers the codec to D0 on probe. The pm_runtime_put()/snd_hda_power_down() calls see an already suspended device and the codec, its HDA link and the display power reference stay powered, preventing the controller from runtime suspending. Mark the device active after the codec has been powered up. Fixes: c3ec8ac82105 ("ASoC: hdac_hda: fix memleak on module unload") Cc: stable@vger.kernel.org Signed-off-by: Peter Ujfalusi --- sound/soc/codecs/hdac_hda.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sound/soc/codecs/hdac_hda.c b/sound/soc/codecs/hdac_hda.c index cae5711e979c..fe5796cad1ff 100644 --- a/sound/soc/codecs/hdac_hda.c +++ b/sound/soc/codecs/hdac_hda.c @@ -435,6 +435,13 @@ static int hdac_hda_codec_probe(struct snd_soc_component *component) goto error_no_pm; } + /* The codec is in D0, the status is RPM_SUSPENDED after a previous unbind */ + ret = pm_runtime_set_active(&hdev->dev); + if (ret < 0) { + dev_err(&hdev->dev, "%s: failed to set runtime PM active %d\n", __func__, ret); + goto error_no_pm; + } + #ifdef CONFIG_SND_HDA_PATCH_LOADER if (loadable_patch[hda_pvt->dev_index] && *loadable_patch[hda_pvt->dev_index]) { const struct firmware *fw __free(firmware) = NULL; @@ -554,6 +561,7 @@ static void hdac_hda_codec_remove(struct snd_soc_component *component) return; } + /* prevent runtime PM callbacks while the link and the codec are torn down */ pm_runtime_disable(&hdev->dev); snd_hdac_ext_bus_link_put(hdev->bus, hlink); @@ -561,6 +569,9 @@ static void hdac_hda_codec_remove(struct snd_soc_component *component) driver->ops->remove(codec); snd_hda_codec_cleanup_for_unbind(codec); + + /* Balances the disable above, cleanup_for_unbind keeps runtime PM disabled */ + pm_runtime_enable(&hdev->dev); } static const struct snd_soc_dapm_route hdac_hda_dapm_routes[] = { -- 2.56.0