Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3080151imw; Mon, 11 Jul 2022 01:01:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vbFc4Ht9vxieDmh9+liNjlv7pwcenQtlg70+5nJ5+BX+mtKmaeDPl4A84b6wAY6KSRVIbE X-Received: by 2002:aa7:d60a:0:b0:43a:5795:b729 with SMTP id c10-20020aa7d60a000000b0043a5795b729mr22918774edr.230.1657526513351; Mon, 11 Jul 2022 01:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657526513; cv=none; d=google.com; s=arc-20160816; b=WdTpjgtreDQH6SiBLNqEN9sxyJdNQNAv3Qv6e508+daLNwMDHdvtp4A6RXnFxil5Wi nS8jyCIGmwhdwSa1EYYYV8fKAaXtz/qskhntgAjO6E2EH+lsN0J5lPTN0CjxwhbXr5sT A2CB+Haw/A85dTsZAG2uWbIrYuuIRIPZkCB36uOp0Bnl/9i2ATvtFYfCeDjz0IGdMXEq u+nSe0VJ2AconClMtqlSbiakrhOOLGLRvTVOwCWxelBOj9ySvyuqUjkv69kJOw6ulB88 mAXQPBWxknlHucjlNuYxoS3gq5mXsb9ARhuTOAGvWg6Z5dVFkFZmH5FyKV+lY1umoSKU sq6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=OS8yMoEJWC5pIc75D33LcDyvm2Vl3MkjdgsLOHnTjlI=; b=QgUi+NTjwOXQX/mrBYNYontUyxXwzqT6LlSRIAVN4tw/T/yb06v+QyK0OSvK2v3Bjg IV8Tn/AYFDJJbSVYI5zprMHLmB3HkoKzmLAPAGmDfiffWIoYYIR1PPxUFMZqh1YHAHx2 BqF2pwX5XaGM8eYatqtjjIUjkCex1xB7oSX8c/zQE9sb8nOa9wyC+0w0s7adtNzCAcF6 +QtfUqQyhAqj+oTByVl/ZDbX3E27lyFK4ZujR8iB6BZbhRgMC2PhbYrLBn3pB2syBl7O 3FxU3lY9JuI871ISpLnwe32c04OTU48mIRimQOIp0PMy6vBhaVesQ0QgavF2/6ZVbARp klfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=fpPb2r1S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q8-20020a170906388800b0072a4d2a1a4dsi8032575ejd.767.2022.07.11.01.01.27; Mon, 11 Jul 2022 01:01:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=fpPb2r1S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229958AbiGKHJC (ORCPT + 99 others); Mon, 11 Jul 2022 03:09:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229934AbiGKHIR (ORCPT ); Mon, 11 Jul 2022 03:08:17 -0400 Received: from mail-m973.mail.163.com (mail-m973.mail.163.com [123.126.97.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 050B01ADA7; Mon, 11 Jul 2022 00:07:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=OS8yM oEJWC5pIc75D33LcDyvm2Vl3MkjdgsLOHnTjlI=; b=fpPb2r1SRLjaz/7u3Eh6A Yo0yfDPbOvbwcSsQ/a3iPfxVFWCxhJ7FOEvPN9gkx18e2yHn9s3mZOrZmjYiffTD RG3cDsHcKN3peqZa0gPPFWhkWNyddrsdLg1/5NRat+blS8Z6vXSSkeCNAs8ygJxv lSQXzFERcMQU1xq2CZ47xc= Received: from localhost.localdomain (unknown [123.112.69.106]) by smtp3 (Coremail) with SMTP id G9xpCgDn_4knzMtimgUiOg--.9376S4; Mon, 11 Jul 2022 15:07:25 +0800 (CST) From: Jianglei Nie To: dennis.dalessandro@cornelisnetworks.com, jgg@ziepe.ca, leon@kernel.org Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Jianglei Nie Subject: [PATCH] RDMA/hfi1: fix potential memory leak in setup_base_ctxt() Date: Mon, 11 Jul 2022 15:07:18 +0800 Message-Id: <20220711070718.2318320-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: G9xpCgDn_4knzMtimgUiOg--.9376S4 X-Coremail-Antispam: 1Uf129KBjvdXoW7Gw47GrW3Xw43Jw17Xw1xAFb_yoWfKrcEgr yUuryDXr4YkwsYvw40vws3ZrWIqrW8Xrs5Za9aq3sxAF15CrZxtF1kuF43X348ZayjvFW5 urs7Kr4SyF4fKjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRibAwPUUUUU== X-Originating-IP: [123.112.69.106] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/1tbiQxU7jFc7ajP70QAAs+ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org setup_base_ctxt() allocates a memory chunk for uctxt->groups with hfi1_alloc_ctxt_rcv_groups(). When init_user_ctxt() fails, uctxt->groups is not released, which will lead to a memory leak. We should release the uctxt->groups with hfi1_free_ctxt_rcv_groups() when init_user_ctxt() fails. Signed-off-by: Jianglei Nie --- drivers/infiniband/hw/hfi1/file_ops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/hfi1/file_ops.c b/drivers/infiniband/hw/hfi1/file_ops.c index 2e4cf2b11653..629beff053ad 100644 --- a/drivers/infiniband/hw/hfi1/file_ops.c +++ b/drivers/infiniband/hw/hfi1/file_ops.c @@ -1179,8 +1179,10 @@ static int setup_base_ctxt(struct hfi1_filedata *fd, goto done; ret = init_user_ctxt(fd, uctxt); - if (ret) + if (ret) { + hfi1_free_ctxt_rcv_groups(uctxt); goto done; + } user_init(uctxt); -- 2.25.1