If we couldn't finish preparing all the TRBs of a request, don't prepare
the next request. Otherwise, the TRBs order will be mixed up and the
controller will process the wrong TRB. This is a corner case where
there's not enough TRBs for a request that needs the extra TRB but
there's still 1 available TRB in the pool.
Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
list_for_each_entry(req, &dep->started_list, list) {
if (req->num_pending_sgs > 0) {
ret = dwc3_prepare_trbs_sg(dep, req);
- if (!ret)
+ if (!ret || req->num_pending_sgs)
return ret;
}
req->num_queued_sgs = 0;
req->num_pending_sgs = req->request.num_mapped_sgs;
- if (req->num_pending_sgs > 0)
+ if (req->num_pending_sgs > 0) {
ret = dwc3_prepare_trbs_sg(dep, req);
- else
+ if (req->num_pending_sgs)
+ return ret;
+ } else {
ret = dwc3_prepare_trbs_linear(dep, req);
+ }
if (!ret || !dwc3_calc_trbs_left(dep))
return ret;