From patchwork Thu Oct 18 08:02:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 10646861 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D68F112B for ; Thu, 18 Oct 2018 08:24:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE9BD274D0 for ; Thu, 18 Oct 2018 08:24:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFC742882A; Thu, 18 Oct 2018 08:24:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A7BA274D0 for ; Thu, 18 Oct 2018 08:24:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726323AbeJRQYh (ORCPT ); Thu, 18 Oct 2018 12:24:37 -0400 Received: from gateway36.websitewelcome.com ([192.185.197.22]:32678 "EHLO gateway36.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726131AbeJRQYh (ORCPT ); Thu, 18 Oct 2018 12:24:37 -0400 X-Greylist: delayed 1285 seconds by postgrey-1.27 at vger.kernel.org; Thu, 18 Oct 2018 12:24:36 EDT Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway36.websitewelcome.com (Postfix) with ESMTP id DD9D4400C8ADB for ; Thu, 18 Oct 2018 02:10:29 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id D3GngfMRVaSeyD3H0gzpIU; Thu, 18 Oct 2018 03:03:23 -0500 X-Authority-Reason: nr=8 Received: from lfbn-1-466-13.w86-245.abo.wanadoo.fr ([86.245.173.13]:48410 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1gD3Gm-004N1d-9D; Thu, 18 Oct 2018 03:03:00 -0500 Date: Thu, 18 Oct 2018 10:02:58 +0200 From: "Gustavo A. R. Silva" To: Lijun Ou , "Wei Hu(Xavier)" , Doug Ledford , Jason Gunthorpe Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] RDMA/hns: Use 64-bit arithmetic instead of 32-bit Message-ID: <20181018080258.GA1720@embeddedor.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 86.245.173.13 X-Source-L: No X-Exim-ID: 1gD3Gm-004N1d-9D X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: lfbn-1-466-13.w86-245.abo.wanadoo.fr (embeddedor) [86.245.173.13]:48410 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 5 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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);