linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thunderbolt: Fix uninitialized variable in tb_tunnel_alloc_usb3()
@ 2024-04-25 23:24 Gil Fine
  2024-04-27  5:07 ` Mika Westerberg
  0 siblings, 1 reply; 2+ messages in thread
From: Gil Fine @ 2024-04-25 23:24 UTC (permalink / raw)
  To: andreas.noever, michael.jamet, mika.westerberg, YehezkelShB
  Cc: gil.fine, linux-usb, lukas, Gil Fine, Dan Carpenter

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().

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/linux-usb/6289898b-cd63-4fb8-906a-1b6977321af9@moroto.mountain/
Fixes: 7e227d09f80d ("thunderbolt: Allow USB3 bandwidth to be lower than maximum supported")
Signed-off-by: Gil Fine <gil.fine@linux.intel.com>
---
 drivers/thunderbolt/tunnel.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/thunderbolt/tunnel.c b/drivers/thunderbolt/tunnel.c
index fdc5e8e12ca8..1a3b197001da 100644
--- a/drivers/thunderbolt/tunnel.c
+++ b/drivers/thunderbolt/tunnel.c
@@ -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)) {
 		/*
-- 
2.25.1


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

* Re: [PATCH] thunderbolt: Fix uninitialized variable in tb_tunnel_alloc_usb3()
  2024-04-25 23:24 [PATCH] thunderbolt: Fix uninitialized variable in tb_tunnel_alloc_usb3() Gil Fine
@ 2024-04-27  5:07 ` Mika Westerberg
  0 siblings, 0 replies; 2+ messages in thread
From: Mika Westerberg @ 2024-04-27  5:07 UTC (permalink / raw)
  To: Gil Fine
  Cc: andreas.noever, michael.jamet, YehezkelShB, gil.fine, linux-usb,
	lukas, Dan Carpenter

On Fri, Apr 26, 2024 at 02:24:17AM +0300, Gil Fine wrote:
> 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().
> 
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/linux-usb/6289898b-cd63-4fb8-906a-1b6977321af9@moroto.mountain/
> Fixes: 7e227d09f80d ("thunderbolt: Allow USB3 bandwidth to be lower than maximum supported")
> Signed-off-by: Gil Fine <gil.fine@linux.intel.com>

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

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

end of thread, other threads:[~2024-04-27  5:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-25 23:24 [PATCH] thunderbolt: Fix uninitialized variable in tb_tunnel_alloc_usb3() Gil Fine
2024-04-27  5:07 ` Mika Westerberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).