Skip to contentSkip to conversation

thunderbolt: Fix uninitialized variable in tb_tunnel_alloc_usb3()

PATCH In review Gil Fine 2 participants 2 messages Apr 25, 2024 – Apr 27, 2024

Subsystems (2)
lore
Share & tools
lore

Gil Fine

author
#0 lore raw

PATCH 1/1 thunderbolt: Fix uninitialized variable in tb_tunnel_alloc_usb3()

Currently in case of no bandwidth available for USB3 tunnel, we are left with uninitialized variable that can lead to huge negative allocated bandwidth.

Fix this by initializing the variable to zero.
While there, fix the kernel-doc to describe more accurately the purpose of the function tb_tunnel_alloc_usb3().

Fixes 7e227d09f80d ("thunderbolt: Allow USB3 bandwidth to be lower than maximum supported")
---
 drivers/thunderbolt/tunnel.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/thunderbolt/tunnel.c +5 -5
index fdc5e8e12ca8..1a3b197001da 100644
@@ -2048,10 +2048,10 @@ struct tb_tunnel *tb_tunnel_discover_usb3(struct tb *tb, struct tb_port *down,
  * @tb: Pointer to the domain structure
  * @up: USB3 upstream adapter port
  * @down: USB3 downstream adapter port
- * @max_up: Maximum available upstream bandwidth for the USB3 tunnel (%0
- *	    if not limited).
- * @max_down: Maximum available downstream bandwidth for the USB3 tunnel
- *	      (%0 if not limited).
+ * @max_up: Maximum available upstream bandwidth for the USB3 tunnel.
+ *	    %0 if no available bandwidth.
+ * @max_down: Maximum available downstream bandwidth for the USB3 tunnel.
+ *	      %0 if no available bandwidth.
  *
  * Allocate an USB3 tunnel. The ports must be of type @TB_TYPE_USB3_UP and
  * @TB_TYPE_USB3_DOWN.
@@ -2064,7 +2064,7 @@ struct tb_tunnel *tb_tunnel_alloc_usb3(struct tb *tb, struct tb_port *up,
 {
 	struct tb_tunnel *tunnel;
 	struct tb_path *path;
-	int max_rate;
+	int max_rate = 0;
 
 	if (!tb_route(down->sw) && (max_up > 0 || max_down > 0)) {
 		/*
Signature · 1 line
2.25.1
#1 lore raw
Quoted 11 lines · Gil Fine

Currently in case of no bandwidth available for USB3 tunnel, we are left with uninitialized variable that can lead to huge negative allocated bandwidth.

Fix this by initializing the variable to zero.
While there, fix the kernel-doc to describe more accurately the purpose of the function tb_tunnel_alloc_usb3().

Fixes 7e227d09f80d ("thunderbolt: Allow USB3 bandwidth to be lower than maximum supported")

I fixed the commit ID to match the one in my tree and applied to thunderbolt.git/next, thanks!