From patchwork Sun Jun 24 08:23:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 10484053 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BA198601C3 for ; Sun, 24 Jun 2018 08:25:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A814A28947 for ; Sun, 24 Jun 2018 08:25:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C7EB28964; Sun, 24 Jun 2018 08:25:03 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 4A9D628947 for ; Sun, 24 Jun 2018 08:25:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752033AbeFXIYe (ORCPT ); Sun, 24 Jun 2018 04:24:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:52984 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751823AbeFXIYa (ORCPT ); Sun, 24 Jun 2018 04:24:30 -0400 Received: from localhost (unknown [193.47.165.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A885B24E49; Sun, 24 Jun 2018 08:24:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1529828670; bh=MtJTygSGmW4CGusiewPOH/14kPvTBtBCRpTs1NMryzA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e6bK/MMcyqkJXVHCuEHK9BQJiz8KURqjR730oNFmLkriLRDNCsiUUKS7uiU778qvb Gt8OveLckc/Dxf8Pyfw0FhLJuGfNe55fNtRjbLCOPHxd5wDgYQ6p+BVPhBovRPYlDZ 2qOdbQX2eLau5u7jEf+OMYXzCFqcEsd7AgM64iRg= From: Leon Romanovsky To: Doug Ledford , Jason Gunthorpe Cc: Leon Romanovsky , RDMA mailing list , Hadar Hen Zion , Matan Barak , Michael J Ruhl , Noa Osherovich , Raed Salem , Yishai Hadas , Saeed Mahameed , linux-netdev Subject: [PATCH rdma-next 10/12] RDMA/mlx5: Reuse existed shift_overlow helper Date: Sun, 24 Jun 2018 11:23:51 +0300 Message-Id: <20180624082353.16138-11-leon@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180624082353.16138-1-leon@kernel.org> References: <20180624082353.16138-1-leon@kernel.org> 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 From: Leon Romanovsky Rewrite commit 002bf2282b2d ("RDMA/mlx5: Protect from shift operand overflow") to reuse newly introduced shift_overflow() helper. Signed-off-by: Leon Romanovsky --- drivers/infiniband/hw/mlx5/qp.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c index 8e40263fd40e..5471b57b873d 100644 --- a/drivers/infiniband/hw/mlx5/qp.c +++ b/drivers/infiniband/hw/mlx5/qp.c @@ -259,13 +259,17 @@ static int set_rq_size(struct mlx5_ib_dev *dev, struct ib_qp_cap *cap, cap->max_recv_sge = 0; } else { if (ucmd) { + size_t s; + qp->rq.wqe_cnt = ucmd->rq_wqe_count; - if (ucmd->rq_wqe_shift > BITS_PER_BYTE * sizeof(ucmd->rq_wqe_shift)) + s = shift_overflow(1, ucmd->rq_wqe_shift); + if (s == SIZE_MAX) return -EINVAL; qp->rq.wqe_shift = ucmd->rq_wqe_shift; - if ((1 << qp->rq.wqe_shift) / sizeof(struct mlx5_wqe_data_seg) < qp->wq_sig) + if (s / sizeof(struct mlx5_wqe_data_seg) < qp->wq_sig) return -EINVAL; - qp->rq.max_gs = (1 << qp->rq.wqe_shift) / sizeof(struct mlx5_wqe_data_seg) - qp->wq_sig; + qp->rq.max_gs = s / sizeof(struct mlx5_wqe_data_seg) - + qp->wq_sig; qp->rq.max_post = qp->rq.wqe_cnt; } else { wqe_size = qp->wq_sig ? sizeof(struct mlx5_wqe_signature_seg) : 0;