Skip to contentSkip to conversation

ASoC: Intel: avs: Add NULL check in avs_component_probe()

PATCH In review Henry Martin 5 participants 10 messages Apr 1, 2025 – Apr 7, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: Intel: avs: Add NULL check in avs_component_probe()

devm_kasprintf() returns NULL when memory allocation fails. Currently, avs_component_probe() does not check for this case, which results in a NULL pointer dereference.

Add NULL check after devm_kasprintf() to prevent this issue.

Fixes 739c031110da ("ASoC: Intel: avs: Provide support for fallback topology")
---
 sound/soc/intel/avs/pcm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
sound/soc/intel/avs/pcm.c +2 -1
index dac463390da1..7072bcf4e56f 100644
@@ -927,7 +927,8 @@ static int avs_component_probe(struct snd_soc_component *component)
 		else
 			mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,
 							     "hda-generic-tplg.bin");
-
+		if (!mach->tplg_filename)
+			return -ENOMEM;
 		filename = kasprintf(GFP_KERNEL, "%s/%s", component->driver->topology_name_prefix,
 				     mach->tplg_filename);
 		if (!filename)
Signature · 1 line
2.34.1
#1 lore raw
Quoted 1 line

devm_kasprintf() returns NULL when memory allocation fails. Currently,

…
call? failed?

Quoted 1 line

Add NULL check after devm_kasprintf() to prevent this issue.

Do you generally propose here to improve the error handling?

…

sound/soc/intel/avs/pcm.c static int avs_component_probe(struct snd_soc_component *component) · line 931

Quoted 8 lines

+++ b/sound/soc/intel/avs/pcm.c

sound/soc/intel/avs/pcm.c +2 -1
@@ -927,7 +927,8 @@ static int avs_component_probe(struct snd_soc_component *component)
 		else
 			mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,
 							     "hda-generic-tplg.bin");
-
+		if (!mach->tplg_filename)
+			return -ENOMEM;

Can a blank line be desirable after such a statement?

Would another source code transformation become helpful with an additional update step?

- if (((vendor_id >> 16) & 0xFFFF) == 0x8086)
- mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,
- "hda-8086-generic-tplg.bin");
- else
- mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,
- "hda-generic-tplg.bin");
+ mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,

+						     (((vendor_id >> 16) & 0xFFFF) == 0x8086)
+						     ? "hda-8086-generic-tplg.bin"
+						     : "hda-generic-tplg.bin");

Regards,
Markus

#2 lore raw
Quoted 37 lines · Markus Elfring
Quoted 1 line

devm_kasprintf() returns NULL when memory allocation fails. Currently,

…
call? failed?

Quoted 1 line

Add NULL check after devm_kasprintf() to prevent this issue.

Do you generally propose here to improve the error handling?

…

sound/soc/intel/avs/pcm.c static int avs_component_probe(struct snd_soc_component *component) · line 931

Quoted 8 lines

+++ b/sound/soc/intel/avs/pcm.c

sound/soc/intel/avs/pcm.c +2 -1
@@ -927,7 +927,8 @@ static int avs_component_probe(struct snd_soc_component *component)
 		else
 			mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,
 							     "hda-generic-tplg.bin");
-
+		if (!mach->tplg_filename)
+			return -ENOMEM;

Can a blank line be desirable after such a statement?

Would another source code transformation become helpful with an additional update step?

(quoted diff) +4 -6
-		if (((vendor_id >> 16) & 0xFFFF) == 0x8086)
-			mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,
-							     "hda-8086-generic-tplg.bin");
-		else
-			mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,
-							     "hda-generic-tplg.bin");
+		mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,
+						     (((vendor_id >> 16) & 0xFFFF) == 0x8086)
+						     ? "hda-8086-generic-tplg.bin"
+						     : "hda-generic-tplg.bin");
Quoted 2 lines

Regards,
Markus

Please feel free to ignore Markus. He has a tendency to provide unclear and nonsense feedback. He has done this several times with my patch sets. I almost wonder if he is an internet troll.

In any case, this change makes sense to me.

#3 lore raw
Quoted 3 lines

Please feel free to ignore Markus. He has a tendency to provide unclear and nonsense feedback. He has done this several times with my patch sets. I almost wonder if he is an internet troll.

Can any of the published contributions change your mind?

Regards,
Markus

maintainer
#4 lore raw
In reply to Markus Elfring
Quoted 8 lines · Markus Elfring
Quoted 1 line

devm_kasprintf() returns NULL when memory allocation fails. Currently,

…
call? failed?

Quoted 1 line

Add NULL check after devm_kasprintf() to prevent this issue.

Do you generally propose here to improve the error handling?

Feel free to ignore Markus, he has a long history of sending unhelpful review comments and continues to ignore repeated requests to stop.

maintainer Reviewed-by on v1 1/1
#5 lore raw
In reply to Henry Martin
Quoted 5 lines · Henry Martin

devm_kasprintf() returns NULL when memory allocation fails. Currently, avs_component_probe() does not check for this case, which results in a NULL pointer dereference.

Add NULL check after devm_kasprintf() to prevent this issue.

This basically repeats the title, I'd suggest to drop this very line. In regard to the title, I believe:

ASoC: Intel: avs: Fix null-ptr-deref in avs_component_probe()

is more straightforward. That's what you're doing here afterall, fixing stuff.

Quoted 3 lines
Fixes 739c031110da ("ASoC: Intel: avs: Provide support for fallback topology")

Good catch, thanks for sending the fix, Martin. I'm rather strict when it comes to wording title/message but nothing more than a nitpick in this case.

Whether you would be willing to provide v2 or not, feel free to add my tag:

Quoted 18 lines
---
  sound/soc/intel/avs/pcm.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
sound/soc/intel/avs/pcm.c +2 -1
index dac463390da1..7072bcf4e56f 100644
@@ -927,7 +927,8 @@ static int avs_component_probe(struct snd_soc_component *component)
  		else
  			mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,
  							     "hda-generic-tplg.bin");
-
+		if (!mach->tplg_filename)
+			return -ENOMEM;
  		filename = kasprintf(GFP_KERNEL, "%s/%s", component->driver->topology_name_prefix,
  				     mach->tplg_filename);
  		if (!filename)
#6 lore raw

PATCH v2 1/1 ASoC: Intel: avs: Fix null-ptr-deref in avs_component_probe()

devm_kasprintf() returns NULL when memory allocation fails. Currently, avs_component_probe() does not check for this case, which results in a NULL pointer dereference.

Fixes 739c031110da ("ASoC: Intel: avs: Provide support for fallback topology")

---
V1 -> V2: No functional changes, just correct title and redundant commit message.

 sound/soc/intel/avs/pcm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
sound/soc/intel/avs/pcm.c +2 -1
index dac463390da1..7072bcf4e56f 100644
@@ -927,7 +927,8 @@ static int avs_component_probe(struct snd_soc_component *component)
 		else
 			mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,
 							     "hda-generic-tplg.bin");
-
+		if (!mach->tplg_filename)
+			return -ENOMEM;
 		filename = kasprintf(GFP_KERNEL, "%s/%s", component->driver->topology_name_prefix,
 				     mach->tplg_filename);
 		if (!filename)
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH v2] ASoC: Intel: avs: Fix null-ptr-deref in avs_component_probe()

Quoted 1 line

devm_kasprintf() returns NULL when memory allocation fails. Currently,

…
failed?

Can a summary phrase like “Prevent null pointer dereference in avs_component_probe()” a bit nicer?

…

sound/soc/intel/avs/pcm.c static int avs_component_probe(struct snd_soc_component *component) · line 931

Quoted 8 lines

+++ b/sound/soc/intel/avs/pcm.c

sound/soc/intel/avs/pcm.c +2 -1
@@ -927,7 +927,8 @@ static int avs_component_probe(struct snd_soc_component *component)
 		else
 			mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,
 							     "hda-generic-tplg.bin");
-
+		if (!mach->tplg_filename)
+			return -ENOMEM;

Can a blank line be desirable after such a statement?

Would another source code transformation become helpful with an additional update step?

- if (((vendor_id >> 16) & 0xFFFF) == 0x8086)
- mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,
- "hda-8086-generic-tplg.bin");
- else
- mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,
- "hda-generic-tplg.bin");
+ mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,

+						     (((vendor_id >> 16) & 0xFFFF) == 0x8086)
+						     ? "hda-8086-generic-tplg.bin"
+						     : "hda-generic-tplg.bin");

Regards,
Markus

maintainer
#8 lore raw

Re: [PATCH v2] ASoC: Intel: avs: Fix null-ptr-deref in avs_component_probe()

Quoted 6 lines · Markus Elfring
Quoted 1 line

devm_kasprintf() returns NULL when memory allocation fails. Currently,

…
failed?

Can a summary phrase like “Prevent null pointer dereference in avs_component_probe()” a bit nicer?

Feel free to ignore Markus, he has a long history of sending unhelpful review comments and continues to ignore repeated requests to stop.

maintainer
#9 lore raw

Re: [PATCH v2] ASoC: Intel: avs: Fix null-ptr-deref in avs_component_probe()

In reply to Henry Martin
Quoted 5 lines · Henry Martin

devm_kasprintf() returns NULL when memory allocation fails. Currently, avs_component_probe() does not check for this case, which results in a NULL pointer dereference.

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: Intel: avs: Fix null-ptr-deref in avs_component_probe()

      commit: 95f723cf141b95e3b3a5b92cf2ea98a863fe7275

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark