ALSA: hda: release resource when snd_hdac_device_init is failed
PATCH 1/1 ALSA: hda: release resource when snd_hdac_device_init is failed
From: Rander Wang <[email protected]>
When snd_hdac_device_init is failed, the codec is released by kfree immediately without releasing some resources. The vendor_name should be free if the memory is allocated and the runtime pm status should be restored, especially the runtime pm status of parent device.
--- sound/hda/hdac_device.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
sound/hda/hdac_device.c +5 -1
@@ -109,12 +109,16 @@ int snd_hdac_device_init(struct hdac_device *codec, struct hdac_bus *bus, codec->vendor_id & 0xffff);if (!codec->chip_name) { err = -ENOMEM ; - goto error; + goto error_chip; }return 0 ; + error_chip: +kfree (codec->vendor_name); error: +pm_runtime_put_noidle (&codec->dev); +pm_runtime_set_suspended (&codec->dev);put_device (&codec->dev);return err; }
Signature · 1 line
2.27.0
Quoted 7 lines · Kai Vehmanen
From: Rander Wang <[email protected]>
When
snd_hdac_device_initis failed, the codec is released by kfree immediately without releasing some resources. Thevendor_nameshould be free if the memory is allocated and the runtime pm status should be restored, especially the runtime pm status of parent device.
It's released via put_device() and this should call the release callback, default_release(), and it contains all those kfree()'s and pm_runtime_*().
Could you double-check whether it's really missing?
thanks,
Takashi
Quoted 36 lines
Signed-off-by Rander Wang <[email protected]>Reviewed-by Ranjani Sridharan <[email protected]>Reviewed-by Pierre-Louis Bossart <[email protected]>Reviewed-by Bard Liao <[email protected]>Reviewed-by Guennadi Liakhovetski <[email protected]>Signed-off-by Kai Vehmanen <[email protected]>--- sound/hda/hdac_device.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)sound/hda/hdac_device.c +5
-1@@ -109,12 +109,16 @@ int snd_hdac_device_init(struct hdac_device *codec, struct hdac_bus *bus, codec->vendor_id & 0xffff);if (!codec->chip_name) { err = -ENOMEM ; - goto error; + goto error_chip; }return 0 ; + error_chip: +kfree (codec->vendor_name); error: +pm_runtime_put_noidle (&codec->dev); +pm_runtime_set_suspended (&codec->dev);put_device (&codec->dev);return err; }Signature · 1 line
2.27.0
Hey,
Quoted 9 lines · Takashi Iwai
Quoted 2 lines · Kai Vehmanen
When
snd_hdac_device_initis failed, the codec is released by kfree immediately without releasing some resources. Thevendor_nameshouldIt's released via
put_device()and this should call the release callback,default_release(), and it contains all those kfree()'s and pm_runtime_*().Could you double-check whether it's really missing?
ack, thanks for spotting. put_device() indeed calls the default release, so this patch is not correct.
Rander, can you check as well this matches with the scenario you were looking at?
Br, Kai
Thanks, I got the point, so the fix in snd_hdac_device_exit will resolve the issue completely.
Rander
Quoted 33 lines
-----Original Message-----
From: Kai Vehmanen <[email protected]>
Sent: Friday, September 4, 2020 7:31 PM
To: Takashi Iwai <[email protected]>; Wang, Rander <[email protected]>
Cc: Kai Vehmanen <[email protected]>; alsa-devel@alsa- project.org; Ranjani Sridharan <[email protected]>; Pierre- Louis Bossart <[email protected]>; Bard Liao <yung- [email protected]>; Guennadi Liakhovetski <[email protected]>
Subject: Re: [PATCH] ALSA: hda: release resource whensnd_hdac_device_initis failedHey,
Quoted 9 lines · Takashi Iwai
Quoted 2 lines · Kai Vehmanen
When
snd_hdac_device_initis failed, the codec is released by kfree immediately without releasing some resources. Thevendor_nameshouldIt's released via
put_device()and this should call the release callback,default_release(), and it contains all those kfree()'s and pm_runtime_*().Could you double-check whether it's really missing?
ack, thanks for spotting.
put_device()indeed calls the default release, so this patch is not correct.Rander, can you check as well this matches with the scenario you were looking at?
Br, Kai