Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1915636pxb; Thu, 16 Sep 2021 20:08:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDeLRKzm3ocA8tSVAkWyruApepMSKcZu82nQsg23+3M2PT4A14GE7oKRExIp+luXOiU+ik X-Received: by 2002:a92:c8d2:: with SMTP id c18mr6126497ilq.121.1631848120870; Thu, 16 Sep 2021 20:08:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631848120; cv=none; d=google.com; s=arc-20160816; b=zuGWkhtilo2Cmeq6doylGp0eejeCUMtkn7aVTgnv8QDqEyDIbq706zolzTNeS8ptQa 1IC2ZM3W2QC0uRbitjjayjQ8QQZOwV4dxe73IoTjov36SqJRK4IIn1RnOnNkODzM6n7e LqA57yQWRtITYMBLOfvFSXDzH6YOwqd3P1pH4QUD9ZgXYeNGGUj+E7w2bmvNFLDq0SLA l4kagKe00X3u/zBHoytVk+6cju+KCd1wu/4Wu0Fl+8V8e3IuXDItZn5Bz7XMGjV9eBjh Za1wNiF43SffPUflGHUETnHIh3rEAm5wJ/ZzNMSzXkkSNgzsdofGCJPNhYmYnPX2dZv7 FTKA== 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=jhjrJN+yk0f37Uj1bkcbZxysoX1WCeBENHkLgNcTscY=; b=ijaa5RgmDaCVeWeG3+cG7KSmFo8Dj9yHNanyLQghrkauXh9GHLfMc5sSNNr/9NFTGg eZ63fR8wQraIgn184HyHUAlB8NkPGffdhSp9VxAXUEfSwMXnLCC++9YidyzBxFsHAfJI oYqDXbzkzqK0dBeZSLh1Qyo4yyjcMnHpWSBG4miij3s0MaPTK+maiM1jbGnG6hdfBFRT f8luLjB5wPtxlitnAQA8lbBRXM2wdGtUOCcq2srNWa8gvpwDUsFfbq9K/EqkYR8pfTS4 WYNBMbsPaolwpAAPkHYOINs5oym8tvRe60d5gS1Hn5fxiaAJ2anZTzvE1HOk9bSktY6O ADYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IPsG85v5; 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 u2si4580077ioc.87.2021.09.16.20.08.29; Thu, 16 Sep 2021 20:08:40 -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=IPsG85v5; 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 S1351682AbhIPR0r (ORCPT + 99 others); Thu, 16 Sep 2021 13:26:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:43646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346367AbhIPRSH (ORCPT ); Thu, 16 Sep 2021 13:18:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 31E8361B93; Thu, 16 Sep 2021 16:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631810468; bh=TD+BqpQc9GtFzId14Bx/2YU+1CKC56nOUGWnhYF2vws=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IPsG85v5k8jaJ+ukfozn+VPMp1PE7h5FV0zlgi8kCHy8jv++A/jWfvKVcVOpiYcF2 o3/CDbwlj2amykVi3qsvQ0Kb5PJOZuXYMKH/kTWVGhmV7Q4/icP2YzILUpso/R0h8p 4Ob7eCQ5e52c9dESBQh2Y/8rzOX+f1lNqqJB7YA4= 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.14 152/432] f2fs: deallocate compressed pages when error happens Date: Thu, 16 Sep 2021 17:58:21 +0200 Message-Id: <20210916155815.895756640@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155810.813340753@linuxfoundation.org> References: <20210916155810.813340753@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 455561826c7d..b8b3f1160afa 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1340,12 +1340,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: @@ -1356,6 +1350,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