From patchwork Tue Jul 5 16:10:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moni Shoua X-Patchwork-Id: 9214717 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 4D9D060752 for ; Tue, 5 Jul 2016 16:11:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DAB81FF29 for ; Tue, 5 Jul 2016 16:11:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3035526E64; Tue, 5 Jul 2016 16:11:20 +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=-6.9 required=2.0 tests=BAYES_00, 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 B5ABE1FF29 for ; Tue, 5 Jul 2016 16:11:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755249AbcGEQLS (ORCPT ); Tue, 5 Jul 2016 12:11:18 -0400 Received: from [193.47.165.129] ([193.47.165.129]:43323 "EHLO mellanox.co.il" rhost-flags-FAIL-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1755205AbcGEQLS (ORCPT ); Tue, 5 Jul 2016 12:11:18 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from monis@mellanox.com) with ESMTPS (AES256-SHA encrypted); 5 Jul 2016 19:10:26 +0300 Received: from r-vnc06.mtr.labs.mlnx (r-vnc06.mtr.labs.mlnx [10.208.0.117]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id u65GAQmN024684; Tue, 5 Jul 2016 19:10:26 +0300 From: Moni Shoua To: dledford@redhat.com Cc: linux-rdma@vger.kernel.org, matanb@mellanox.com, talal@mellanox.com, leonro@mellanox.com, majd@mellanox.com, Leon Romanovsky Subject: [PATCH rdma-next] IB/rxe: Simplify rxe_init_ports logic Date: Tue, 5 Jul 2016 19:10:23 +0300 Message-Id: <1467735023-21942-1-git-send-email-monis@mellanox.com> X-Mailer: git-send-email 1.7.6.4 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 Simplify rxe_init_ports and remove double free. Fixes: 0784481b2f32 ('Add initialization for Soft RoCE driver, pools constants etc.') Reported-by: Dan Carpenter Signed-off-by: Leon Romanovsky --- drivers/infiniband/hw/rxe/rxe.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/drivers/infiniband/hw/rxe/rxe.c b/drivers/infiniband/hw/rxe/rxe.c index 48c41e00..d49418b 100644 --- a/drivers/infiniband/hw/rxe/rxe.c +++ b/drivers/infiniband/hw/rxe/rxe.c @@ -165,42 +165,25 @@ static int rxe_init_port_param(struct rxe_port *port) */ static int rxe_init_ports(struct rxe_dev *rxe) { - int err; - struct rxe_port *port; - - port = &rxe->port; + struct rxe_port *port = &rxe->port; rxe_init_port_param(port); - if (!port->attr.pkey_tbl_len) { - err = -EINVAL; - goto err1; - } + if (!port->attr.pkey_tbl_len || !port->attr.gid_tbl_len) + return -EINVAL; port->pkey_tbl = kcalloc(port->attr.pkey_tbl_len, sizeof(*port->pkey_tbl), GFP_KERNEL); - if (!port->pkey_tbl) { - err = -ENOMEM; - goto err1; - } - port->pkey_tbl[0] = 0xffff; - - if (!port->attr.gid_tbl_len) { - kfree(port->pkey_tbl); - err = -EINVAL; - goto err1; - } + if (!port->pkey_tbl) + return -ENOMEM; + port->pkey_tbl[0] = 0xffff; port->port_guid = rxe->ifc_ops->port_guid(rxe); spin_lock_init(&port->port_lock); return 0; - -err1: - kfree(port->pkey_tbl); - return err; } /* init pools of managed objects */