Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp4058796pxb; Mon, 30 Aug 2021 17:54:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6NsIPnkMyR14jbEnd5LPRECOKZ+oP1h6yg3qwhxAwzL887+o4RO2CLi2IWhYA5YhrNKM4 X-Received: by 2002:a92:d1d0:: with SMTP id u16mr8317393ilg.56.1630371279189; Mon, 30 Aug 2021 17:54:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630371279; cv=none; d=google.com; s=arc-20160816; b=qyYrkCktkRn4jA7JDkbqYWTJOa9TrbCsUGAAA1mifnUPduhaXTCAgfj03G5n5zDsE8 aloRlZVys6rTgHUyTiuQ2Qyx1ywrUd5Bahd98ViTkdssTFj0LAmibsQ9mWrs2sOvvZ3Q e9b5lGAsWwp/mrkp21DbnTN+ffFVcdr/SKz9hPe8h/uwiHc0kcGDf2wT+JYm5mmEIJ29 lD7YvVB3i8/X9N5w1wDH6WUVPNRqyhKnnTDPVAnpEPmDBUr/NAMDT+anB/l+/Gm0KJJt R1dzVIMYIiZraKipKcU96s+HZDNQCLx0RcHrGPyphUGLpq3N02AOyuWi9rqiSR6wV7jS oINA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=S/eM6ub/e/UKAnLGYQrIwljPO3L/gHJfpOtSIwN+JGc=; b=ClnCrUuKNwfhaIr0YxP3Xmgs58/7x6PpSQn9q4LjBlyrZA1R3hbzlDOsoKYLy1rUz3 ft3Uh49iDo96C0+yKEci88ISb0UdoVVrwgWO7pcUD6C9LKrnHKCIfYvffETLW1w6D0/m 6WN1dKVYkvwvuz15PLplmDbUvuBJgrmgiN6MOdM0ieFsmhrSETjdxdtXFWTkI8ftpC+G d2ZaHDjLEyTrtmgsTE6CU47Xg52QS/g7xEtMC+XYmxiLMrw6RzfI9zauRafFORRGADjU wNkb8oDe8GFCJf9iW2gBwPUuHKtvYF5tdTHPJVCOad/ZMABrF9FpCZj8eFGGaQCsYYqt auBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=asjTqDVP; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n5si19105028jat.10.2021.08.30.17.54.27; Mon, 30 Aug 2021 17:54:39 -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=@kernel.org header.s=k20201202 header.b=asjTqDVP; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239107AbhHaAyn (ORCPT + 99 others); Mon, 30 Aug 2021 20:54:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:53170 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230523AbhHaAym (ORCPT ); Mon, 30 Aug 2021 20:54:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 767A260FE6; Tue, 31 Aug 2021 00:53:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630371228; bh=ooTDUto4Y8X1OmuC8lpldPc6v/zwqtRT620l+46tx0c=; h=From:To:Cc:Subject:Date:From; b=asjTqDVPpZEmoBXOBj1lHhcouEn9iDwA4r5DOw8i0HfIcKsq5N/baZc2n19KOMziG ppoP9V4ey2IqQoOmsJqNSdRV84vibU70KO6vy13o+fCqeKD3cD6e/BiGGg7CuBjvQY IOHvVluo0KhZ6t33ysLfjRUoT/2IVAIQ+UG53G2T2CNTBdt/omBPgf88GAyBwSjFTC UXOLBHIdhqF0B0mhUJr4eAz28PZi2V3VxILSkCRVPq12dp/zc+Kxl00DUCuePFXv7z 25tWMz00qIZzedzbHRAZVb7yZpeVp4ZY9yezFG8wKwYKoLLTwgSbGBbHOStWGyuJck UK48Duvrcf4YQ== From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim Subject: [PATCH 1/2] f2fs: deallocate compressed pages when error happens Date: Mon, 30 Aug 2021 17:53:45 -0700 Message-Id: <20210831005346.118701-1-jaegeuk@kernel.org> X-Mailer: git-send-email 2.33.0.259.gc128427fd7-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Jaegeuk Kim --- 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 ec70a0a32327..c1bf9ad4c220 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1394,12 +1394,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: @@ -1410,6 +1404,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.33.0.259.gc128427fd7-goog