All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] RDMA/hns: Use 64-bit arithmetic instead of 32-bit
@ 2018-10-18  8:02 Gustavo A. R. Silva
  2018-10-18 11:01 ` Leon Romanovsky
  2018-10-22 18:15 ` Jason Gunthorpe
  0 siblings, 2 replies; 6+ messages in thread
From: Gustavo A. R. Silva @ 2018-10-18  8:02 UTC (permalink / raw)
  To: Lijun Ou, Wei Hu(Xavier), Doug Ledford, Jason Gunthorpe
  Cc: linux-rdma, linux-kernel, Gustavo A. R. Silva

Cast *max_num_sg* to u64 in order to give the compiler complete
information about the proper arithmetic to use.

Notice that such variable is used in a context that expects an
expression of type u64 (64 bits, unsigned) and the following
expression is currently being evaluated using 32-bit
arithmetic:

length = max_num_sg * page_size;

Addresses-Coverity-ID: 1474517 ("Unintentional integer overflow")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 drivers/infiniband/hw/hns/hns_roce_mr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/hns/hns_roce_mr.c b/drivers/infiniband/hw/hns/hns_roce_mr.c
index 521ad2a..d479d5e 100644
--- a/drivers/infiniband/hw/hns/hns_roce_mr.c
+++ b/drivers/infiniband/hw/hns/hns_roce_mr.c
@@ -1219,7 +1219,7 @@ struct ib_mr *hns_roce_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
 	int ret;
 
 	page_size = 1 << (hr_dev->caps.pbl_buf_pg_sz + PAGE_SHIFT);
-	length = max_num_sg * page_size;
+	length = (u64)max_num_sg * page_size;
 
 	if (mr_type != IB_MR_TYPE_MEM_REG)
 		return ERR_PTR(-EINVAL);
-- 
2.7.4

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

end of thread, other threads:[~2018-10-29 10:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-18  8:02 [PATCH] RDMA/hns: Use 64-bit arithmetic instead of 32-bit Gustavo A. R. Silva
2018-10-18 11:01 ` Leon Romanovsky
2018-10-19  0:17   ` Doug Ledford
2018-10-29 10:07     ` Leon Romanovsky
2018-10-22 18:15 ` Jason Gunthorpe
2018-10-22 18:22   ` Gustavo A. R. Silva

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.