From: Eric Wu <kunjinkao.jp@gmail.com>
To: vkoul@kernel.org
Cc: pierre-louis.bossart@linux.dev, yung-chuan.liao@linux.intel.com,
ckeepax@opensource.cirrus.com, linux-sound@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2] soundwire: stream: validate slave port properties
Date: Fri, 31 Jul 2026 20:34:15 +0800 [thread overview]
Message-ID: <20260731123415.34070-1-kunjinkao.jp@gmail.com> (raw)
sdw_slave_port_config() validates that a port number is within the
generic valid range, but does not verify that the Slave exposes the
port for the requested stream direction. As a result, an in-range but
unsupported port, or a valid port used in the wrong direction, can be
accepted.
Use sdw_get_slave_dpn_prop() to perform the direction-specific lookup
and reject unsupported ports before storing the runtime configuration.
Signed-off-by: Eric Wu <kunjinkao.jp@gmail.com>
Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
---
Changes in v2:
- Explain why the generic range check is insufficient.
- Perform a direction-specific DPN lookup and reject a missing entry.
- Drop the fallback that skipped validation when both port bitmaps were
zero.
Testing:
- Locally compile-tested with GCC 9.4 using allmodconfig, W=1 and
-Werror for x86_64, i386, arm64, arm and riscv64.
- SOF CI was temporarily unavailable. Bard Liao manually tested the
patch on SoundWire hardware.
The same revision was reviewed and merged into the SOF topic/sof-dev
branch as commit 54c1da4:
https://github.com/thesofproject/linux/pull/5849#issuecomment-5141207403
drivers/soundwire/stream.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
index cbf7bd3d4e7b..e85025a5aea0 100644
--- a/drivers/soundwire/stream.c
+++ b/drivers/soundwire/stream.c
@@ -1069,14 +1069,23 @@ static int sdw_slave_port_config(struct sdw_slave *slave,
i = 0;
list_for_each_entry(p_rt, &s_rt->port_list, port_node) {
- /*
- * TODO: Check valid port range as defined by DisCo/
- * slave
- */
if (!is_bpt_stream) {
ret = sdw_slave_port_is_valid_range(&slave->dev, port_config[i].num);
if (ret < 0)
return ret;
+
+ /*
+ * A port in the generic valid range may still be unsupported by
+ * the Slave or unavailable for the requested stream direction.
+ */
+ if (!sdw_get_slave_dpn_prop(slave, s_rt->direction,
+ port_config[i].num)) {
+ dev_err(&slave->dev,
+ "port %u not supported for %s\n",
+ port_config[i].num,
+ s_rt->direction == SDW_DATA_DIR_TX ? "TX" : "RX");
+ return -EINVAL;
+ }
} else if (port_config[i].num) {
return -EINVAL;
}
--
2.48.0
next reply other threads:[~2026-07-31 12:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 12:34 Eric Wu [this message]
2026-08-06 8:39 ` [PATCH v2] soundwire: stream: validate slave port properties Vinod Koul
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=20260731123415.34070-1-kunjinkao.jp@gmail.com \
--to=kunjinkao.jp@gmail.com \
--cc=ckeepax@opensource.cirrus.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=pierre-louis.bossart@linux.dev \
--cc=vkoul@kernel.org \
--cc=yung-chuan.liao@linux.intel.com \
/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