mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Srinivas Kandagatla <srini@kernel.org>
To: Christopher Obbard <chris.obbard@oss.qualcomm.com>,
	Srinivas Kandagatla <srini@kernel.org>,
	Vinod Koul <vkoul@kernel.org>,
	Bard Liao <yung-chuan.liao@linux.intel.com>,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>
Cc: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>,
	linux-sound@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v2] soundwire: qcom: Fix off-by-one error in port exhaustion check
Date: Thu, 26 Nov 2026 09:16:53 +0000	[thread overview]
Message-ID: <534f7330-d4de-47a8-ba6b-68c29c138186@kernel.org> (raw)
In-Reply-To: <20261126-wip-obbardc-soundwire-qcom-fix-port-off-by-one-v2-1-c424edf85968@oss.qualcomm.com>



On 11/26/26 8:56 AM, Christopher Obbard wrote:
> Qualcomm SoundWire master ports are indexed from 1, with bit 0 of
> port_mask reserved. Valid port numbers therefore range from 1 to
> maxport.
> 
> Commit 6ccec91c3535 ("soundwire: qcom: Fix port exhaustion check in
> stream_alloc_ports") changed the port exhaustion check from
> pn > maxport to pn >= maxport which rejects the last valid port.
> 
> On RB3gen2 (QCS6490), two WSA883x speaker amplifiers are connected
> to swr2, which has qcom,dout-ports = <6> and qcom,din-ports = <2>
> (8 ports). Each amplifier uses one port for playback and another for
> voltage and current sensing (VISENSE). The right amplifier's
> qcom,port-mapping is <4 5 6 8>, so its VISENSE port is master port 8,
> which is rejected by the new check.
> 
> Since all ports in a SoundWire stream are allocated together during
> hw_params, this causes the stream to fail with:
> 
>     qcom-soundwire 3250000.soundwire: All ports busy
> 
> The -EBUSY propagates through hw_params, preventing speaker playback.
> Disabling VISENSE works around the issue. Speaker protection is not
> enabled on this device in upstream, but with AudioReach userspace the
> userspace PAL mixer paths enable VISENSE on every speaker stream, so a
> mixer change alone does not avoid the failure.
> 
> The original fix addressed an exhaustion check that could never
> trigger because find_first_zero_bit() returns maxport when all
> searched bits are set. Include the reserved bit 0 in the search so
> exhaustion returns maxport + 1 and restore the pn > maxport check.
> 
> Tested on RB3gen2 with a v7.4-rc3 based kernel and AudioReach
> userspace: with the stock PAL mixer paths, which enable VISENSE on
> both amplifiers, speaker playback through the PAL speaker sink is
> audible and no longer fails with "All ports busy".
> 
> Fixes: 6ccec91c3535 ("soundwire: qcom: Fix port exhaustion check in stream_alloc_ports")
> Cc: stable@vger.kernel.org
> Signed-off-by: Christopher Obbard <chris.obbard@oss.qualcomm.com>
lgtm,

Reviewed-by: Srinivas Kandagatla<srinivas.kandagatla@oss.qualcomm.com>

--Srini
> ---
> Changes in v2:
> - Rebase onto soundwire/next.
> - soundwire/next now has commit d9ea256ee889 ("soundwire: qcom: Prevent
>   pconfig buffer overflow in qcom_swrm_stream_alloc_ports()"), which
>   adds an nports >= maxport bound on the pconfig array. That bound is
>   separate from the off-by-one fixed here: it keeps pn >= maxport, so
>   the last valid master port (maxport) is still rejected and RB3gen2
>   speaker playback with VISENSE still fails with "All ports busy". This
>   patch is still needed; keep both checks as
>   pn > maxport || nports >= maxport.
> - Add Cc: stable@vger.kernel.org, as 6ccec91c3535 landed in v7.3 and
>   was backported to stable (Srini).
> - Drop the claim that disabling VISENSE disables speaker protection;
>   speaker protection is not enabled on any upstream device (Srini).
> - Give the concrete swr2 port counts and the right WSA883x
>   qcom,port-mapping from the RB3gen2 DT.
> - Note that the PAL mixer paths enable VISENSE on every speaker
>   stream, so a mixer change alone does not work around the issue.
> - Add a note about testing on RB3gen2.
> - Say the -EBUSY propagates through hw_params rather than naming the
>   codec DMA backend.
> - Link to v1: https://patch.msgid.link/20261012-wip-obbardc-soundwire-qcom-fix-port-off-by-one-v1-1-81f1a4c9c73a@oss.qualcomm.com
> ---
>  drivers/soundwire/qcom.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
> index 65add9a74ffd9..05311cf639e4c 100644
> --- a/drivers/soundwire/qcom.c
> +++ b/drivers/soundwire/qcom.c
> @@ -1461,9 +1461,9 @@ static int qcom_swrm_stream_alloc_ports(struct qcom_swrm_ctrl *ctrl,
>  				if (m_port)
>  					pn = m_port;
>  				else
> -					pn = find_first_zero_bit(port_mask, maxport);
> +					pn = find_first_zero_bit(port_mask, maxport + 1);
>  
> -				if (pn >= maxport || nports >= maxport) {
> +				if (pn > maxport || nports >= maxport) {
>  					dev_err(ctrl->dev, "All ports busy\n");
>  					*port_mask &= ~allocated;
>  					return -EBUSY;
> 
> ---
> base-commit: d9ea256ee889f3db9f0bd07ce5d114ce92e31b4f
> change-id: 20261012-wip-obbardc-soundwire-qcom-fix-port-off-by-one-47c0a8af1c5e
> 
> Best regards,
> --  
> Christopher Obbard
> 


      reply	other threads:[~2026-11-26  9:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  8:56 Christopher Obbard
2026-11-26  9:16 ` Srinivas Kandagatla [this message]

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=534f7330-d4de-47a8-ba6b-68c29c138186@kernel.org \
    --to=srini@kernel.org \
    --cc=chris.obbard@oss.qualcomm.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=pierre-louis.bossart@linux.dev \
    --cc=srinivas.kandagatla@oss.qualcomm.com \
    --cc=stable@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®