[alsa-devel] [PATCH 0/2] Fixes for SOF module unload/reload
A recent commit "ALSA: hdac: fix memory release for SST and SOF drivers" removed the kfree call for the hdac device in snd_hdac_ext_bus_device_exit(). This requires that the SOF driver also make the hdac_device and hdac_hda_priv device-managed so that they can be freed when the SOF module in unloaded. The first patch takes care of this change.
Additionally, because of the above change, the hda_codec is device-managed and freeing it in snd_hda_codec_dev_release() leads to kernel panic with module unload/reload stress tests. The second patch includes the change to avoid freeing hda_codec for ASoC driver.
More details for the module unload/reload test failures can be found here: https://github.com/thesofproject/linux/issues/966
Ranjani Sridharan (2): ASoC: SOF: Intel: hda: Make hdac_device device-managed ASoC: hda: don't free hda_codec for HDA_DEV_ASOC type
sound/pci/hda/hda_codec.c | 8 +++++++- sound/soc/sof/intel/hda-codec.c | 6 ++---- 2 files changed, 9 insertions(+), 5 deletions(-)
snd_hdac_ext_bus_device_exit() has been recently modified to no longer free the hdac device. SOF allocates memory for hdac_device and hda_hda_priv with kzalloc. Make them device-managed instead so that they will be freed when the SOF driver is unloaded.
Signed-off-by: Libin Yang libin.yang@intel.com Signed-off-by: Ranjani Sridharan ranjani.sridharan@linux.intel.com --- sound/soc/sof/intel/hda-codec.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/sound/soc/sof/intel/hda-codec.c b/sound/soc/sof/intel/hda-codec.c index b8b37f082309..0d8437b080bf 100644 --- a/sound/soc/sof/intel/hda-codec.c +++ b/sound/soc/sof/intel/hda-codec.c @@ -62,8 +62,7 @@ static int hda_codec_probe(struct snd_sof_dev *sdev, int address) address, resp);
#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC) - /* snd_hdac_ext_bus_device_exit will use kfree to free hdev */ - hda_priv = kzalloc(sizeof(*hda_priv), GFP_KERNEL); + hda_priv = devm_kzalloc(sdev->dev, sizeof(*hda_priv), GFP_KERNEL); if (!hda_priv) return -ENOMEM;
@@ -82,8 +81,7 @@ static int hda_codec_probe(struct snd_sof_dev *sdev, int address)
return 0; #else - /* snd_hdac_ext_bus_device_exit will use kfree to free hdev */ - hdev = kzalloc(sizeof(*hdev), GFP_KERNEL); + hdev = devm_kzalloc(sdev->dev, sizeof(*hdev), GFP_KERNEL); if (!hdev) return -ENOMEM;
In the case of ASoC driver, the hdac_hda_priv pointer containing the hda_codec is device-managed. It will be freed when the ASoC device is removed during driver unloading. Freeing the codec in snd_hda_codec_dev_release() leads to kernel panics while unloading and reloading the ASoC driver.
Signed-off-by: Ranjani Sridharan ranjani.sridharan@linux.intel.com --- sound/pci/hda/hda_codec.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 6c51b8363f8b..a2e23d7e768f 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -846,7 +846,13 @@ static void snd_hda_codec_dev_release(struct device *dev) snd_hda_sysfs_clear(codec); kfree(codec->modelname); kfree(codec->wcaps); - kfree(codec); + + /* + * In the case of ASoC HD-audio, hda_codec is device managed. + * It will be freed when the ASoC device is removed. + */ + if (codec->core.type == HDA_DEV_LEGACY) + kfree(codec); }
#define DEV_NAME_LEN 31
On Wed, 26 Jun 2019 08:29:33 +0200, Ranjani Sridharan wrote:
A recent commit "ALSA: hdac: fix memory release for SST and SOF drivers" removed the kfree call for the hdac device in snd_hdac_ext_bus_device_exit(). This requires that the SOF driver also make the hdac_device and hdac_hda_priv device-managed so that they can be freed when the SOF module in unloaded. The first patch takes care of this change.
Additionally, because of the above change, the hda_codec is device-managed and freeing it in snd_hda_codec_dev_release() leads to kernel panic with module unload/reload stress tests. The second patch includes the change to avoid freeing hda_codec for ASoC driver.
In such a case, both patch need to be put into a single patch. Otherwise it leads to a bisection failure.
thanks,
Takashi
More details for the module unload/reload test failures can be found here: https://github.com/thesofproject/linux/issues/966
Ranjani Sridharan (2): ASoC: SOF: Intel: hda: Make hdac_device device-managed ASoC: hda: don't free hda_codec for HDA_DEV_ASOC type
sound/pci/hda/hda_codec.c | 8 +++++++- sound/soc/sof/intel/hda-codec.c | 6 ++---- 2 files changed, 9 insertions(+), 5 deletions(-)
-- 2.17.1
On Wed, 2019-06-26 at 08:44 +0200, Takashi Iwai wrote:
On Wed, 26 Jun 2019 08:29:33 +0200, Ranjani Sridharan wrote:
A recent commit "ALSA: hdac: fix memory release for SST and SOF drivers" removed the kfree call for the hdac device in snd_hdac_ext_bus_device_exit(). This requires that the SOF driver also make the hdac_device and hdac_hda_priv device-managed so that they can be freed when the SOF module in unloaded. The first patch takes care of this change.
Additionally, because of the above change, the hda_codec is device-managed and freeing it in snd_hda_codec_dev_release() leads to kernel panic with module unload/reload stress tests. The second patch includes the change to avoid freeing hda_codec for ASoC driver.
In such a case, both patch need to be put into a single patch. Otherwise it leads to a bisection failure.
Thanks, Takashi. Just sent a v2 combining both the changes.
Thanks, Ranjani
thanks,
Takashi
More details for the module unload/reload test failures can be found here: https://github.com/thesofproject/linux/issues/966
Ranjani Sridharan (2): ASoC: SOF: Intel: hda: Make hdac_device device-managed ASoC: hda: don't free hda_codec for HDA_DEV_ASOC type
sound/pci/hda/hda_codec.c | 8 +++++++- sound/soc/sof/intel/hda-codec.c | 6 ++---- 2 files changed, 9 insertions(+), 5 deletions(-)
-- 2.17.1
Alsa-devel mailing list Alsa-devel@alsa-project.org https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
participants (2)
-
Ranjani Sridharan
-
Takashi Iwai