[PATCH] thunderbolt: Use min() for the DMA path credit cap
From: Fan Ye via B4 Relay
Date: Mon Aug 10 2026 - 05:44:49 EST
From: Fan Ye <fy15309206903@xxxxxxxxx>
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@xxxxxxxxx>
---
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@xxxxxxxxx>