From: Ranjani Sridharan Subject: Re: [RESEND PATCH v2] ASoC: SOF: Intel: hda: Make hdac_device device-managed Date: Mon, 15 Jul 2019 08:27:55 -0700 Message-ID: <7fc6fdf3461c8faff4d853f80e282f3830a04724.camel@linux.intel.com> References: <20190707235633.7114-1-ranjani.sridharan@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id EB47AF800C6 for ; Mon, 15 Jul 2019 17:27:58 +0200 (CEST) In-Reply-To: <20190707235633.7114-1-ranjani.sridharan@linux.intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" To: alsa-devel@alsa-project.org, broonie@kernel.org Cc: tiwai@suse.de, libin.yang@intel.com, Pierre-Louis Bossart List-Id: alsa-devel@alsa-project.org On Sun, 2019-07-07 at 16:56 -0700, Ranjani Sridharan wrote: > 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. > > Because of the above change, hda_codec is device-managed and > it will be freed when the ASoC device is removed. Freeing > the codec in snd_hda_codec_dev_release() leads to kernel > panic while unloading and reloading the ASoC driver. So, > avoid freeing the hda_codec for ASoC driver. This is done in > the same patch to avoid bisect failure. Hi Mark, This patch is needed for the module load/unload stress tests for the Intel platforms with SOF. Could you please help review it? The details of the issue can be found here: https://github.com/thesofproject/linux/issues/966 Thanks, Ranjani > > Signed-off-by: Libin Yang > Signed-off-by: Ranjani Sridharan > Reviewed-by: Takashi Iwai > Reviewed-by: Pierre-Louis Bossart < > pierre-louis.bossart@linux.intel.com> > --- > sound/pci/hda/hda_codec.c | 8 +++++++- > sound/soc/sof/intel/hda-codec.c | 6 ++---- > 2 files changed, 9 insertions(+), 5 deletions(-) > > 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 > 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; >