Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1473709pxb; Sun, 22 Aug 2021 18:39:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycDKt69JHHrdcvSOPTr/MNzF3ifVI0kRXldG1yAO1Eh05qbJigCI5aAFqvwzO/2ncLa+VS X-Received: by 2002:a17:906:318c:: with SMTP id 12mr32757149ejy.28.1629682785986; Sun, 22 Aug 2021 18:39:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629682785; cv=none; d=google.com; s=arc-20160816; b=QcoA9UIhvtGo4fg8LZG60NXCaOpPS9H7OcUZuPo8/p0UVetZ8f4pen9XhkBJRWICUL dm4WoaexbjSCo0OzETpVn8i4eC1H7OKoYesw/a4fQrx4Livk1XkZj+x22Qb8qGwQ7R+b oU712jXsEolWE+J3zQQiK3C6+vuUpqgNnTuqQiusyvR0KVZPTptMKPU7Nnc3DVarBaw5 X053nCufmQsHqPNrxx6kIyB9rSFtKA/XwUMpGfPm/FjEXKCKqdkOM5dgJKJmF0Oucgcp OBdGL/XHgBR92+k1e7g+NmspVzZovWd+4ORo0q3QJjczFZpoH40oC8k1BfRFhLgpTuaw CONA== 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:in-reply-to:to:from:sender:reply-to:subject:mime-version :dkim-signature:dkim-filter; bh=q+J/BDN8g7YL5QAH0PemEbR6v4KIUjl5qmAlnayWP8s=; b=EW+/bZgHBQ3TjY2DYo2vTS2AQq0fO/69ULbpGzA+a84gOVEFgva1t3F7fmlMctiOJK id+pCvaTsIXYSxzd+I40jpAjuRL8hXyKHp9RwZGeDkOH/bszrp8kZiS7aX4hc2oxGiI0 rf0ADmEpTnLLkSTJZkzBRzG8RYk4EyH28XGdL0JLTFXj+IB4Rcx95G4TVcujPq8BzWp2 FYrAVD9uIYBV0jUTs1mLE6VnVrjhnd+yj/GEtA1MoHgCooze/DOwLQLRGOsgrmUq32Yf pMao6oZmzlFSka18Im7+L66t0A1xI6le9kRD1BGu2BPt2kNMkg+ZCAcnK9iiqyd9KL4H wfcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=OVhQJofW; 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 h2si13391137eds.213.2021.08.22.18.39.23; Sun, 22 Aug 2021 18:39:45 -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=OVhQJofW; 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 S234612AbhHWBiq (ORCPT + 99 others); Sun, 22 Aug 2021 21:38:46 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:63945 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234572AbhHWBip (ORCPT ); Sun, 22 Aug 2021 21:38:45 -0400 Received: from epcas3p4.samsung.com (unknown [182.195.41.22]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20210823013802epoutp010084a834165d6f84d62d911101ea80f3~dy8PxFIRp2728927289epoutp01h for ; Mon, 23 Aug 2021 01:38:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20210823013802epoutp010084a834165d6f84d62d911101ea80f3~dy8PxFIRp2728927289epoutp01h DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1629682682; bh=q+J/BDN8g7YL5QAH0PemEbR6v4KIUjl5qmAlnayWP8s=; h=Subject:Reply-To:From:To:In-Reply-To:Date:References:From; b=OVhQJofW8QJifNHqVSHOm1kvML5fy/06ikqN//FqClaaoXkA3+IdY7R5IkHc7xCqi bW7me2OcA1F3H9BP/D42rCJK2x9ZJL94RoBxDBIwP5zZote7pkLwI92ihbc5d/PQhI E2q9v//Ukw7JrjDPRYl4Ceg73NJ0cnOx+SC8WBtU= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas3p3.samsung.com (KnoxPortal) with ESMTP id 20210823013802epcas3p3ad1c51ead38448ce9b637b67d33fcee0~dy8POXfF22802628026epcas3p3I; Mon, 23 Aug 2021 01:38:02 +0000 (GMT) Received: from epcpadp4 (unknown [182.195.40.18]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4GtFHY6zvGz4x9Qb; Mon, 23 Aug 2021 01:38:01 +0000 (GMT) Mime-Version: 1.0 Subject: RE: Re: [PATCH] scsi: ufs: ufshpb: Fix possible memory leak Reply-To: keosung.park@samsung.com Sender: Keoseong Park From: Keoseong Park To: Bart Van Assche , Keoseong Park , 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 In-Reply-To: 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.01629682681949.JavaMail.epsvc@epcpadp4> Date: Mon, 23 Aug 2021 10:09:12 +0900 X-CMS-MailID: 20210823010912epcms2p38bc3176b6e11f2e9d9494ae668d479fc 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: <1891546521.01629427801384.JavaMail.epsvc@epcpadp3> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Bart, > On 8/19/21 6:46 PM, Keoseong Park wrote: >> 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); > >'rgn_table' is allocated with kvcalloc() so please merge the new kvfree() statement >with the for-loop below it. > >There is another improvement that can be made in this function: hpb->rgn_tbl >is not cleared in the error path. I propose to move the "hpb->rgn_tbl = rgn_table" >assignment from the start of the function to just above the "return 0" statement. > >Thanks, > >Bart. > Thank you for your feedback. I will fix it. Best Regards, Keoseong