U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: bigunclemax@gmail.com
Cc: bigunclemax@gmail.com, Bin Meng <bmeng.cn@gmail.com>,
	Marek Vasut <marex@denx.de>, Tom Rini <trini@konsulko.com>,
	Neal Gompa <neal@gompa.dev>, Janne Grunau <j@jannau.net>,
	Hector Martin <marcan@marcan.st>,
	Godfrey Mwangi <godmwan@microsoft.com>,
	u-boot@lists.denx.de
Subject: [PATCH v1 1/1] usb: xhci: fix calculation of act_len in case of using multipe TRB
Date: Fri, 21 Mar 2025 19:58:50 +0300	[thread overview]
Message-ID: <20250321165853.742837-2-bigunclemax@gmail.com> (raw)
In-Reply-To: <20250321165853.742837-1-bigunclemax@gmail.com>

From: Maksim Kiselev <bigunclemax@gmail.com>

In the case when the transfer buffer spans 64KB boundary, one trb is
divided into several. In this case, the size of the first trb buffer
sets equal to the size of truncated to 64K boundary.

However, this is not taken into account when calculating the actual
length.

To fix this need to subtract the trimmed size of first TRB buff
from the available_length.

Signed-off-by: Maksim Kiselev <bigunclemax@gmail.com>
---
 drivers/usb/host/xhci-ring.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 34eb4536f0e..89d2e54f20a 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -659,6 +659,7 @@ int xhci_bulk_tx(struct usb_device *udev, unsigned long pipe,
 	u64 buf_64 = xhci_dma_map(ctrl, buffer, length);
 	dma_addr_t last_transfer_trb_addr;
 	int available_length;
+	int first_trb_trimmed_sz = 0;
 
 	debug("dev=%p, pipe=%lx, buffer=%p, length=%d\n",
 		udev, pipe, buffer, length);
@@ -740,6 +741,8 @@ int xhci_bulk_tx(struct usb_device *udev, unsigned long pipe,
 
 	if (trb_buff_len > length)
 		trb_buff_len = length;
+	else
+		first_trb_trimmed_sz = length - trb_buff_len;
 
 	first_trb = true;
 
@@ -825,6 +828,8 @@ again:
 	BUG_ON(TRB_TO_SLOT_ID(field) != slot_id);
 	BUG_ON(TRB_TO_EP_INDEX(field) != ep_index);
 
+	available_length -= first_trb_trimmed_sz;
+
 	record_transfer_result(udev, event, available_length);
 	xhci_acknowledge_event(ctrl);
 	xhci_inval_cache((uintptr_t)buffer, length);
-- 
2.45.2


  reply	other threads:[~2025-03-21 16:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-21 16:58 [PATCH v1 0/1] USB xHCI wrong act_len calculation in case of using multipe TRB bigunclemax
2025-03-21 16:58 ` bigunclemax [this message]
2025-04-07 17:41 ` marcan

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=20250321165853.742837-2-bigunclemax@gmail.com \
    --to=bigunclemax@gmail.com \
    --cc=bmeng.cn@gmail.com \
    --cc=godmwan@microsoft.com \
    --cc=j@jannau.net \
    --cc=marcan@marcan.st \
    --cc=marex@denx.de \
    --cc=neal@gompa.dev \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /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