[PATCH v2] ALSA: hda: intel: Validate master count before creating link mask

From: Sreeraj S Kurup

Date: Sat Dec 05 2026 - 10:19:25 EST


The driver uses GENMASK(count - 1, 0) to create the link
mask from the mipi-sdw-master-count ACPI property.

However, the link mask is created before validating the
master count. If firmware reports a count of zero, the
unsigned subtraction count - 1 underflows. If the count
exceeds SDW_INTEL_MAX_LINKS, an invalid link mask may
be generated.

Move link mask creation after the existing count checks
to ensure the count is valid before calling GENMASK().

Fixes: 71dce222d586 ("ALSA/hda: intel-sdw-acpi: add support for sdw-manager-list property read")
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@xxxxxxxxx>
---
v2:
- Move GENMASK() after the existing master count validation.
- Avoid duplicate count checks and preserve existing error
handling.
- Add Fixes trailer.

sound/hda/core/intel-sdw-acpi.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/sound/hda/core/intel-sdw-acpi.c b/sound/hda/core/intel-sdw-acpi.c
index d3511135f7d3..c38e956d4643 100644
--- a/sound/hda/core/intel-sdw-acpi.c
+++ b/sound/hda/core/intel-sdw-acpi.c
@@ -62,6 +62,7 @@ sdw_intel_scan_controller(struct sdw_intel_acpi_info *info)
u32 count;
u32 tmp;
int ret;
+ bool use_master_count = false;

if (!adev)
return -EINVAL;
@@ -90,7 +91,8 @@ sdw_intel_scan_controller(struct sdw_intel_acpi_info *info)
ret);
return ret;
}
- list = GENMASK(count - 1, 0);
+ use_master_count = true;
+
} else {
list = tmp;
count = hweight32(list);
@@ -98,7 +100,7 @@ sdw_intel_scan_controller(struct sdw_intel_acpi_info *info)

/* Check count is within bounds */
if (count > SDW_INTEL_MAX_LINKS) {
- dev_err(&adev->dev, "Link count %d exceeds max %d\n",
+ dev_err(&adev->dev, "Link count %u exceeds max %d\n",
count, SDW_INTEL_MAX_LINKS);
return -EINVAL;
}
@@ -107,7 +109,11 @@ sdw_intel_scan_controller(struct sdw_intel_acpi_info *info)
dev_warn(&adev->dev, "No SoundWire links detected\n");
return -EINVAL;
}
- dev_dbg(&adev->dev, "ACPI reports %d SDW Link devices\n", count);
+
+ if (use_master_count)
+ list = GENMASK(count - 1, 0);
+
+ dev_dbg(&adev->dev, "ACPI reports %u SDW Link devices\n", count);

info->count = count;
info->link_mask = 0;
--
2.55.0