diff mbox series

[for-next,3/6] RDMA/hfi1: Fix potential integer multiplication overflow errors

Message ID 20220520183712.48973.29855.stgit@awfm-01.cornelisnetworks.com (mailing list archive)
State Accepted
Delegated to: Jason Gunthorpe
Headers show
Series Updates for 5.19 | expand

Commit Message

Dennis Dalessandro May 20, 2022, 6:37 p.m. UTC
When multiplying of different types, an overflow is possible even
when storing the result in a larger type. This is because the
conversion is done after the multiplication. So arithmetic
overflow and thus in incorrect value is possible.

Correct an instance of this in the inter packet delay calculation.
Fix by ensuring one of the operands is u64 which will promote the
other to u64 as well ensuring no overflow.

Fixes: 7724105686e7 ("IB/hfi1: add driver files")
Cc: stable@vger.kernel.org
Reviewed-by: Mike Marciniszyn <mike.marciniszyn@cornelisnetworks.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
---
 drivers/infiniband/hw/hfi1/init.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/hfi1/init.c b/drivers/infiniband/hw/hfi1/init.c
index 4436ed4..436372b 100644
--- a/drivers/infiniband/hw/hfi1/init.c
+++ b/drivers/infiniband/hw/hfi1/init.c
@@ -489,7 +489,7 @@  void set_link_ipg(struct hfi1_pportdata *ppd)
 	u16 shift, mult;
 	u64 src;
 	u32 current_egress_rate; /* Mbits /sec */
-	u32 max_pkt_time;
+	u64 max_pkt_time;
 	/*
 	 * max_pkt_time is the maximum packet egress time in units
 	 * of the fabric clock period 1/(805 MHz).