All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Liao, Bard" <bard.liao@intel.com>
To: "tiwai@suse.de" <tiwai@suse.de>,
	"broonie@kernel.org" <broonie@kernel.org>
Cc: "alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>,
	"Girdwood, Liam R" <liam.r.girdwood@intel.com>,
	"Bossart, Pierre-louis" <pierre-louis.bossart@intel.com>
Subject: snd_hdac_device_unregister is called twice on ASoC driver
Date: Sun, 28 Apr 2019 01:46:56 +0000	[thread overview]
Message-ID: <567A313375B6F043A9BE3A1D9B8C6E7F0B425509@SHSMSX101.ccr.corp.intel.com> (raw)

Hi Takashi and all,

We meet a problem that snd_hdac_device_unregister will be called twice
on ASoC driver. We will call snd_hdac_ext_bus_device_init ->
snd_hdac_device_register and snd_hdac_ext_bus_device_remove ->
snd_hdac_device_unregister on ASoC driver. It looks even to me.
However, hdac_hda_codec_probe will call snd_hda_codec_device_new
to create a hda codec device. And it will assign snd_hda_codec_dev_free
to the .dev_free ops where snd_hdac_device_unregister will be called.
That's why snd_hdac_device_unregister will be call twice on ASoC driver.
Below patch can "fix" this issue, but I don't know if it is the right way
to fix it. Could you take a look and give me some advice?

--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -841,7 +841,13 @@ static int snd_hda_codec_dev_free(struct snd_device *device)
        struct hda_codec *codec = device->device_data;

        codec->in_freeing = 1;
-       snd_hdac_device_unregister(&codec->core);
+       /*
+        * snd_hda_codec_device_new() is used by legacy HDA and ASoC driver.
+        * We can't unregister ASoC device since it will be unregistered in
+        * snd_hdac_ext_bus_device_remove().
+        */
+       if (codec->core.type == HDA_DEV_LEGACY)
+               snd_hdac_device_unregister(&codec->core);
        codec_display_power(codec, false);
        put_device(hda_codec_dev(codec));
        return 0;

--- a/sound/soc/codecs/hdac_hda.c
+++ b/sound/soc/codecs/hdac_hda.c
@@ -328,6 +328,12 @@ static int hdac_hda_codec_probe(struct snd_soc_component *component)
                dev_err(&hdev->dev, "failed to create hda codec %d\n", ret);
                goto error_no_pm;
        }
+       /*
+        * Overwrite type to HDA_DEV_ASOC since it is a ASoC driver
+        * hda_codec.c will check this flag to determine if unregister
+        * device is needed.
+        */
+       hdev->type = HDA_DEV_ASOC;

        /*
         * snd_hda_codec_device_new decrements the usage count so call get pm

             reply	other threads:[~2019-04-28  1:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-28  1:46 Liao, Bard [this message]
2019-04-28  6:18 ` snd_hdac_device_unregister is called twice on ASoC driver Takashi Iwai

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=567A313375B6F043A9BE3A1D9B8C6E7F0B425509@SHSMSX101.ccr.corp.intel.com \
    --to=bard.liao@intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=liam.r.girdwood@intel.com \
    --cc=pierre-louis.bossart@intel.com \
    --cc=tiwai@suse.de \
    /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.