Re: [PATCH 3/4] usb: gadget: dummy_hcd: fix SG transfer handling across chunks
Alan Stern <[email protected]>
| Newsgroups | org.kernel.vger.linux-usb,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Aug 07, 2026 at 09:54:37AM +0200, Igor Skalkin wrote:
> dummy_perform_transfer() may be called multiple times for the same URB
> as the transfer is progressed in chunks. The previous sg_miter-based
> implementation kept iterator state in struct urbp between calls; on
> resumed chunks sg_miter_next() would advance past the already-consumed
> segment, causing -EINVAL and broken transfers.
That definitely is a bug.
> Replace the stateful iterator with sg_miter_skip() to seek to the
> correct SG position (urb->actual_length bytes in) on every call,
> followed by a fresh manual walk for the requested chunk length. This
> makes each call self-contained and correct regardless of how many
> partial transfers have already occurred.
Doesn't it make more sense to use sg_miter_skip() after each time part
of the mapping is consumed, so that the next iteration will start off
exactly where it needs to be? That way you avoid the work, on each
iteration, of going back to the beginning and accounting for the
portion already used.
Alan Stern
> Return -EINVAL if the total copied length does not match the requested
> length (e.g. SG list exhausted prematurely).
>
> Fixes: 14fce33a960a ("usb: gadget: dummy_hcd: add sg support")
> Assisted-by: OpenCode:claude-sonnet-5
> Signed-off-by: Igor Skalkin <[email protected]>
> ---