All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Fixes for SOF module unload/reload
@ 2019-06-26  6:29 Ranjani Sridharan
  2019-06-26  6:29 ` [PATCH 1/2] ASoC: SOF: Intel: hda: Make hdac_device device-managed Ranjani Sridharan
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ranjani Sridharan @ 2019-06-26  6:29 UTC (permalink / raw)
  To: alsa-devel; +Cc: tiwai, libin.yang, broonie, pierre-louis.bossart

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(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] ASoC: SOF: Intel: hda: Make hdac_device device-managed
  2019-06-26  6:29 [PATCH 0/2] Fixes for SOF module unload/reload Ranjani Sridharan
@ 2019-06-26  6:29 ` Ranjani Sridharan
  2019-06-26  6:29 ` [PATCH 2/2] ASoC: hda: don't free hda_codec for HDA_DEV_ASOC type Ranjani Sridharan
  2019-06-26  6:44 ` [PATCH 0/2] Fixes for SOF module unload/reload Takashi Iwai
  2 siblings, 0 replies; 5+ messages in thread
From: Ranjani Sridharan @ 2019-06-26  6:29 UTC (permalink / raw)
  To: alsa-devel; +Cc: tiwai, libin.yang, broonie, pierre-louis.bossart

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;
 
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] ASoC: hda: don't free hda_codec for HDA_DEV_ASOC type
  2019-06-26  6:29 [PATCH 0/2] Fixes for SOF module unload/reload Ranjani Sridharan
  2019-06-26  6:29 ` [PATCH 1/2] ASoC: SOF: Intel: hda: Make hdac_device device-managed Ranjani Sridharan
@ 2019-06-26  6:29 ` Ranjani Sridharan
  2019-06-26  6:44 ` [PATCH 0/2] Fixes for SOF module unload/reload Takashi Iwai
  2 siblings, 0 replies; 5+ messages in thread
From: Ranjani Sridharan @ 2019-06-26  6:29 UTC (permalink / raw)
  To: alsa-devel; +Cc: tiwai, libin.yang, broonie, pierre-louis.bossart

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
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] Fixes for SOF module unload/reload
  2019-06-26  6:29 [PATCH 0/2] Fixes for SOF module unload/reload Ranjani Sridharan
  2019-06-26  6:29 ` [PATCH 1/2] ASoC: SOF: Intel: hda: Make hdac_device device-managed Ranjani Sridharan
  2019-06-26  6:29 ` [PATCH 2/2] ASoC: hda: don't free hda_codec for HDA_DEV_ASOC type Ranjani Sridharan
@ 2019-06-26  6:44 ` Takashi Iwai
  2019-06-26  7:07   ` Ranjani Sridharan
  2 siblings, 1 reply; 5+ messages in thread
From: Takashi Iwai @ 2019-06-26  6:44 UTC (permalink / raw)
  To: Ranjani Sridharan; +Cc: libin.yang, alsa-devel, broonie, pierre-louis.bossart

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
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] Fixes for SOF module unload/reload
  2019-06-26  6:44 ` [PATCH 0/2] Fixes for SOF module unload/reload Takashi Iwai
@ 2019-06-26  7:07   ` Ranjani Sridharan
  0 siblings, 0 replies; 5+ messages in thread
From: Ranjani Sridharan @ 2019-06-26  7:07 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: libin.yang, alsa-devel, broonie, pierre-louis.bossart

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-06-26  7:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-26  6:29 [PATCH 0/2] Fixes for SOF module unload/reload Ranjani Sridharan
2019-06-26  6:29 ` [PATCH 1/2] ASoC: SOF: Intel: hda: Make hdac_device device-managed Ranjani Sridharan
2019-06-26  6:29 ` [PATCH 2/2] ASoC: hda: don't free hda_codec for HDA_DEV_ASOC type Ranjani Sridharan
2019-06-26  6:44 ` [PATCH 0/2] Fixes for SOF module unload/reload Takashi Iwai
2019-06-26  7:07   ` Ranjani Sridharan

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.