From: Eric Wu <kunjinkao.jp@gmail.com>
To: Vinod Koul <vkoul@kernel.org>,
Bard Liao <yung-chuan.liao@linux.intel.com>
Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
Eric Wu <kunjinkao.jp@gmail.com>
Subject: [PATCH] soundwire: stream: validate slave port against DisCo port bitmap
Date: Mon, 13 Jul 2026 15:15:44 +0800 [thread overview]
Message-ID: <20260713071544.35722-1-kunjinkao.jp@gmail.com> (raw)
sdw_slave_port_config() checks that the port number falls in the
generic valid range, but never checks whether the Slave actually
exposes that port for the requested direction. An in-range but
unsupported port number (or the right port with the wrong direction)
gets accepted without complaint.
sdw_get_slave_dpn_prop() already does this lookup against the
source_ports/sink_ports bitmaps for other purposes, so reuse it here
instead of open-coding a new check.
Slaves that don't report source_ports/sink_ports at all (both zero)
are left unchecked, since that's treated elsewhere in the driver as
"property not provided" rather than "no ports supported".
Signed-off-by: Eric Wu <kunjinkao.jp@gmail.com>
---
Only compile-tested: x86_64 gcc, arm64 and arm32 clang (LLVM=1),
all clean with W=1. I do not have SoundWire hardware to test with.
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 4ed8fb7663ad..30cb8a8552d8 100644
--- a/drivers/soundwire/stream.c
+++ b/drivers/soundwire/stream.c
@@ -1054,14 +1054,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;
+
+ /*
+ * source_ports/sink_ports are optional DisCo properties:
+ * both zero means "not provided" rather than "no ports",
+ * so only enforce the check when the Slave reports them.
+ */
+ if ((slave->prop.source_ports || slave->prop.sink_ports) &&
+ !sdw_get_slave_dpn_prop(slave, s_rt->direction, port_config[i].num)) {
+ dev_err(&slave->dev, "port %d 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.25.1
next reply other threads:[~2026-07-13 7:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-13 7:15 Eric Wu [this message]
2026-07-13 8:01 ` Pierre-Louis Bossart
2026-07-14 8:35 ` Eric Wu
2026-07-14 8:44 ` chang wu
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=20260713071544.35722-1-kunjinkao.jp@gmail.com \
--to=kunjinkao.jp@gmail.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
Powered by JetHome