From patchwork Thu Dec 6 11:06:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuval Shaia X-Patchwork-Id: 10715603 X-Patchwork-Delegate: leon@leon.nu 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 B338A109C for ; Thu, 6 Dec 2018 11:06:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A164A2D000 for ; Thu, 6 Dec 2018 11:06:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 947BC2D3A6; Thu, 6 Dec 2018 11:06:33 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 EE4BC2D000 for ; Thu, 6 Dec 2018 11:06:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729289AbeLFLGc (ORCPT ); Thu, 6 Dec 2018 06:06:32 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:52210 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728245AbeLFLGc (ORCPT ); Thu, 6 Dec 2018 06:06:32 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wB6B4O0W031696; Thu, 6 Dec 2018 11:06:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=k7VSATV25rjnjDP8j+E1U2+JElHByyWfukXwKiDRFV0=; b=4rQAy7ldrnxgTNd83hD14TNOqg8EdEgYuUJ/MtU0EwOyDpnHiXNr3slPs6PTxGIqOrWi fRYGR037ump6zuirUTJdC3+YaB9hdEykFRvLs2755u/D3eL3XVdNaQeg5IrwxLZUGBxZ CSUVtsV8oxxpMCp22bzrRLxrpmEpWbLL2jmqaNW3FjA4FgiMzaoCH/6Ox8OvWU4FxWwP Enu6yMhE/AnWJXCb+XOY/Fe1OaSg9DEDwKhIiH8cbGopwbs6/gI+8OD80/4eZp4NEqW7 nDIRperMW9ZXo3zrTK+mkPhPYWJsYCXiKVetbh0ZxmabM2o298iFUXiEUM2Wxj3Mv8yV dw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2p3ftfbh4u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 06 Dec 2018 11:06:25 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wB6B6OwK030623 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 6 Dec 2018 11:06:25 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id wB6B6On6012960; Thu, 6 Dec 2018 11:06:24 GMT Received: from localhost.localdomain (/77.138.186.148) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 06 Dec 2018 03:06:23 -0800 From: Yuval Shaia To: monis@mellanox.com, dledford@redhat.com, jgg@ziepe.ca, linux-rdma@vger.kernel.org Cc: Yuval Shaia Subject: [PATCH] IB/rxe: Utilize generic function to validate port number Date: Thu, 6 Dec 2018 13:06:15 +0200 Message-Id: <20181206110615.9053-1-yuval.shaia@oracle.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9098 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812060100 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 RXE has only one port. No need to hard code it on every verb instead use rdma_is_port_valid to validate the given port number. Signed-off-by: Yuval Shaia --- drivers/infiniband/sw/rxe/rxe_verbs.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c index 30817c79ba96..88fdb8890038 100644 --- a/drivers/infiniband/sw/rxe/rxe_verbs.c +++ b/drivers/infiniband/sw/rxe/rxe_verbs.c @@ -51,6 +51,16 @@ static int rxe_query_device(struct ib_device *dev, return 0; } +static bool rxe_is_port_valid(struct rxe_dev *rxe, u8 port_num) +{ + if (unlikely(!rdma_is_port_valid(&rxe->ib_dev, port_num))) { + pr_warn("Invalid port number %d\n", port_num); + return 0; + } + + return 1; +} + static int rxe_query_port(struct ib_device *dev, u8 port_num, struct ib_port_attr *attr) { @@ -58,10 +68,8 @@ static int rxe_query_port(struct ib_device *dev, struct rxe_port *port; int rc = -EINVAL; - if (unlikely(port_num != 1)) { - pr_warn("invalid port_number %d\n", port_num); + if (unlikely(!rxe_is_port_valid(rxe, port_num))) goto out; - } port = &rxe->port; @@ -104,11 +112,8 @@ static int rxe_query_pkey(struct ib_device *device, struct rxe_dev *rxe = to_rdev(device); struct rxe_port *port; - if (unlikely(port_num != 1)) { - dev_warn(device->dev.parent, "invalid port_num = %d\n", - port_num); + if (unlikely(!rxe_is_port_valid(rxe, port_num))) goto err1; - } port = &rxe->port; @@ -147,10 +152,8 @@ static int rxe_modify_port(struct ib_device *dev, struct rxe_dev *rxe = to_rdev(dev); struct rxe_port *port; - if (unlikely(port_num != 1)) { - pr_warn("invalid port_num = %d\n", port_num); + if (unlikely(!rxe_is_port_valid(rxe, port_num))) goto err1; - } port = &rxe->port;