Linux USB
 help / color / mirror / Atom feed
* [PATCH] thunderbolt: Use min() for the DMA path credit cap
@ 2026-08-10  9:38 Fan Ye via B4 Relay
  2026-08-10 11:30 ` Mika Westerberg
  0 siblings, 1 reply; 2+ messages in thread
From: Fan Ye via B4 Relay @ 2026-08-10  9:38 UTC (permalink / raw)
  To: Yehezkel Bernat, Mika Westerberg, Andreas Noever
  Cc: linux-usb, linux-kernel, Fan Ye

From: Fan Ye <fy15309206903@gmail.com>

tb_dma_reserve_credits() caps the request against what the adapter has
left by decrementing one credit at a time. The other arm of the same
if() already caps with min(port->total_credits, credits); use min()
here too.

No functional change: the object code is unchanged.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Fan Ye <fy15309206903@gmail.com>
---
Verified by building drivers/thunderbolt/tunnel.o with and without this
patch (gcc 13.3.0, x86_64): objdump output is identical, a single cmovbe
either way.
---
 drivers/thunderbolt/tunnel.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/thunderbolt/tunnel.c b/drivers/thunderbolt/tunnel.c
index b7f32305f14a..e9214de5f3b7 100644
--- a/drivers/thunderbolt/tunnel.c
+++ b/drivers/thunderbolt/tunnel.c
@@ -1778,8 +1778,7 @@ static int tb_dma_reserve_credits(struct tb_path_hop *hop, unsigned int credits)
 		if (available < TB_MIN_DMA_CREDITS)
 			return -ENOSPC;
 
-		while (credits > available)
-			credits--;
+		credits = min(credits, available);
 
 		tb_port_dbg(port, "reserving %u credits for DMA path\n",
 			    credits);

---
base-commit: db2ddb87143519e20a95aa36c60b36107b736a58
change-id: 20260810-tb-dma-credit-min-78b89d149bd7

Best regards,
--  
Fan Ye <fy15309206903@gmail.com>



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] thunderbolt: Use min() for the DMA path credit cap
  2026-08-10  9:38 [PATCH] thunderbolt: Use min() for the DMA path credit cap Fan Ye via B4 Relay
@ 2026-08-10 11:30 ` Mika Westerberg
  0 siblings, 0 replies; 2+ messages in thread
From: Mika Westerberg @ 2026-08-10 11:30 UTC (permalink / raw)
  To: fy15309206903
  Cc: Yehezkel Bernat, Mika Westerberg, Andreas Noever, linux-usb,
	linux-kernel

Hi,

On Mon, Aug 10, 2026 at 09:38:43AM +0000, Fan Ye via B4 Relay wrote:
> From: Fan Ye <fy15309206903@gmail.com>
> 
> tb_dma_reserve_credits() caps the request against what the adapter has
> left by decrementing one credit at a time. The other arm of the same
> if() already caps with min(port->total_credits, credits); use min()
> here too.
> 
> No functional change: the object code is unchanged.
> 
> Assisted-by: Claude:claude-opus-5
> Signed-off-by: Fan Ye <fy15309206903@gmail.com>

Applied to thunderbolt.git/next, thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-10 11:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-10  9:38 [PATCH] thunderbolt: Use min() for the DMA path credit cap Fan Ye via B4 Relay
2026-08-10 11:30 ` Mika Westerberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox