Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1531773pxb; Thu, 16 Sep 2021 09:21:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeUCDH60dU4NQYpbFKDrwC9uW/OTegQ3PYrWznVFFhJaAABlUzCEUdDb5chkNmsiTkobdR X-Received: by 2002:a17:907:75d9:: with SMTP id jl25mr7232680ejc.4.1631809267100; Thu, 16 Sep 2021 09:21:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631809267; cv=none; d=google.com; s=arc-20160816; b=ouSScBnWJvk9tPPFD1qon3BkDWDQPtbSp/qaJ//gaYxcH3vhIpvvPvS3/dXK44JtEL JsJAZrF5fK6ZozT8c6ZqVaz+Uy4TVCo1IZ8SC92ZaXex16Zjrl0s+m5LP9dDGjiUg49W bK0GTQzxu7ePB1IRZt+bwY9y78ckMKtMHvgBGS0Xd42uuirGV4Wi7vAKNZnRf+22Idew lMPKNvodTFEl03SKYj1Ty4CMZmYm/tryWw99pyGvzHsI1ObPHi+J63QDquWRZAYR/WcO CW53M98ecXjwIAgZK2g2lCrYl2S9hAfhcqm1RpA4nl2Yr81GoLGsdzHJMnM2SoOyLfZD 5sXA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=haOeD2iqJTSVj8lEXbVEzjHyfP1HTyRxOYbWlwQPxok=; b=oNW7JCHZyJQAi7QDO8utPJTfV17yxGWwSvCstaKuXXFVSiXhyk7uXlIIXIu0j8nW9B jwBizoB4So7lVE873GFm8hF71kaCu3gVjbQiW1k/7lGx7A7kudPxh2jiBB6zw2ub8LO0 P8MC+sTOAXWhg3aJlRHhxMSyKrOAPSX9gtyHfBvnCzXCg+UxUcHEMQpTIegU4Rq5ig6k Tq7HDYHgHSS/OgX9MHvG/iNjWdfunY1NyYuE73QPj1jIo18twKUUB/OZiiJr4Qt77gJf W6V4NSG4Ivt9n7j23SLlFFEtZ0sjFD75cgwqyGOy4olm9NkDrnQ5dJZLPquRBBiwTgFq VlGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=U7PP7Lnv; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hb44si3402278ejc.174.2021.09.16.09.20.38; Thu, 16 Sep 2021 09:21:07 -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=@linuxfoundation.org header.s=korg header.b=U7PP7Lnv; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241541AbhIPQTr (ORCPT + 99 others); Thu, 16 Sep 2021 12:19:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:48542 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236194AbhIPQK7 (ORCPT ); Thu, 16 Sep 2021 12:10:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D244A61359; Thu, 16 Sep 2021 16:08:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808522; bh=MxxWNK/Ar+X6mIo8tPVERAmcZPj2c31xcA0uylciFss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U7PP7Lnv1HRn/pI2GwF2MFYEVaOqoyDhIImxlYJfoNohgALFkvVhAT6VCEEh5O1si ek2MTW8+55OOTgEBXZNLb/q/GeeIgSiJBNwNSplGR0Iy0fzbtYAr4EqSCVxE7LN2Yc GHanxhktw3KNYBQ45x1Ee/nbX609d1RwHW/hoIeo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.10 105/306] f2fs: deallocate compressed pages when error happens Date: Thu, 16 Sep 2021 17:57:30 +0200 Message-Id: <20210916155757.656735859@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jaegeuk Kim [ Upstream commit 827f02842e40ea2e00f401e8f4cb1bccf3b8cd86 ] In f2fs_write_multi_pages(), f2fs_compress_pages() allocates pages for compression work in cc->cpages[]. Then, f2fs_write_compressed_pages() initiates bio submission. But, if there's any error before submitting the IOs like early f2fs_cp_error(), previously it didn't free cpages by f2fs_compress_free_page(). Let's fix memory leak by putting that just before deallocating cc->cpages. Fixes: 4c8ff7095bef ("f2fs: support data compression") Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/compress.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index f94b13075ea4..30987ea011f1 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1308,12 +1308,6 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc, for (--i; i >= 0; i--) fscrypt_finalize_bounce_page(&cc->cpages[i]); - for (i = 0; i < cc->nr_cpages; i++) { - if (!cc->cpages[i]) - continue; - f2fs_compress_free_page(cc->cpages[i]); - cc->cpages[i] = NULL; - } out_put_cic: kmem_cache_free(cic_entry_slab, cic); out_put_dnode: @@ -1324,6 +1318,12 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc, else f2fs_unlock_op(sbi); out_free: + for (i = 0; i < cc->nr_cpages; i++) { + if (!cc->cpages[i]) + continue; + f2fs_compress_free_page(cc->cpages[i]); + cc->cpages[i] = NULL; + } page_array_free(cc->inode, cc->cpages, cc->nr_cpages); cc->cpages = NULL; return -EAGAIN; -- 2.30.2