Skip to contentSkip to conversation

ASoC: amd: acp: SoundWire machine driver fixes

PATCH In review Vijendar Mukunda 3 participants 8 messages Sep 10 – Sep 17

Subsystems (3)
lore
Share & tools
lore

Vijendar Mukunda

author maintainer
#0 lore raw

cover ASoC: amd: acp: SoundWire machine driver fixes

This series fixes four defects in the AMD ACP SoundWire machine drivers (acp-sdw-legacy-mach.c and acp-sdw-sof-mach.c).

A bounds check is added to validate the SoundWire link ID before it is used as an array index in create_sdw_dailink(), preventing out-of-bounds access when an unexpected link_mask value is encountered. The codec config count in the SOF machine driver is refactored to use a dedicated variable rather than reusing the endpoint-count variable for two purposes, making the intent clearer and avoiding a stale value being passed to the codec config array. An operator-precedence bug in the ffs(link_mask - 1) expression is corrected to ffs(link_mask) - 1, ensuring the link ID is derived from the correct bit position. Finally, the SOF machine driver card name is shortened to fit within the 16-byte snd_card driver[] field and eliminate a compile-time warning.

Vijendar Mukunda (4):
ASoC: amd: acp: bounds-check SoundWire link ID in machine drivers
ASoC: amd: acp: refactor codec config count in SOF SoundWire machine
driver
ASoC: amd: acp: fix ffs() operator precedence for SoundWire link ID
ASoC: amd: acp: fix card name length warning in SOF SoundWire machine
driver

 sound/soc/amd/acp/acp-sdw-legacy-mach.c | 14 ++++++++++++--
 sound/soc/amd/acp/acp-sdw-sof-mach.c    | 23 +++++++++++++++++------
 2 files changed, 29 insertions(+), 8 deletions(-)
Signature · 1 line
2.48.1
author maintainer Applied
#1 lore raw

PATCH 1/4 ASoC: amd: acp: bounds-check SoundWire link ID in machine drivers

Add a bounds check in create_sdw_dailink() to validate that the SoundWire link ID derived from link_mask does not exceed the maximum supported by the platform. If the link ID is out of range or link_mask is zero, log an error and return -EINVAL to prevent accessing invalid CPU pin ID tables.

Applied to both acp-sdw-sof-mach.c and acp-sdw-legacy-mach.c.

Fixes 6d8348ddc56e ("ASoC: amd: acp: refactor SoundWire machine driver code")
---
 sound/soc/amd/acp/acp-sdw-legacy-mach.c | 10 ++++++++++
 sound/soc/amd/acp/acp-sdw-sof-mach.c    |  9 +++++++++
 2 files changed, 19 insertions(+)
sound/soc/amd/acp/acp-sdw-legacy-mach.c +10 -0
index 6eac42bac855..2ea226a195c3 100644
@@ -205,6 +205,16 @@ static int create_sdw_dailink(struct snd_soc_card *card,
 			return -EINVAL;
 		}
 
+		if (!soc_end->link_mask) {
+			dev_err(dev, "invalid zero link_mask\n");
+			return -EINVAL;
+		}
+		if ((ffs(soc_end->link_mask) - 1) >= amd_ctx->max_sdw_links) {
+			dev_err(dev, "link_id %d exceeds max_sdw_links %d\n",
+				ffs(soc_end->link_mask) - 1, amd_ctx->max_sdw_links);
+			return -EINVAL;
+		}
+
 		switch (amd_ctx->acp_rev) {
 		case ACP63_PCI_REV:
 			ret = get_acp63_cpu_pin_id(ffs(soc_end->link_mask - 1),
sound/soc/amd/acp/acp-sdw-sof-mach.c +9 -0
index a9cd1f335167..6c74e67b134f 100644
@@ -121,6 +121,15 @@ static int create_sdw_dailink(struct snd_soc_card *card,
 			return -EINVAL;
 		}
 
+		if (!sof_end->link_mask) {
+			dev_err(dev, "invalid zero link_mask\n");
+			return -EINVAL;
+		}
+		if ((ffs(sof_end->link_mask) - 1) >= amd_ctx->max_sdw_links) {
+			dev_err(dev, "link_id %d exceeds max_sdw_links %d\n",
+				ffs(sof_end->link_mask) - 1, amd_ctx->max_sdw_links);
+			return -EINVAL;
+		}
 		switch (amd_ctx->acp_rev) {
 		case ACP63_PCI_REV:
 			ret = get_acp63_cpu_pin_id(ffs(sof_end->link_mask - 1),
Signature · 1 line
2.48.1
author maintainer
#2 lore raw

PATCH 2/4 ASoC: amd: acp: refactor codec config count in SOF SoundWire machine driver

In reply to Vijendar Mukunda

num_devs was used both as the endpoint count and as the output for asoc_sdw_parse_sdw_endpoints(), which overwrites it with the codec configuration count. Introduce a separate num_confs variable to hold the codec conf count so the two values remain distinct across codec_conf allocation and card->num_configs assignment.

Fixes 6d8348ddc56e ("ASoC: amd: acp: refactor SoundWire machine driver code")
---
 sound/soc/amd/acp/acp-sdw-sof-mach.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
sound/soc/amd/acp/acp-sdw-sof-mach.c +5 -3
index 6c74e67b134f..b7926967593f 100644
@@ -286,6 +286,7 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
 	int num_devs = 0;
 	int num_ends = 0;
 	int num_aux = 0;
+	int num_confs;
 	int num_links;
 	int be_id = 0;
 	int ret;
@@ -296,6 +297,7 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
 		return ret;
 	}
 
+	num_confs = num_ends;
 	/* One per DAI link, worst case is a DAI link for every endpoint */
 	struct asoc_sdw_dailink *sof_dais __free(kfree) =
 		kzalloc_objs(*sof_dais, num_ends);
@@ -312,7 +314,7 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
 	if (!sof_aux)
 		return -ENOMEM;
 
-	ret = asoc_sdw_parse_sdw_endpoints(dev, ctx, sof_aux, sof_dais, sof_ends, &num_devs);
+	ret = asoc_sdw_parse_sdw_endpoints(dev, ctx, sof_aux, sof_dais, sof_ends, &num_confs);
 	if (ret < 0)
 		return ret;
 
@@ -324,7 +326,7 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
 
 	dev_dbg(dev, "sdw %d, dmic %d", sdw_be_num, dmic_num);
 
-	codec_conf = devm_kcalloc(dev, num_devs, sizeof(*codec_conf), GFP_KERNEL);
+	codec_conf = devm_kcalloc(dev, num_confs, sizeof(*codec_conf), GFP_KERNEL);
 	if (!codec_conf)
 		return -ENOMEM;
 
@@ -335,7 +337,7 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
 		return -ENOMEM;
 
 	card->codec_conf = codec_conf;
-	card->num_configs = num_devs;
+	card->num_configs = num_confs;
 	card->dai_link = dai_links;
 	card->num_links = num_links;
 	card->aux_dev = sof_aux;
Signature · 1 line
2.48.1
author maintainer
#3 lore raw

PATCH 3/4 ASoC: amd: acp: fix ffs() operator precedence for SoundWire link ID

In reply to Vijendar Mukunda

ffs(link_mask - 1) computes ffs on (link_mask - 1) instead of subtracting 1 from the result of ffs(link_mask). For a typical power-of-2 link_mask this returns the wrong link ID, causing cpu_pin_id lookup to select the incorrect SoundWire manager.

Fix the operator precedence to ffs(link_mask) - 1 in both acp-sdw-sof-mach.c and acp-sdw-legacy-mach.c.

Fixes 6d8348ddc56e ("ASoC: amd: acp: refactor SoundWire machine driver code")
---
 sound/soc/amd/acp/acp-sdw-legacy-mach.c | 4 ++--
 sound/soc/amd/acp/acp-sdw-sof-mach.c    | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
sound/soc/amd/acp/acp-sdw-legacy-mach.c +2 -2
index 2ea226a195c3..1a05d4288a46 100644
@@ -217,7 +217,7 @@ static int create_sdw_dailink(struct snd_soc_card *card,
 
 		switch (amd_ctx->acp_rev) {
 		case ACP63_PCI_REV:
-			ret = get_acp63_cpu_pin_id(ffs(soc_end->link_mask - 1),
+			ret = get_acp63_cpu_pin_id(ffs(soc_end->link_mask) - 1,
 						   *be_id, &cpu_pin_id, dev);
 			if (ret)
 				return ret;
@@ -225,7 +225,7 @@ static int create_sdw_dailink(struct snd_soc_card *card,
 		case ACP70_PCI_REV:
 		case ACP71_PCI_REV:
 		case ACP72_PCI_REV:
-			ret = get_acp70_cpu_pin_id(ffs(soc_end->link_mask - 1),
+			ret = get_acp70_cpu_pin_id(ffs(soc_end->link_mask) - 1,
 						   *be_id, &cpu_pin_id, dev);
 			if (ret)
 				return ret;
sound/soc/amd/acp/acp-sdw-sof-mach.c +2 -2
index b7926967593f..e6d545fd665e 100644
@@ -132,7 +132,7 @@ static int create_sdw_dailink(struct snd_soc_card *card,
 		}
 		switch (amd_ctx->acp_rev) {
 		case ACP63_PCI_REV:
-			ret = get_acp63_cpu_pin_id(ffs(sof_end->link_mask - 1),
+			ret = get_acp63_cpu_pin_id(ffs(sof_end->link_mask) - 1,
 						   *be_id, &cpu_pin_id, dev);
 			if (ret)
 				return ret;
@@ -140,7 +140,7 @@ static int create_sdw_dailink(struct snd_soc_card *card,
 		case ACP70_PCI_REV:
 		case ACP71_PCI_REV:
 		case ACP72_PCI_REV:
-			ret = get_acp70_cpu_pin_id(ffs(sof_end->link_mask - 1),
+			ret = get_acp70_cpu_pin_id(ffs(sof_end->link_mask) - 1,
 						   *be_id, &cpu_pin_id, dev);
 			if (ret)
 				return ret;
Signature · 1 line
2.48.1
author maintainer
#4 lore raw

PATCH 4/4 ASoC: amd: acp: fix card name length warning in SOF SoundWire machine driver

In reply to Vijendar Mukunda

The ALSA snd_card driver[] field is 16 bytes (including the NUL terminator), leaving 15 usable characters. The SOF framework prepends a "sof-" prefix when registering the card, so card->name = "amd-soundwire" becomes driver name "sof-amd-soundwire" which is 17 characters and overflows the driver[16] buffer, triggering a kernel warning.

Fix by shortening the card name to "amd-sdw"; the resulting driver name "sof-amd-sdw" fits within the 15-character limit.

---
 sound/soc/amd/acp/acp-sdw-sof-mach.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/amd/acp/acp-sdw-sof-mach.c +1 -1
index e6d545fd665e..ec3e1f5f1052 100644
@@ -390,7 +390,7 @@ static int mc_probe(struct platform_device *pdev)
 	ctx->private = amd_ctx;
 	card = &ctx->card;
 	card->dev = &pdev->dev;
-	card->name = "amd-soundwire";
+	card->name = "amd-sdw";
 	card->owner = THIS_MODULE;
 	card->late_probe = asoc_sdw_card_late_probe;
 
Signature · 1 line
2.48.1
Reviewed-by on the v1 series
#5 lore raw
In reply to Vijendar Mukunda
Quoted 23 lines · Vijendar Mukunda

This series fixes four defects in the AMD ACP SoundWire machine drivers (acp-sdw-legacy-mach.c and acp-sdw-sof-mach.c).

A bounds check is added to validate the SoundWire link ID before it is used as an array index in create_sdw_dailink(), preventing out-of-bounds access when an unexpected link_mask value is encountered. The codec config count in the SOF machine driver is refactored to use a dedicated variable rather than reusing the endpoint-count variable for two purposes, making the intent clearer and avoiding a stale value being passed to the codec config array. An operator-precedence bug in the ffs(link_mask - 1) expression is corrected to ffs(link_mask) - 1, ensuring the link ID is derived from the correct bit position. Finally, the SOF machine driver card name is shortened to fit within the 16-byte snd_card driver[] field and eliminate a compile-time warning.

Vijendar Mukunda (4):
ASoC: amd: acp: bounds-check SoundWire link ID in machine drivers
ASoC: amd: acp: refactor codec config count in SOF SoundWire machine
driver
ASoC: amd: acp: fix ffs() operator precedence for SoundWire link ID
ASoC: amd: acp: fix card name length warning in SOF SoundWire machine
driver

Quoted 4 lines
  sound/soc/amd/acp/acp-sdw-legacy-mach.c | 14 ++++++++++++--
  sound/soc/amd/acp/acp-sdw-sof-mach.c    | 23 +++++++++++++++++------
  2 files changed, 29 insertions(+), 8 deletions(-)
maintainer
#6 lore raw
In reply to Vijendar Mukunda
Quoted 17 lines · Vijendar Mukunda

ASoC: amd: acp: SoundWire machine driver fixes

This series fixes four defects in the AMD ACP SoundWire machine drivers (acp-sdw-legacy-mach.c and acp-sdw-sof-mach.c).

A bounds check is added to validate the SoundWire link ID before it is used as an array index in create_sdw_dailink(), preventing out-of-bounds access when an unexpected link_mask value is encountered. The codec config count in the SOF machine driver is refactored to use a dedicated variable rather than reusing the endpoint-count variable for two purposes, making the intent clearer and avoiding a stale value being passed to the codec config array. An operator-precedence bug in the ffs(link_mask - 1) expression is corrected to ffs(link_mask) - 1, ensuring the link ID is derived from the correct bit position. Finally, the SOF machine driver card name is shortened to fit within the 16-byte snd_card driver[] field and eliminate a compile-time warning.

Quoted 1 line

[...]

Applied to

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

Thanks!

[1/4] ASoC: amd: acp: bounds-check SoundWire link ID in machine drivers

      https://git.kernel.org/broonie/sound/c/2faa0ae56fa5
[2/4] ASoC: amd: acp: refactor codec config count in SOF SoundWire machine driver
      https://git.kernel.org/broonie/sound/c/efd76c8d6153
[3/4] ASoC: amd: acp: fix ffs() operator precedence for SoundWire link ID
      https://git.kernel.org/broonie/sound/c/5b28d773ed3a
[4/4] ASoC: amd: acp: fix card name length warning in SOF SoundWire machine driver
      https://git.kernel.org/broonie/sound/c/2444f73fe476

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

maintainer
#7 lore raw
In reply to Vijendar Mukunda
Quoted 17 lines · Vijendar Mukunda

ASoC: amd: acp: SoundWire machine driver fixes

This series fixes four defects in the AMD ACP SoundWire machine drivers (acp-sdw-legacy-mach.c and acp-sdw-sof-mach.c).

A bounds check is added to validate the SoundWire link ID before it is used as an array index in create_sdw_dailink(), preventing out-of-bounds access when an unexpected link_mask value is encountered. The codec config count in the SOF machine driver is refactored to use a dedicated variable rather than reusing the endpoint-count variable for two purposes, making the intent clearer and avoiding a stale value being passed to the codec config array. An operator-precedence bug in the ffs(link_mask - 1) expression is corrected to ffs(link_mask) - 1, ensuring the link ID is derived from the correct bit position. Finally, the SOF machine driver card name is shortened to fit within the 16-byte snd_card driver[] field and eliminate a compile-time warning.

Quoted 1 line

[...]

Applied to

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

Thanks!

[1/4] ASoC: amd: acp: bounds-check SoundWire link ID in machine drivers

      https://git.kernel.org/broonie/sound/c/29218a4d11a3
[2/4] ASoC: amd: acp: refactor codec config count in SOF SoundWire machine driver
      https://git.kernel.org/broonie/sound/c/0b7d55d3a912
[3/4] ASoC: amd: acp: fix ffs() operator precedence for SoundWire link ID
      https://git.kernel.org/broonie/sound/c/27098aaf28b9
[4/4] ASoC: amd: acp: fix card name length warning in SOF SoundWire machine driver
      https://git.kernel.org/broonie/sound/c/d57616f8be56

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