From: Michal Pecio <michal.pecio@gmail.com>
To: Arthur Gautier <baloo@superbaloo.net>
Cc: linux-usb@vger.kernel.org,
Mathias Nyman <mathias.nyman@linux.intel.com>,
stable@vger.kernel.org
Subject: Re: [PATCH] xhci: fix lost bounce buffers on TDs spanning several ring segments
Date: Tue, 11 Aug 2026 10:58:56 +0200 [thread overview]
Message-ID: <20260811105856.75d5a7dd.michal.pecio@gmail.com> (raw)
In-Reply-To: <20260811104237.4500b578.michal.pecio@gmail.com>
On Tue, 11 Aug 2026 10:42:37 +0200, Michal Pecio wrote:
> The code looks correct, though I would do it differently: store the
> last bounce_seg and run the loop from td->start_seg to td->bounce_seg.
> This avoids adding the 'if' during enqueue, and still works correctly
> if the TD wraps around the whole ring so that end_seg == start_seg.
>
> The driver is never supposed to create such TDs (they break the ring
> expansion procedure) but I prefer more robust code if it costs nothing.
> Bugs happen, or expansion could theoretically become more flexible.
>
> Regards,
> Michal
>
> > + seg = td->bounce_seg;
> > + for (i = 0; i < ring->num_segs; i++) {
> > + if (seg->bounce_len)
> > + xhci_unmap_one_bounce_buffer(xhci, ring, td, seg);
> > + if (seg == td->end_seg)
> > + break;
> > + seg = seg->next;
> > + }
Oops, sorry, Mathias is right, this loop may incorrectly unmap a buffer
belonging to a later TD which starts somewhere in td->end_seg.
I think the alternative procedure I suggested is free of this problem.
- if td has bounce_seg, then it surely spans beyond start_seg, so we
can safely unmap start_seg's bounce buffer
- if start_seg == bounce_seg then this was the last bounce to unmap,
because it's impossible for end_trb to also be a bonuce.
- otherwise, we can continue to blindly unmap until reachng bounce_seg
- after unmapping bounce_seg, there is nothing more left to unmap
Regards,
Michal
next prev parent reply other threads:[~2026-08-11 8:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 3:35 [PATCH] xhci: fix lost bounce buffers on TDs spanning several ring segments Arthur Gautier
2026-08-11 8:42 ` Michal Pecio
2026-08-11 8:58 ` Michal Pecio [this message]
2026-08-12 0:27 ` Arthur Gautier
2026-08-11 8:42 ` Mathias Nyman
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=20260811105856.75d5a7dd.michal.pecio@gmail.com \
--to=michal.pecio@gmail.com \
--cc=baloo@superbaloo.net \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@linux.intel.com \
--cc=stable@vger.kernel.org \
/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