public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] thunderbolt: Check whether bandwidth request needs asymmetric mode before check whether it can be done
@ 2025-06-28 12:34 zhangjianrong
  2025-06-28 13:50 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: zhangjianrong @ 2025-06-28 12:34 UTC (permalink / raw)
  To: andreas.noever, michael.jamet, mika.westerberg, YehezkelShB,
	linux-usb, linux-kernel
  Cc: guhengsheng, caiyadong, xuetao09, lixinghang1

Current implementation may cause allocation failures in
tb_alloc_dp_bandwidth() in some cases. This will happen
when requesting downstream bandwidth while total upstream
bandwidth usage on the link exceeds TB_ASYM_MIN (36 Gbps).
tb_configure_asym() will return -ENOBUFS while asymmetric
mode isn't necessary.

Fixes: 3e36528c1127 ("thunderbolt: Configure asymmetric link if needed and bandwidth allows")
Signed-off-by: zhangjianrong <zhangjianrong5@huawei.com>
---
v2: update subject and commit message
v1: initial submission

 drivers/thunderbolt/tb.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index a7c6919fbf97..558455d9716b 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -1039,6 +1039,9 @@ static int tb_configure_asym(struct tb *tb, struct tb_port *src_port,
 			break;
 
 		if (downstream) {
+			/* Does consumed + requested exceed the threshold */
+			if (consumed_down + requested_down < asym_threshold)
+				continue;
 			/*
 			 * Downstream so make sure upstream is within the 36G
 			 * (40G - guard band 10%), and the requested is above
@@ -1048,20 +1051,17 @@ static int tb_configure_asym(struct tb *tb, struct tb_port *src_port,
 				ret = -ENOBUFS;
 				break;
 			}
-			/* Does consumed + requested exceed the threshold */
-			if (consumed_down + requested_down < asym_threshold)
-				continue;
 
 			width_up = TB_LINK_WIDTH_ASYM_RX;
 			width_down = TB_LINK_WIDTH_ASYM_TX;
 		} else {
 			/* Upstream, the opposite of above */
+			if (consumed_up + requested_up < asym_threshold)
+				continue;
 			if (consumed_down + requested_down >= TB_ASYM_MIN) {
 				ret = -ENOBUFS;
 				break;
 			}
-			if (consumed_up + requested_up < asym_threshold)
-				continue;
 
 			width_up = TB_LINK_WIDTH_ASYM_TX;
 			width_down = TB_LINK_WIDTH_ASYM_RX;
-- 
2.34.1


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

end of thread, other threads:[~2025-06-28 13:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-28 12:34 [PATCH v2] thunderbolt: Check whether bandwidth request needs asymmetric mode before check whether it can be done zhangjianrong
2025-06-28 13:50 ` Greg KH

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