Blob Blame History Raw
From 93bf344f66995ef816bd63c165fa9ac1ea4fcb3d Mon Sep 17 00:00:00 2001
From: Gil Fine <gil.fine@intel.com>
Date: Mon, 9 May 2022 23:49:03 +0300
Subject: [PATCH] thunderbolt: Fix buffer allocation of devices with no
 DisplayPort adapters
Git-commit: 93bf344f66995ef816bd63c165fa9ac1ea4fcb3d
References: git-fixes
Patch-mainline: v5.19-rc1

For the case of a device without DisplayPort adapters we calculate
incorrectly the amount of buffers. Fix the calculation for this case.

Signed-off-by: Gil Fine <gil.fine@intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
 drivers/thunderbolt/tunnel.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/thunderbolt/tunnel.c b/drivers/thunderbolt/tunnel.c
index 8ccd70920b6a..2c3cf7fc3357 100644
--- a/drivers/thunderbolt/tunnel.c
+++ b/drivers/thunderbolt/tunnel.c
@@ -102,8 +102,11 @@ static unsigned int tb_available_credits(const struct tb_port *port,
 		 * Maximum number of DP streams possible through the
 		 * lane adapter.
 		 */
-		ndp = (credits - (usb3 + pcie + spare)) /
-		      (sw->min_dp_aux_credits + sw->min_dp_main_credits);
+		if (sw->min_dp_aux_credits + sw->min_dp_main_credits)
+			ndp = (credits - (usb3 + pcie + spare)) /
+			      (sw->min_dp_aux_credits + sw->min_dp_main_credits);
+		else
+			ndp = 0;
 	} else {
 		ndp = 0;
 	}
-- 
2.35.3