Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1708433pxb; Mon, 23 Aug 2021 02:41:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8k49Kia9i+/MNHsa9fifxgHvk35lHT+4hEJ1SYCzxBwfiZ+KQEfgS6HIWrWxXLpYPp+J8 X-Received: by 2002:a05:6638:13d6:: with SMTP id i22mr28657174jaj.13.1629711681537; Mon, 23 Aug 2021 02:41:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629711681; cv=none; d=google.com; s=arc-20160816; b=zPGJR8khbBa5CiYGlB8Zte/jbjpbywXPj812pDpO6uqnf3IKaWsidGkfZf4olUbimZ SV6wW+lZPOQG8Eow2I+pZcuNQ21uQVyWQE87CsN8PBh4nI/keE00yCv7MwOy4zffVWtD yehkDAiIEY2cn+U8V4AeD2ZfOrvM2oexK+XiFxWSXaYBiYUeK6sf6FiUZQeLv2UiuTSm U/Ce5uKsbh/ql80YTtH2RlJd/1QAN4ACI0t5hITiNZP2OSQCGM34jv1eI2tmRE9ojqc2 iNktxShNxRE5dsIZ45j22u+m3picvcwiLnzaPckWKwJXWLMUyjE6m6VCR1d+RnVb/8Iz lxiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:content-transfer-encoding:date :message-id:to:from:sender:reply-to:subject:mime-version :dkim-signature:dkim-filter; bh=uyE27SkHI3Ns9KOB7Haj/anPPTHAw4hz43j27DE7sto=; b=tUDAg4fUH0uSEH6w8FSp2cAV5ikKJ2iynhQ7CKZcLYHtwafGiBxY/yi48vzA9hRBI7 C9AyK5QZPnPAjxJN9ViRmExP6LKkbCZFFCnyGnVIy7TAkXUETQyti2t+m2s+vXmcJKrQ sbWO0zFMnxtIBwLgCReQSXYCDODs4UtWOQG0iTC/k2qSkVx7VoKcZJaHSp+vwzxW898K BEp0JtlKaVZ2Xvmh/MjYC6knnhZ9tN7e2bcSdza/Id/evIb+TwH28rJS8CWRyklU2xIJ Af0G+GYKL2ef8LoNnNRllg9rXfEq3N1qVuL2wwLLSjasSYqB/Z3NusMdfrIV+qEpmGB1 KNpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=rXNT64Uq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f10si11224900ilk.8.2021.08.23.02.41.09; Mon, 23 Aug 2021 02:41:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=rXNT64Uq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235722AbhHWJkq (ORCPT + 99 others); Mon, 23 Aug 2021 05:40:46 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:30580 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229845AbhHWJkp (ORCPT ); Mon, 23 Aug 2021 05:40:45 -0400 Received: from epcas3p2.samsung.com (unknown [182.195.41.20]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20210823094002epoutp01c87ac104b313746fe4f7796a71b139e8~d5hFGaMvy0160701607epoutp01c for ; Mon, 23 Aug 2021 09:40:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20210823094002epoutp01c87ac104b313746fe4f7796a71b139e8~d5hFGaMvy0160701607epoutp01c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1629711602; bh=uyE27SkHI3Ns9KOB7Haj/anPPTHAw4hz43j27DE7sto=; h=Subject:Reply-To:From:To:Date:References:From; b=rXNT64UqzUsuW2WUCtsGbc3RD0eVFdOYk8ih1YxuNAf5DFajaSKftWlStmj+QVGdf /jbzxlIQcfU6aPG0EJzRJrzSwkFnJeB7aRAeGKUNKFz8PBCTLnS1q4986QL6j0VGy7 ciHTUeczde2bTW/limi0dxJTm5AIktuHPGaev+3g= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas3p1.samsung.com (KnoxPortal) with ESMTP id 20210823094001epcas3p12d76e0c9add42297a67e30a71f76ea91~d5hEdJk_A0763607636epcas3p1H; Mon, 23 Aug 2021 09:40:01 +0000 (GMT) Received: from epcpadp3 (unknown [182.195.40.17]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4GtRzj2Gbxz4x9Pw; Mon, 23 Aug 2021 09:40:01 +0000 (GMT) Mime-Version: 1.0 Subject: [PATCH v2] scsi: ufs: ufshpb: Fix possible memory leak Reply-To: keosung.park@samsung.com Sender: Keoseong Park From: Keoseong Park To: ALIM AKHTAR , "avri.altman@wdc.com" , "jejb@linux.ibm.com" , "martin.petersen@oracle.com" , Daejun Park , "beanhuo@micron.com" , "cang@codeaurora.org" , "linux-scsi@vger.kernel.org" , "linux-kernel@vger.kernel.org" X-Priority: 3 X-Content-Kind-Code: NORMAL X-CPGS-Detection: blocking_info_exchange X-Drm-Type: N,general X-Msg-Generator: Mail X-Msg-Type: PERSONAL X-Reply-Demand: N Message-ID: <1891546521.01629711601304.JavaMail.epsvc@epcpadp3> Date: Mon, 23 Aug 2021 18:07:14 +0900 X-CMS-MailID: 20210823090714epcms2p1e414fdd91582bdbf8170b4cefb8a0f74 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: AUTO_CONFIDENTIAL X-CPGSPASS: Y X-CPGSPASS: Y X-Hop-Count: 3 X-CMS-RootMailID: 20210823090714epcms2p1e414fdd91582bdbf8170b4cefb8a0f74 References: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When HPB pinned region exists and mctx allocation for this region fails, memory leak is possible because memory is not released for the subregion table of the current region. So, change to free memory for the subregion table of the current region. Signed-off-by: Keoseong Park --- v1 -> v2: * Merge new kvfree() statement with the for-loop below it. * Change to assign "hpb->rgn_tbl" when no error occurs. drivers/scsi/ufs/ufshpb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 9acce92a356b..58db9ab8f0ae 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -1904,8 +1904,6 @@ static int ufshpb_alloc_region_tbl(struct ufs_hba *hba, struct ufshpb_lu *hpb) if (!rgn_table) return -ENOMEM; - hpb->rgn_tbl = rgn_table; - for (rgn_idx = 0; rgn_idx < hpb->rgns_per_lu; rgn_idx++) { int srgn_cnt = hpb->srgns_per_rgn; bool last_srgn = false; @@ -1942,10 +1940,12 @@ static int ufshpb_alloc_region_tbl(struct ufs_hba *hba, struct ufshpb_lu *hpb) rgn->hpb = hpb; } + hpb->rgn_tbl = rgn_table; + return 0; release_srgn_table: - for (i = 0; i < rgn_idx; i++) + for (i = 0; i <= rgn_idx; i++) kvfree(rgn_table[i].srgn_tbl); kvfree(rgn_table); -- 2.17.1