From patchwork Fri Oct 28 16:33:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yongjun X-Patchwork-Id: 9402303 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 AF26E6022E for ; Fri, 28 Oct 2016 16:33:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1BA72A8AE for ; Fri, 28 Oct 2016 16:33:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 958822A8B0; Fri, 28 Oct 2016 16:33:56 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 18E9F2A8AE for ; Fri, 28 Oct 2016 16:33:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S941716AbcJ1Qdz (ORCPT ); Fri, 28 Oct 2016 12:33:55 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:33561 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S937846AbcJ1Qdy (ORCPT ); Fri, 28 Oct 2016 12:33:54 -0400 Received: by mail-pf0-f193.google.com with SMTP id i85so1677219pfa.0 for ; Fri, 28 Oct 2016 09:33:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2TnBuiHWNppZdyBtMmcp8E31rh2NesmwsIuDu1d5a08=; b=0UeGO+ZjfRCnPYtS6Xo5xjawlyxtp5la73tlzxRpn+wcrjSFFNfOWxyeYCAORNjBTl o0+5sOR3YfGDPk3q75RCrwTgR0j3kjuNfVx5P/UgRsThlbfB2yjWd+BSFmjyeXNZMtPs u6IHpsbz4Q3y3uj+WVuuoAJpVjME97hBdseyBzBA85Mzum7nWq2swNxAtEtP6S6M5oO/ 9j+2H4hcpS5jpORjB29KYXbCps5IjsGJw6ZcAcTHjG0PVBoBfiFZgCZsVfQAhBGSbtLc FRR67h3WADn5AcIvGRRsBG+fzItRi+Y4GtDnuUh5rPVUvBmSip1QSIVJ32/L4ptA0Vph hJOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2TnBuiHWNppZdyBtMmcp8E31rh2NesmwsIuDu1d5a08=; b=Jbv979CAriqLEGCzqayy7ZxEAmB0Fo4LSRCKtNdvvNxJtnEwxTrIpWkk09E9e7py/y 8Kha/2g/0iLqtQfbgg6QtHoql5T89nt2vpALn2lUVlP5AWx2OKn7F2tZ30aqF5nIZupg dgxNMuJqsnXENcpOUFjNyIarLNIjOiP+4yz6b4194mTRhe3xIRtzBUjgS/M0yeP8Rxat W3DNeEUcZCHnV3UmadUAS1HrfmSSdmbdKjXQuBM2+663gYIp93UHuak5hu7qdrRhZz1j xb79+IBOXF0mGp9mgFnudKwWO5VfNwPZcAF1+z/r07LoBFl+/m1Vw8LLpwwfV8YkGvip z0Jw== X-Gm-Message-State: ABUngvcnYmUDAtOr5+bFtd0YYndq6oD1UZPE1E/if6DDdclDLeVCDMNl6xv4hoLcCoroHQ== X-Received: by 10.98.102.84 with SMTP id a81mr26074593pfc.176.1477672433589; Fri, 28 Oct 2016 09:33:53 -0700 (PDT) Received: from 192.168.0.37 (ec2-52-192-197-227.ap-northeast-1.compute.amazonaws.com. [52.192.197.227]) by smtp.gmail.com with ESMTPSA id 128sm20089795pfy.4.2016.10.28.09.33.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Oct 2016 09:33:53 -0700 (PDT) From: Wei Yongjun To: Doug Ledford , Sean Hefty , Hal Rosenstock , Ram Amrani , Rajesh Borundia Cc: Wei Yongjun , linux-rdma@vger.kernel.org Subject: [PATCH] qedr: Fix possible memory leak in qedr_create_qp() Date: Fri, 28 Oct 2016 16:33:47 +0000 Message-Id: <1477672427-31575-1-git-send-email-weiyj.lk@gmail.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 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: Wei Yongjun 'qp' is malloced in qedr_create_qp() and should be freed before leaving from the error handling cases, otherwise it will cause memory leak. Signed-off-by: Wei Yongjun Acked-by: Ram Amrani --- drivers/infiniband/hw/qedr/verbs.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/infiniband/hw/qedr/verbs.c b/drivers/infiniband/hw/qedr/verbs.c index a615142..b60f145 100644 --- a/drivers/infiniband/hw/qedr/verbs.c +++ b/drivers/infiniband/hw/qedr/verbs.c @@ -1477,6 +1477,7 @@ struct ib_qp *qedr_create_qp(struct ib_pd *ibpd, struct qedr_ucontext *ctx = NULL; struct qedr_create_qp_ureq ureq; struct qedr_qp *qp; + struct ib_qp *ibqp; int rc = 0; DP_DEBUG(dev, QEDR_MSG_QP, "create qp: called from %s, pd=%p\n", @@ -1486,13 +1487,13 @@ struct ib_qp *qedr_create_qp(struct ib_pd *ibpd, if (rc) return ERR_PTR(rc); + if (attrs->srq) + return ERR_PTR(-EINVAL); + qp = kzalloc(sizeof(*qp), GFP_KERNEL); if (!qp) return ERR_PTR(-ENOMEM); - if (attrs->srq) - return ERR_PTR(-EINVAL); - DP_DEBUG(dev, QEDR_MSG_QP, "create qp: sq_cq=%p, sq_icid=%d, rq_cq=%p, rq_icid=%d\n", get_qedr_cq(attrs->send_cq), @@ -1508,7 +1509,10 @@ struct ib_qp *qedr_create_qp(struct ib_pd *ibpd, "create qp: unexpected udata when creating GSI QP\n"); goto err0; } - return qedr_create_gsi_qp(dev, attrs, qp); + ibqp = qedr_create_gsi_qp(dev, attrs, qp); + if (IS_ERR(ibqp)) + kfree(qp); + return ibqp; } memset(&in_params, 0, sizeof(in_params));