Skip to contentSkip to conversation

ALSA: hda: release resource when snd_hdac_device_init is failed

PATCH In review Kai Vehmanen 3 participants 4 messages Sep 2, 2020 – Sep 7, 2020 Sound

lore
Share & tools
lore
#0 lore raw

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
index 3e9e9ac804f6..8d9d37225701 100644
@@ -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
#1 lore raw
Quoted 7 lines · Kai Vehmanen

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.

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
---
 sound/hda/hdac_device.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
sound/hda/hdac_device.c +5 -1
index 3e9e9ac804f6..8d9d37225701 100644
@@ -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
#2 lore raw

Hey,

Quoted 9 lines · Takashi Iwai
Quoted 2 lines · Kai Vehmanen

When snd_hdac_device_init is failed, the codec is released by kfree immediately without releasing some resources. The vendor_name should

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?

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

#3 lore raw

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 when snd_hdac_device_init is failed

Hey,

Quoted 9 lines · Takashi Iwai
Quoted 2 lines · Kai Vehmanen

When snd_hdac_device_init is failed, the codec is released by kfree immediately without releasing some resources. The vendor_name should

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?

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