mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] ASoC: amd: acp: SoundWire machine driver fixes
@ 2026-09-10 16:16 Vijendar Mukunda
  2026-09-10 16:16 ` [PATCH 1/4] ASoC: amd: acp: bounds-check SoundWire link ID in machine drivers Vijendar Mukunda
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Vijendar Mukunda @ 2026-09-10 16:16 UTC (permalink / raw)
  To: broonie
  Cc: alsa-devel, lgirdwood, perex, tiwai, yung-chuan.liao,
	Basavaraj.Hiregoudar, Sunil-kumar.Dommati, venkataprasad.potturu,
	Syed.SabaKareem, Mario.Limonciello, Richard.Gong, ckeepax,
	linux-sound, linux-kernel, 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

 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(-)

-- 
2.48.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] ASoC: amd: acp: bounds-check SoundWire link ID in machine drivers
  2026-09-10 16:16 [PATCH 0/4] ASoC: amd: acp: SoundWire machine driver fixes Vijendar Mukunda
@ 2026-09-10 16:16 ` Vijendar Mukunda
  2026-09-10 16:16 ` [PATCH 2/4] ASoC: amd: acp: refactor codec config count in SOF SoundWire machine driver Vijendar Mukunda
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Vijendar Mukunda @ 2026-09-10 16:16 UTC (permalink / raw)
  To: broonie
  Cc: alsa-devel, lgirdwood, perex, tiwai, yung-chuan.liao,
	Basavaraj.Hiregoudar, Sunil-kumar.Dommati, venkataprasad.potturu,
	Syed.SabaKareem, Mario.Limonciello, Richard.Gong, ckeepax,
	linux-sound, linux-kernel, Vijendar Mukunda

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")
Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 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(+)

diff --git a/sound/soc/amd/acp/acp-sdw-legacy-mach.c b/sound/soc/amd/acp/acp-sdw-legacy-mach.c
index 6eac42bac855..2ea226a195c3 100644
--- a/sound/soc/amd/acp/acp-sdw-legacy-mach.c
+++ b/sound/soc/amd/acp/acp-sdw-legacy-mach.c
@@ -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),
diff --git a/sound/soc/amd/acp/acp-sdw-sof-mach.c b/sound/soc/amd/acp/acp-sdw-sof-mach.c
index a9cd1f335167..6c74e67b134f 100644
--- a/sound/soc/amd/acp/acp-sdw-sof-mach.c
+++ b/sound/soc/amd/acp/acp-sdw-sof-mach.c
@@ -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),
-- 
2.48.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/4] ASoC: amd: acp: refactor codec config count in SOF SoundWire machine driver
  2026-09-10 16:16 [PATCH 0/4] ASoC: amd: acp: SoundWire machine driver fixes Vijendar Mukunda
  2026-09-10 16:16 ` [PATCH 1/4] ASoC: amd: acp: bounds-check SoundWire link ID in machine drivers Vijendar Mukunda
@ 2026-09-10 16:16 ` Vijendar Mukunda
  2026-09-10 16:16 ` [PATCH 3/4] ASoC: amd: acp: fix ffs() operator precedence for SoundWire link ID Vijendar Mukunda
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Vijendar Mukunda @ 2026-09-10 16:16 UTC (permalink / raw)
  To: broonie
  Cc: alsa-devel, lgirdwood, perex, tiwai, yung-chuan.liao,
	Basavaraj.Hiregoudar, Sunil-kumar.Dommati, venkataprasad.potturu,
	Syed.SabaKareem, Mario.Limonciello, Richard.Gong, ckeepax,
	linux-sound, linux-kernel, 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")
Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 sound/soc/amd/acp/acp-sdw-sof-mach.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sound/soc/amd/acp/acp-sdw-sof-mach.c b/sound/soc/amd/acp/acp-sdw-sof-mach.c
index 6c74e67b134f..b7926967593f 100644
--- a/sound/soc/amd/acp/acp-sdw-sof-mach.c
+++ b/sound/soc/amd/acp/acp-sdw-sof-mach.c
@@ -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;
-- 
2.48.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/4] ASoC: amd: acp: fix ffs() operator precedence for SoundWire link ID
  2026-09-10 16:16 [PATCH 0/4] ASoC: amd: acp: SoundWire machine driver fixes Vijendar Mukunda
  2026-09-10 16:16 ` [PATCH 1/4] ASoC: amd: acp: bounds-check SoundWire link ID in machine drivers Vijendar Mukunda
  2026-09-10 16:16 ` [PATCH 2/4] ASoC: amd: acp: refactor codec config count in SOF SoundWire machine driver Vijendar Mukunda
@ 2026-09-10 16:16 ` Vijendar Mukunda
  2026-09-10 16:16 ` [PATCH 4/4] ASoC: amd: acp: fix card name length warning in SOF SoundWire machine driver Vijendar Mukunda
  2026-09-10 16:27 ` [PATCH 0/4] ASoC: amd: acp: SoundWire machine driver fixes Mario Limonciello
  4 siblings, 0 replies; 6+ messages in thread
From: Vijendar Mukunda @ 2026-09-10 16:16 UTC (permalink / raw)
  To: broonie
  Cc: alsa-devel, lgirdwood, perex, tiwai, yung-chuan.liao,
	Basavaraj.Hiregoudar, Sunil-kumar.Dommati, venkataprasad.potturu,
	Syed.SabaKareem, Mario.Limonciello, Richard.Gong, ckeepax,
	linux-sound, linux-kernel, 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")
Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 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(-)

diff --git a/sound/soc/amd/acp/acp-sdw-legacy-mach.c b/sound/soc/amd/acp/acp-sdw-legacy-mach.c
index 2ea226a195c3..1a05d4288a46 100644
--- a/sound/soc/amd/acp/acp-sdw-legacy-mach.c
+++ b/sound/soc/amd/acp/acp-sdw-legacy-mach.c
@@ -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;
diff --git a/sound/soc/amd/acp/acp-sdw-sof-mach.c b/sound/soc/amd/acp/acp-sdw-sof-mach.c
index b7926967593f..e6d545fd665e 100644
--- a/sound/soc/amd/acp/acp-sdw-sof-mach.c
+++ b/sound/soc/amd/acp/acp-sdw-sof-mach.c
@@ -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;
-- 
2.48.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 4/4] ASoC: amd: acp: fix card name length warning in SOF SoundWire machine driver
  2026-09-10 16:16 [PATCH 0/4] ASoC: amd: acp: SoundWire machine driver fixes Vijendar Mukunda
                   ` (2 preceding siblings ...)
  2026-09-10 16:16 ` [PATCH 3/4] ASoC: amd: acp: fix ffs() operator precedence for SoundWire link ID Vijendar Mukunda
@ 2026-09-10 16:16 ` Vijendar Mukunda
  2026-09-10 16:27 ` [PATCH 0/4] ASoC: amd: acp: SoundWire machine driver fixes Mario Limonciello
  4 siblings, 0 replies; 6+ messages in thread
From: Vijendar Mukunda @ 2026-09-10 16:16 UTC (permalink / raw)
  To: broonie
  Cc: alsa-devel, lgirdwood, perex, tiwai, yung-chuan.liao,
	Basavaraj.Hiregoudar, Sunil-kumar.Dommati, venkataprasad.potturu,
	Syed.SabaKareem, Mario.Limonciello, Richard.Gong, ckeepax,
	linux-sound, linux-kernel, 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.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 sound/soc/amd/acp/acp-sdw-sof-mach.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/amd/acp/acp-sdw-sof-mach.c b/sound/soc/amd/acp/acp-sdw-sof-mach.c
index e6d545fd665e..ec3e1f5f1052 100644
--- a/sound/soc/amd/acp/acp-sdw-sof-mach.c
+++ b/sound/soc/amd/acp/acp-sdw-sof-mach.c
@@ -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;
 
-- 
2.48.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] ASoC: amd: acp: SoundWire machine driver fixes
  2026-09-10 16:16 [PATCH 0/4] ASoC: amd: acp: SoundWire machine driver fixes Vijendar Mukunda
                   ` (3 preceding siblings ...)
  2026-09-10 16:16 ` [PATCH 4/4] ASoC: amd: acp: fix card name length warning in SOF SoundWire machine driver Vijendar Mukunda
@ 2026-09-10 16:27 ` Mario Limonciello
  4 siblings, 0 replies; 6+ messages in thread
From: Mario Limonciello @ 2026-09-10 16:27 UTC (permalink / raw)
  To: Vijendar Mukunda, broonie
  Cc: alsa-devel, lgirdwood, perex, tiwai, yung-chuan.liao,
	Basavaraj.Hiregoudar, Sunil-kumar.Dommati, venkataprasad.potturu,
	Syed.SabaKareem, Richard.Gong, ckeepax, linux-sound,
	linux-kernel



On 9/10/26 11:16, Vijendar Mukunda wrote:
> 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(-)
> 
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-09-10 16:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-10 16:16 [PATCH 0/4] ASoC: amd: acp: SoundWire machine driver fixes Vijendar Mukunda
2026-09-10 16:16 ` [PATCH 1/4] ASoC: amd: acp: bounds-check SoundWire link ID in machine drivers Vijendar Mukunda
2026-09-10 16:16 ` [PATCH 2/4] ASoC: amd: acp: refactor codec config count in SOF SoundWire machine driver Vijendar Mukunda
2026-09-10 16:16 ` [PATCH 3/4] ASoC: amd: acp: fix ffs() operator precedence for SoundWire link ID Vijendar Mukunda
2026-09-10 16:16 ` [PATCH 4/4] ASoC: amd: acp: fix card name length warning in SOF SoundWire machine driver Vijendar Mukunda
2026-09-10 16:27 ` [PATCH 0/4] ASoC: amd: acp: SoundWire machine driver fixes Mario Limonciello

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®