From patchwork Mon Mar 27 07:06:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhu Yanjun X-Patchwork-Id: 9645399 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 BD9AF602BF for ; Mon, 27 Mar 2017 07:07:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE8262832D for ; Mon, 27 Mar 2017 07:07:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A188628356; Mon, 27 Mar 2017 07:07:27 +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 5B5282832D for ; Mon, 27 Mar 2017 07:07:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752033AbdC0HH0 (ORCPT ); Mon, 27 Mar 2017 03:07:26 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:22570 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751633AbdC0HH0 (ORCPT ); Mon, 27 Mar 2017 03:07:26 -0400 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v2R76iSC019463 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2017 07:06:45 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v2R76iFU010092 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 27 Mar 2017 07:06:44 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v2R76i8L011549; Mon, 27 Mar 2017 07:06:44 GMT Received: from redman.cn.oracle.com (/10.113.194.127) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 27 Mar 2017 00:06:43 -0700 From: Zhu Yanjun To: yanjun.zhu@oracle.com, santosh.shilimkar@oracle.com, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, rds-devel@oss.oracle.com, junxiao.bi@oracle.com, joe.jin@oracle.com Subject: [PATCH 2/5] rds: rdma: fix memory leak error Date: Mon, 27 Mar 2017 03:06:27 -0400 Message-Id: <1490598390-13812-3-git-send-email-yanjun.zhu@oracle.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490598390-13812-1-git-send-email-yanjun.zhu@oracle.com> References: <1490598390-13812-1-git-send-email-yanjun.zhu@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] 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 In the function __rds_rdma_map, the allocated memory and other resources should be freed when some error occurs. Signed-off-by: Zhu Yanjun --- net/rds/rdma.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/rds/rdma.c b/net/rds/rdma.c index f06fac4..ad9b6bd 100644 --- a/net/rds/rdma.c +++ b/net/rds/rdma.c @@ -253,6 +253,8 @@ static int __rds_rdma_map(struct rds_sock *rs, struct rds_get_mr_args *args, sg = kcalloc(nents, sizeof(*sg), GFP_KERNEL); if (!sg) { ret = -ENOMEM; + for (i = 0; i < nents; i++) + put_page(pages[i]); goto out; } WARN_ON(!nents); @@ -293,6 +295,11 @@ static int __rds_rdma_map(struct rds_sock *rs, struct rds_get_mr_args *args, *cookie_ret = cookie; if (args->cookie_addr && put_user(cookie, (u64 __user *)(unsigned long) args->cookie_addr)) { + for (i = 0; i < nents; i++) + put_page(sg_page(&sg[i])); + kfree(sg); + mr->r_trans->free_mr(mr->r_trans_private, 1); + mr->r_trans_private = NULL; ret = -EFAULT; goto out; }