Re: [PATCH] soundwire: qcom: Fix off-by-one error in port exhaustion check

From: Chris Obbard

Date: Thu Nov 26 2026 - 03:56:56 EST


Hey Srini,

Thanks for the review! I got some time to send a v2; it should be in
your inbox soon.

On Mon, 19 Oct 2026 at 09:10, Srinivas Kandagatla
<srinivas.kandagatla@xxxxxxxxxxxxxxxx> wrote:
> On 10/12/26 11:17 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 8 ports. Each amplifier uses one port for playback
> > and another for voltage and current sensing. The right amplifier's
> > VISENSE port is mapped to 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 codec DMA backend then returns -EBUSY, preventing speaker playback.
> > Disabling VISENSE works around the issue but also disables speaker
> > protection.
> This comment is incorrect, we do not have speaker protection enabled on
> any of the devices.

Thanks; I've reworded this in v2. This bug was found while testing
AudioReach userspace on
RB3gen2; Speaker protection isn't (yet!) enabled in upstream, but with
AudioReach userspace PAL mixer
paths enable VISENSE on every speaker stream, so playback fails unless
VISENSE is disabled.

> >
> > 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.
> >
> > Fixes: 6ccec91c3535 ("soundwire: qcom: Fix port exhaustion check in stream_alloc_ports")
> Cc Stable and Reported-by missing

Added Cc Stable. I found the bug when testing the AudioReach stack so
no Reported-by is needed...


> > Signed-off-by: Christopher Obbard <chris.obbard@xxxxxxxxxxxxxxxx>
> > ---
> > 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 6e0c5fb10efad..b4ce96792fa94 100644
> > --- a/drivers/soundwire/qcom.c
> > +++ b/drivers/soundwire/qcom.c
> > @@ -1348,9 +1348,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);
> thanks for adding this case, rb3gen2 should not hit this anyway.

It does with AudioReach userspace, which reads the VISENSE port :-).

> >
> > - if (pn >= maxport) {
> > + if (pn > maxport) {
> > dev_err(ctrl->dev, "All ports busy\n");
> > return -EBUSY;
> > }
> >
>
> Once those are fixed,
>
> Reviewed-by: Srinivas Kandagatla <srinivas.kandagatla@xxxxxxxxxxxxxxxx>

I didn't add your R-b as I would like a review of v2. Hope that's OK.


Cheers!


Chris