Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1080544pxb; Thu, 19 Aug 2021 19:53:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwu1WPdlskLAvF133gPYbnopIHBmmZx+yFXlIHCqPhRsQiEk6jNs+mc4THwwqU/HYv2nfOP X-Received: by 2002:a05:6e02:2184:: with SMTP id j4mr12538227ila.30.1629427981560; Thu, 19 Aug 2021 19:53:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629427981; cv=none; d=google.com; s=arc-20160816; b=A8Z4AtKLlkUiHI2y1RDlRQ6nM7+es9xkvIhhZqx7C20aC6FYAwXYU3N/5raMy+T/i5 89MYocOI86HuZdWKkNWDvC9O39x8V1TckPVGIk4DlOMwAhAmepcSjBhMfYiWYnWKB1pE q+rf08RL1wwW23ccu1MT9JNrWFnhc67XxX9HJ1fOHd9UsN6JSvtjLUpuMegWXpBj2IbK 53W/fdh4TqKvZkTJR/Emiv/u/RDIR/ORj2V/vVS5wXBZ4aTKh7SspOuzoM4+dF0A8Ajp wlJP/32k5xnMJ0WvkfI1MrJH0nC/sn7/8r5IHO0Ilg+cKYo76IE/U4uDADF/2u4ogqiS EHhg== 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=h4IH088jehCETSAa9K4QBYYehY4vUxwWfjOEUe8G1uw=; b=DOFJRFyPOe/p1DqJydEsRkaFnENM5Qos8i//tWXVtZBC41Edi5XqIoNdXWC2HVpfDL oAbwEsD4157Zny1ZoRlP56GPQSuzPg1jBJwyj7EF2iwbf9dnUzWgMZ7s03z6cWzhJgDL rMs/FJIxNJHYvQqUCNoPiVvsngG47r7NLKv13tqA98+4C+EmsVeoQNOfo+4Bn3eJu4wH mENdIBJJPAoW82dlMXtWMCfKpT7oLIy3qrKF6He/ETkdvx9pswXWQmNxaBw+LS/xbm3m jTpLSo4OMEf2UhIRMGiB2ESRIeUqeMDKan/OxGgTA8UKwoc7NCbzMg+fNYlUxsarGyPx JJCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=iMjg3dOG; 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 i11si5185089ilm.28.2021.08.19.19.52.49; Thu, 19 Aug 2021 19:53:01 -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=iMjg3dOG; 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 S237848AbhHTCum (ORCPT + 99 others); Thu, 19 Aug 2021 22:50:42 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:60604 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237636AbhHTCum (ORCPT ); Thu, 19 Aug 2021 22:50:42 -0400 Received: from epcas3p4.samsung.com (unknown [182.195.41.22]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20210820025001epoutp03a7d0c2b7cf7b2aa37ef5c2ca49c53259~c4-PmgIYk1723317233epoutp03q for ; Fri, 20 Aug 2021 02:50:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20210820025001epoutp03a7d0c2b7cf7b2aa37ef5c2ca49c53259~c4-PmgIYk1723317233epoutp03q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1629427801; bh=h4IH088jehCETSAa9K4QBYYehY4vUxwWfjOEUe8G1uw=; h=Subject:Reply-To:From:To:Date:References:From; b=iMjg3dOG5vlnndAtVOOlSdFPj8YcJrBeG9W/Z9THJ3d3HfZakHpg7HyNZZryu+5+m A8t1MY23Fo9zkB2bia/5qt3nfc1fcYmcjUilY6H8TjtB8Ux9K9krOjIqTNoJg5nI3K zzIgI25V7/iHW6RClI2CHlI2J1uzFBa/gw489Ypk= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas3p1.samsung.com (KnoxPortal) with ESMTP id 20210820025001epcas3p1f1f72b2f017e6bc9eb8c19aed5c5c61a~c4-PLu0EH2298422984epcas3p16; Fri, 20 Aug 2021 02:50:01 +0000 (GMT) Received: from epcpadp3 (unknown [182.195.40.17]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4GrR212rLtz4x9QT; Fri, 20 Aug 2021 02:50:01 +0000 (GMT) Mime-Version: 1.0 Subject: [PATCH] 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" , "gregkh@linuxfoundation.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.01629427801384.JavaMail.epsvc@epcpadp3> Date: Fri, 20 Aug 2021 10:46:24 +0900 X-CMS-MailID: 20210820014624epcms2p6724e146ca1f93ba6eac5e7cf95d4cfd2 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: 20210820014624epcms2p6724e146ca1f93ba6eac5e7cf95d4cfd2 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 --- drivers/scsi/ufs/ufshpb.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 9acce92a356b..052f584c789a 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -1933,7 +1933,7 @@ static int ufshpb_alloc_region_tbl(struct ufs_hba *hba, struct ufshpb_lu *hpb) if (ufshpb_is_pinned_region(hpb, rgn_idx)) { ret = ufshpb_init_pinned_active_region(hba, hpb, rgn); if (ret) - goto release_srgn_table; + goto release_current_srgn_table; } else { rgn->rgn_state = HPB_RGN_INACTIVE; } @@ -1944,6 +1944,9 @@ static int ufshpb_alloc_region_tbl(struct ufs_hba *hba, struct ufshpb_lu *hpb) return 0; +release_current_srgn_table: + kvfree(rgn_table[rgn_idx].srgn_tbl); + release_srgn_table: for (i = 0; i < rgn_idx; i++) kvfree(rgn_table[i].srgn_tbl); -- 2.17.1