mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
To: sreekuttan2156239@gmail.com, perex@perex.cz, tiwai@suse.de
Cc: linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org
Subject: [PATCH v2] ALSA: hda: intel: Validate master count before creating link mask
Date: Sat,  5 Dec 2026 15:18:40 +0000	[thread overview]
Message-ID: <20261205151840.2821-1-sreekuttan2156239@gmail.com> (raw)
In-Reply-To: <20261205143113.2888-1-sreekuttan2156239@gmail.com>

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@gmail.com>
---
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


  reply	other threads:[~2026-12-05 15:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 14:31 [PATCH] " Sreeraj S Kurup
2026-12-05 15:18 ` Sreeraj S Kurup [this message]
2026-12-06 11:09   ` [PATCH v2] " Takashi Iwai
2026-12-06 13:06     ` Sreeraj S Kurup

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261205151840.2821-1-sreekuttan2156239@gmail.com \
    --to=sreekuttan2156239@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®