From patchwork Sat Jun 18 10:34:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 9185507 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 F3FBD601C0 for ; Sat, 18 Jun 2016 10:34:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D543B24151 for ; Sat, 18 Jun 2016 10:34:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C702F25EA6; Sat, 18 Jun 2016 10:34:39 +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, T_TVD_MIME_EPI 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 4369024151 for ; Sat, 18 Jun 2016 10:34:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751066AbcFRKeg (ORCPT ); Sat, 18 Jun 2016 06:34:36 -0400 Received: from mail.kernel.org ([198.145.29.136]:37000 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751007AbcFRKef (ORCPT ); Sat, 18 Jun 2016 06:34:35 -0400 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 20B722020F; Sat, 18 Jun 2016 10:34:34 +0000 (UTC) Received: from localhost (unknown [213.57.247.249]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B61B1201F4; Sat, 18 Jun 2016 10:34:32 +0000 (UTC) Date: Sat, 18 Jun 2016 13:34:30 +0300 From: Leon Romanovsky To: Dan Carpenter Cc: Moni Shoua , Doug Ledford , Sean Hefty , Hal Rosenstock , linux-rdma@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [patch] ib/rxe: double free on error Message-ID: <20160618103430.GC5408@leon.nu> Reply-To: leon@kernel.org References: <20160618084021.GB21713@mwanda> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160618084021.GB21713@mwanda> User-Agent: Mutt/1.5.23 (2014-03-12) X-Virus-Scanned: ClamAV using ClamSMTP 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 On Sat, Jun 18, 2016 at 11:40:21AM +0300, Dan Carpenter wrote: > "goto err1" could probably be remained "goto free_pkey_tbl" since > that's what it does. This is a double free. > > Fixes: 0784481b2f32 ('Add initialization for Soft RoCE driver, pools constants etc.') > Signed-off-by: Dan Carpenter Hi Dan, Thank you for pointing it out. I rewrote your patch a little bit and applied it. From 6a320576c7304905df722afcf1b8d49242c8ae48 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Sat, 18 Jun 2016 11:40:21 +0300 Subject: [PATCH] IB/rxe: Simplify rxe_init_ports logic Simplify rxe_init_ports and remove double free. Fixes: 0784481b2f32 ('Add initialization for Soft RoCE driver, pools constants etc.') Signed-off-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..156a1021 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 */ -- 2.1.4